function BlockCacheTest::testCachePermissions
Same name in other branches
- 9 core/modules/block/tests/src/Functional/BlockCacheTest.php \Drupal\Tests\block\Functional\BlockCacheTest::testCachePermissions()
- 8.9.x core/modules/block/tests/src/Functional/BlockCacheTest.php \Drupal\Tests\block\Functional\BlockCacheTest::testCachePermissions()
- 11.x core/modules/block/tests/src/Functional/BlockCacheTest.php \Drupal\Tests\block\Functional\BlockCacheTest::testCachePermissions()
Tests a cacheable block without any additional cache context.
File
-
core/
modules/ block/ tests/ src/ Functional/ BlockCacheTest.php, line 135
Class
- BlockCacheTest
- Tests block caching.
Namespace
Drupal\Tests\block\FunctionalCode
public function testCachePermissions() : void {
// user.permissions is a required context, so a user with different
// permissions will see a different version of the block.
\Drupal::state()->set('block_test.cache_contexts', []);
$current_content = $this->randomMachineName();
\Drupal::state()->set('block_test.content', $current_content);
$this->drupalGet('');
$this->assertSession()
->pageTextContains($current_content);
$old_content = $current_content;
$current_content = $this->randomMachineName();
\Drupal::state()->set('block_test.content', $current_content);
// Block content served from cache.
$this->drupalGet('user');
$this->assertSession()
->pageTextContains($old_content);
// Block content not served from cache.
$this->drupalLogout();
$this->drupalGet('user');
$this->assertSession()
->pageTextContains($current_content);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.