function PageCacheTest::testPageCacheTags in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/page_cache/src/Tests/PageCacheTest.php \Drupal\page_cache\Tests\PageCacheTest::testPageCacheTags()
Test that cache tags are properly persisted.
Since tag based invalidation works, we know that our tag properly persisted.
File
- core/
modules/ page_cache/ src/ Tests/ PageCacheTest.php, line 52 - Contains \Drupal\page_cache\Tests\PageCacheTest.
Class
- PageCacheTest
- Enables the page cache and tests it with various HTTP requests.
Namespace
Drupal\page_cache\TestsCode
function testPageCacheTags() {
$config = $this
->config('system.performance');
$config
->set('cache.page.max_age', 300);
$config
->save();
$path = 'system-test/cache_tags_page';
$tags = array(
'system_test_cache_tags_page',
);
$this
->drupalGet($path);
$this
->assertEqual($this
->drupalGetHeader('X-Drupal-Cache'), 'MISS');
// Verify a cache hit, but also the presence of the correct cache tags.
$this
->drupalGet($path);
$this
->assertEqual($this
->drupalGetHeader('X-Drupal-Cache'), 'HIT');
$cid_parts = array(
\Drupal::url('system_test.cache_tags_page', array(), array(
'absolute' => TRUE,
)),
'html',
);
$cid = implode(':', $cid_parts);
$cache_entry = \Drupal::cache('render')
->get($cid);
sort($cache_entry->tags);
$expected_tags = array(
'config:user.role.anonymous',
'pre_render',
'rendered',
'system_test_cache_tags_page',
);
$this
->assertIdentical($cache_entry->tags, $expected_tags);
Cache::invalidateTags($tags);
$this
->drupalGet($path);
$this
->assertEqual($this
->drupalGetHeader('X-Drupal-Cache'), 'MISS');
}