function BlockCacheTest::testNoCache
Same name in other branches
- 9 core/modules/block/tests/src/Functional/BlockCacheTest.php \Drupal\Tests\block\Functional\BlockCacheTest::testNoCache()
- 8.9.x core/modules/block/tests/src/Functional/BlockCacheTest.php \Drupal\Tests\block\Functional\BlockCacheTest::testNoCache()
- 10 core/modules/block/tests/src/Functional/BlockCacheTest.php \Drupal\Tests\block\Functional\BlockCacheTest::testNoCache()
Tests non-cacheable block.
File
-
core/
modules/ block/ tests/ src/ Functional/ BlockCacheTest.php, line 163
Class
- BlockCacheTest
- Tests block caching.
Namespace
Drupal\Tests\block\FunctionalCode
public function testNoCache() : void {
\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->assertSession()
->pageTextContains($current_content);
// A cached copy should not be served.
$current_content = $this->randomMachineName();
\Drupal::state()->set('block_test.content', $current_content);
$this->drupalGet('');
// Maximum age of zero prevents blocks from being cached.
$this->assertSession()
->pageTextContains($current_content);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.