Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
993c3219
Commit
993c3219
authored
Jan 24, 2010
by
Dries Buytaert
Browse files
Options
Downloads
Patches
Plain Diff
- Rollback of
#691938
.
parent
6a573915
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!7452
Issue #1797438. HTML5 validation is preventing form submit and not fully...
,
!789
Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
modules/block/block.module
+1
-1
1 addition, 1 deletion
modules/block/block.module
modules/block/block.test
+0
-177
0 additions, 177 deletions
modules/block/block.test
with
1 addition
and
178 deletions
modules/block/block.module
+
1
−
1
View file @
993c3219
...
...
@@ -825,7 +825,7 @@ function _block_get_cache_id($block) {
// Start with common sub-patterns: block identification, theme, language.
$cid_parts
[]
=
$block
->
module
;
$cid_parts
[]
=
$block
->
delta
;
$cid_parts
=
array_merge
(
$cid_parts
,
drupal_render_cid_parts
(
$block
->
cache
)
)
;
$cid_parts
+
=
drupal_render_cid_parts
(
$block
->
cache
);
return
implode
(
':'
,
$cid_parts
);
}
...
...
This diff is collapsed.
Click to expand it.
modules/block/block.test
+
0
−
177
View file @
993c3219
...
...
@@ -318,180 +318,3 @@ class BlockAdminThemeTestCase extends DrupalWebTestCase {
$this
->
assertResponse
(
200
,
t
(
'The block admin page for the admin theme can be accessed'
));
}
}
/**
* Test block cache effectiveness.
*/
class
BlockCacheTestCase
extends
DrupalWebTestCase
{
protected
$admin_user
;
protected
$normal_user
;
protected
$normal_user_alt
;
public
static
function
getInfo
()
{
return
array
(
'name'
=>
'Block caching'
,
'description'
=>
'Test block cache effectiveness.'
,
'group'
=>
'Block'
,
);
}
function
setUp
()
{
parent
::
setUp
(
'block_test'
);
// Create an admin user, log in and enable test blocks.
$this
->
admin_user
=
$this
->
drupalCreateUser
(
array
(
'administer blocks'
,
'administer filters'
,
'access administration pages'
));
$this
->
drupalLogin
(
$this
->
admin_user
);
// Create additional users to test caching modes.
$this
->
normal_user
=
$this
->
drupalCreateUser
();
$this
->
normal_user_alt
=
$this
->
drupalCreateUser
();
// Sync the roles, since drupalCreateUser() creates separate roles for
// the same permission sets.
$this
->
normal_user_alt
->
roles
=
$this
->
normal_user
->
roles
;
// Enable block caching.
variable_set
(
'block_cache'
,
1
);
// Enable our test block.
$edit
[
'block_test_test_cache[region]'
]
=
'sidebar_first'
;
$this
->
drupalPost
(
'admin/structure/block'
,
$edit
,
t
(
'Save blocks'
));
}
/**
* Test per-role caching.
*/
function
testCachePerRole
()
{
$this
->
setCacheMode
(
DRUPAL_CACHE_PER_ROLE
);
// Enable our test block. Set some content for it to display.
variable_set
(
'block_test_content'
,
$this
->
randomName
());
$this
->
drupalLogin
(
$this
->
normal_user
);
$this
->
drupalGet
(
''
);
$this
->
assertText
(
variable_get
(
'block_test_content'
,
''
),
t
(
'Block content displays.'
));
// Change the content, but the cached copy should still be served.
$old_content
=
variable_get
(
'block_test_content'
,
''
);
variable_set
(
'block_test_content'
,
$this
->
randomName
());
$this
->
drupalGet
(
''
);
$this
->
assertText
(
$old_content
,
t
(
'Block is served from the cache.'
));
// Clear the cache and verify that the stale data is no longer there.
cache_clear_all
();
$this
->
drupalGet
(
''
);
$this
->
assertNoText
(
$old_content
,
t
(
'Block cache clear removes stale cache data.'
));
// Test whether the cached data is served for the correct users.
$old_content
=
variable_get
(
'block_test_content'
,
''
);
variable_set
(
'block_test_content'
,
$this
->
randomName
());
$this
->
drupalLogout
();
$this
->
drupalGet
(
''
);
$this
->
assertNoText
(
$old_content
,
t
(
'Anonymous user does not see content cached per-role for normal user.'
));
$this
->
drupalLogin
(
$this
->
normal_user_alt
);
$this
->
drupalGet
(
''
);
$this
->
assertText
(
$old_content
,
t
(
'User with the same roles sees per-role cached content.'
));
$this
->
drupalLogin
(
$this
->
admin_user
);
$this
->
drupalGet
(
''
);
$this
->
assertNoText
(
$old_content
,
t
(
'Admin user does not see content cached per-role for normal user.'
));
$this
->
drupalLogin
(
$this
->
normal_user
);
$this
->
drupalGet
(
''
);
$this
->
assertText
(
$old_content
,
t
(
'Block is served from the per-role cache.'
));
}
/**
* Test global caching.
*/
function
testCacheGlobal
()
{
$this
->
setCacheMode
(
DRUPAL_CACHE_GLOBAL
);
variable_set
(
'block_test_content'
,
$this
->
randomName
());
$this
->
drupalGet
(
''
);
$this
->
assertText
(
variable_get
(
'block_test_content'
,
''
),
t
(
'Block content displays.'
));
$old_content
=
variable_get
(
'block_test_content'
,
''
);
variable_set
(
'block_test_content'
,
$this
->
randomName
());
$this
->
drupalLogout
();
$this
->
drupalGet
(
'user'
);
$this
->
assertText
(
$old_content
,
t
(
'Block content served from global cache.'
));
}
/**
* Test DRUPAL_NO_CACHE.
*/
function
testNoCache
()
{
$this
->
setCacheMode
(
DRUPAL_NO_CACHE
);
variable_set
(
'block_test_content'
,
$this
->
randomName
());
// If DRUPAL_NO_CACHE has no effect, the next request would be cached.
$this
->
drupalGet
(
''
);
$this
->
assertText
(
variable_get
(
'block_test_content'
,
''
),
t
(
'Block content displays.'
));
// A cached copy should not be served.
variable_set
(
'block_test_content'
,
$this
->
randomName
());
$this
->
drupalGet
(
''
);
$this
->
assertText
(
variable_get
(
'block_test_content'
,
''
),
t
(
'DRUPAL_NO_CACHE prevents blocks from being cached.'
));
}
/**
* Test per-user caching.
*/
function
testCachePerUser
()
{
$this
->
setCacheMode
(
DRUPAL_CACHE_PER_USER
);
variable_set
(
'block_test_content'
,
$this
->
randomName
());
$this
->
drupalLogin
(
$this
->
normal_user
);
$this
->
drupalGet
(
''
);
$this
->
assertText
(
variable_get
(
'block_test_content'
,
''
),
t
(
'Block content displays.'
));
$old_content
=
variable_get
(
'block_test_content'
,
''
);
variable_set
(
'block_test_content'
,
$this
->
randomName
());
$this
->
drupalGet
(
''
);
$this
->
assertText
(
$old_content
,
t
(
'Block is served from per-user cache.'
));
$this
->
drupalLogin
(
$this
->
normal_user_alt
);
$this
->
drupalGet
(
''
);
$this
->
assertText
(
variable_get
(
'block_test_content'
,
''
),
t
(
'Per-user block cache is not served for other users.'
));
$this
->
drupalLogin
(
$this
->
normal_user
);
$this
->
drupalGet
(
''
);
$this
->
assertText
(
$old_content
,
t
(
'Per-user block cache is persistent.'
));
}
/**
* Test per-page caching.
*/
function
testCachePerPage
()
{
$this
->
setCacheMode
(
DRUPAL_CACHE_PER_PAGE
);
variable_set
(
'block_test_content'
,
$this
->
randomName
());
$this
->
drupalGet
(
'node'
);
$this
->
assertText
(
variable_get
(
'block_test_content'
,
''
),
t
(
'Block content displays on the node page.'
));
$old_content
=
variable_get
(
'block_test_content'
,
''
);
variable_set
(
'block_test_content'
,
$this
->
randomName
());
$this
->
drupalGet
(
'user'
);
$this
->
assertNoText
(
$old_content
,
t
(
'Block content cached for the node page does not show up for the user page.'
));
$this
->
drupalGet
(
'node'
);
$this
->
assertText
(
$old_content
,
t
(
'Block content cached for the node page.'
));
}
private
function
setCacheMode
(
$cache_mode
)
{
// _block_rehash() manually populates the {block} table.
_block_rehash
();
$affected
=
db_update
(
'block'
)
->
fields
(
array
(
'cache'
=>
$cache_mode
))
->
condition
(
'module'
,
'block_test'
)
->
execute
();
$current_mode
=
db_query
(
"SELECT cache FROM
{
block
}
WHERE module = 'block_test'"
)
->
fetchField
();
if
(
$current_mode
!=
$cache_mode
)
{
$this
->
fail
(
t
(
'Unable to set cache mode to %mode. Current mode: %current_mode'
,
array
(
'%mode'
=>
$cache_mode
,
'%current_mode'
=>
$current_mode
)));
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment