function BlockCacheTest::testCachePerUser in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/block/src/Tests/BlockCacheTest.php \Drupal\block\Tests\BlockCacheTest::testCachePerUser()
Test "user" cache context.
File
- core/
modules/ block/ src/ Tests/ BlockCacheTest.php, line 170 - Contains \Drupal\block\Tests\BlockCacheTest.
Class
- BlockCacheTest
- Tests block caching.
Namespace
Drupal\block\TestsCode
function testCachePerUser() {
\Drupal::state()
->set('block_test.cache_contexts', [
'user',
]);
$current_content = $this
->randomMachineName();
\Drupal::state()
->set('block_test.content', $current_content);
$this
->drupalLogin($this->normalUser);
$this
->drupalGet('');
$this
->assertText($current_content, 'Block content displays.');
$old_content = $current_content;
$current_content = $this
->randomMachineName();
\Drupal::state()
->set('block_test.content', $current_content);
$this
->drupalGet('');
$this
->assertText($old_content, 'Block is served from per-user cache.');
$this
->drupalLogin($this->normalUserAlt);
$this
->drupalGet('');
$this
->assertText($current_content, 'Per-user block cache is not served for other users.');
$this
->drupalLogin($this->normalUser);
$this
->drupalGet('');
$this
->assertText($old_content, 'Per-user block cache is persistent.');
}