function BlockCacheTest::testCachePerPage
Test "url" cache context.
File
- 
              core/modules/ block/ tests/ src/ Functional/ BlockCacheTest.php, line 202 
Class
- BlockCacheTest
- Tests block caching.
Namespace
Drupal\Tests\block\FunctionalCode
public 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->assertSession()
    ->statusCodeEquals(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->assertSession()
    ->statusCodeEquals(200);
  $this->assertText($old_content, 'Block content cached for the test page.');
}Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
