function AssertPageCacheContextsAndTagsTrait::assertPageCacheContextsAndTags
Same name in other branches
- 8.9.x core/modules/system/src/Tests/Cache/AssertPageCacheContextsAndTagsTrait.php \Drupal\system\Tests\Cache\AssertPageCacheContextsAndTagsTrait::assertPageCacheContextsAndTags()
- 8.9.x core/modules/system/tests/src/Functional/Cache/AssertPageCacheContextsAndTagsTrait.php \Drupal\Tests\system\Functional\Cache\AssertPageCacheContextsAndTagsTrait::assertPageCacheContextsAndTags()
- 10 core/modules/system/tests/src/Functional/Cache/AssertPageCacheContextsAndTagsTrait.php \Drupal\Tests\system\Functional\Cache\AssertPageCacheContextsAndTagsTrait::assertPageCacheContextsAndTags()
- 11.x core/modules/system/tests/src/Functional/Cache/AssertPageCacheContextsAndTagsTrait.php \Drupal\Tests\system\Functional\Cache\AssertPageCacheContextsAndTagsTrait::assertPageCacheContextsAndTags()
Asserts page cache miss, then hit for the given URL; checks cache headers.
Parameters
\Drupal\Core\Url $url: The URL to test.
string[] $expected_contexts: The expected cache contexts for the given URL.
string[] $expected_tags: The expected cache tags for the given URL.
3 calls to AssertPageCacheContextsAndTagsTrait::assertPageCacheContextsAndTags()
- FrontPageTest::doTestFrontPageViewCacheTags in core/
modules/ node/ tests/ src/ Functional/ Views/ FrontPageTest.php - Tests the cache tags on the front page.
- GlossaryTest::testGlossaryView in core/
modules/ views/ tests/ src/ Functional/ GlossaryTest.php - Tests the default glossary view.
- PageCacheTagsIntegrationTest::testPageCacheTags in core/
modules/ page_cache/ tests/ src/ Functional/ PageCacheTagsIntegrationTest.php - Tests that cache tags are properly bubbled up to the page level.
File
-
core/
modules/ system/ tests/ src/ Functional/ Cache/ AssertPageCacheContextsAndTagsTrait.php, line 70
Class
- AssertPageCacheContextsAndTagsTrait
- Provides test assertions for testing page-level cache contexts & tags.
Namespace
Drupal\Tests\system\Functional\CacheCode
protected function assertPageCacheContextsAndTags(Url $url, array $expected_contexts, array $expected_tags) {
$absolute_url = $url->setAbsolute()
->toString();
sort($expected_contexts);
sort($expected_tags);
// Assert cache miss + expected cache contexts + tags.
$this->drupalGet($absolute_url);
$this->assertSession()
->responseHeaderEquals('X-Drupal-Cache', 'MISS');
$this->assertCacheTags($expected_tags);
$this->assertCacheContexts($expected_contexts);
// Assert cache hit + expected cache contexts + tags.
$this->drupalGet($absolute_url);
$this->assertCacheTags($expected_tags);
$this->assertCacheContexts($expected_contexts);
// Assert page cache item + expected cache tags.
$cid_parts = [
$url->setAbsolute()
->toString(),
'',
];
$cid = implode(':', $cid_parts);
$cache_entry = \Drupal::cache('page')->get($cid);
sort($cache_entry->tags);
$this->assertEquals($expected_tags, $cache_entry->tags);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.