You are here

function BlockCacheTest::testCachePerPage 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::testCachePerPage()

Test "url" cache context.

File

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

Class

BlockCacheTest
Tests block caching.

Namespace

Drupal\block\Tests

Code

function testCachePerPage() {
  \Drupal::state()
    ->set('block_test.cache_contexts', [
    'url',
  ]);
  $current_content = $this
    ->randomMachineName();
  \Drupal::state()
    ->set('block_test.content', $current_content);
  $this
    ->drupalGet('test-page');
  $this
    ->assertText($current_content, 'Block content displays on the test page.');
  $old_content = $current_content;
  $current_content = $this
    ->randomMachineName();
  \Drupal::state()
    ->set('block_test.content', $current_content);
  $this
    ->drupalGet('user');
  $this
    ->assertResponse(200);
  $this
    ->assertNoText($old_content, 'Block content cached for the test page does not show up for the user page.');
  $this
    ->drupalGet('test-page');
  $this
    ->assertResponse(200);
  $this
    ->assertText($old_content, 'Block content cached for the test page.');
}