You are here

function BlockCacheTest::testCachePermissions in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/block/src/Tests/BlockCacheTest.php \Drupal\block\Tests\BlockCacheTest::testCachePermissions()

Test a cacheable block without any additional cache context.

File

core/modules/block/src/Tests/BlockCacheTest.php, line 124
Contains \Drupal\block\Tests\BlockCacheTest.

Class

BlockCacheTest
Tests block caching.

Namespace

Drupal\block\Tests

Code

function testCachePermissions() {

  // 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
    ->assertText($current_content, 'Block content displays.');
  $old_content = $current_content;
  $current_content = $this
    ->randomMachineName();
  \Drupal::state()
    ->set('block_test.content', $current_content);
  $this
    ->drupalGet('user');
  $this
    ->assertText($old_content, 'Block content served from cache.');
  $this
    ->drupalLogout();
  $this
    ->drupalGet('user');
  $this
    ->assertText($current_content, 'Block content not served from cache.');
}