function BlockCacheTest::testNoCache

Test DRUPAL_NO_CACHE.

File

drupal/core/modules/block/lib/Drupal/block/Tests/BlockCacheTest.php, line 126
Definition of Drupal\block\Tests\BlockCacheTest.

Class

BlockCacheTest
Test block caching.

Namespace

Drupal\block\Tests

Code

function testNoCache() {
  $this
    ->setCacheMode(DRUPAL_NO_CACHE);
  $current_content = $this
    ->randomName();
  \Drupal::state()
    ->set('block_test.content', $current_content);

  // If DRUPAL_NO_CACHE 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
    ->randomName();
  \Drupal::state()
    ->set('block_test.content', $current_content);
  $this
    ->drupalGet('');
  $this
    ->assertText($current_content, 'DRUPAL_NO_CACHE prevents blocks from being cached.');
}