function PageCacheTagsTestBase::verifyPageCache
Same name in this branch
- 8.9.x core/modules/system/tests/src/Functional/Cache/PageCacheTagsTestBase.php \Drupal\Tests\system\Functional\Cache\PageCacheTagsTestBase::verifyPageCache()
Same name in other branches
- 9 core/modules/system/tests/src/Functional/Cache/PageCacheTagsTestBase.php \Drupal\Tests\system\Functional\Cache\PageCacheTagsTestBase::verifyPageCache()
- 10 core/modules/system/tests/src/Functional/Cache/PageCacheTagsTestBase.php \Drupal\Tests\system\Functional\Cache\PageCacheTagsTestBase::verifyPageCache()
- 11.x core/modules/system/tests/src/Functional/Cache/PageCacheTagsTestBase.php \Drupal\Tests\system\Functional\Cache\PageCacheTagsTestBase::verifyPageCache()
Verify that when loading a given page, it's a page cache hit or miss.
Parameters
\Drupal\Core\Url $url: The page for this URL will be loaded.
string $hit_or_miss: 'HIT' if a page cache hit is expected, 'MISS' otherwise.
array|false $tags: When expecting a page cache hit, you may optionally specify an array of expected cache tags. While FALSE, the cache tags will not be verified.
2 calls to PageCacheTagsTestBase::verifyPageCache()
- EntityCacheTagsTestBase::testReferencedEntity in core/
modules/ system/ src/ Tests/ Entity/ EntityCacheTagsTestBase.php - Tests cache tags presence and invalidation of the entity when referenced.
- EntityWithUriCacheTagsTestBase::testEntityUri in core/
modules/ system/ src/ Tests/ Entity/ EntityWithUriCacheTagsTestBase.php - Tests cache tags presence and invalidation of the entity at its URI.
File
-
core/
modules/ system/ src/ Tests/ Cache/ PageCacheTagsTestBase.php, line 52
Class
- PageCacheTagsTestBase
- Provides helper methods for page cache tags tests.
Namespace
Drupal\system\Tests\CacheCode
protected function verifyPageCache(Url $url, $hit_or_miss, $tags = FALSE) {
$this->drupalGet($url);
$message = new FormattableMarkup('Page cache @hit_or_miss for %path.', [
'@hit_or_miss' => $hit_or_miss,
'%path' => $url->toString(),
]);
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), $hit_or_miss, $message);
if ($hit_or_miss === 'HIT' && is_array($tags)) {
$absolute_url = $url->setAbsolute()
->toString();
$cid_parts = [
$absolute_url,
'html',
];
$cid = implode(':', $cid_parts);
$cache_entry = \Drupal::cache('page')->get($cid);
sort($cache_entry->tags);
$tags = array_unique($tags);
sort($tags);
$this->assertIdentical($cache_entry->tags, $tags);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.