You are here

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

Test non-cacheable block.

File

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

Class

BlockCacheTest
Tests block caching.

Namespace

Drupal\block\Tests

Code

function testNoCache() {
  \Drupal::state()
    ->set('block_test.cache_max_age', 0);
  $current_content = $this
    ->randomMachineName();
  \Drupal::state()
    ->set('block_test.content', $current_content);

  // If max_age = 0 has no effect, the next request would be cached.
  $this
    ->drupalGet('');
  $this
    ->assertText($current_content, 'Block content displays.');

  // A cached copy should not be served.
  $current_content = $this
    ->randomMachineName();
  \Drupal::state()
    ->set('block_test.content', $current_content);
  $this
    ->drupalGet('');
  $this
    ->assertText($current_content, 'Maximum age of zero prevents blocks from being cached.');
}