function AssertPageCacheContextsAndTagsTrait::assertCacheTags
Same name in other branches
- 9 core/modules/system/tests/src/Functional/Cache/AssertPageCacheContextsAndTagsTrait.php \Drupal\Tests\system\Functional\Cache\AssertPageCacheContextsAndTagsTrait::assertCacheTags()
- 8.9.x core/modules/system/src/Tests/Cache/AssertPageCacheContextsAndTagsTrait.php \Drupal\system\Tests\Cache\AssertPageCacheContextsAndTagsTrait::assertCacheTags()
- 8.9.x core/modules/system/tests/src/Functional/Cache/AssertPageCacheContextsAndTagsTrait.php \Drupal\Tests\system\Functional\Cache\AssertPageCacheContextsAndTagsTrait::assertCacheTags()
- 10 core/modules/system/tests/src/Functional/Cache/AssertPageCacheContextsAndTagsTrait.php \Drupal\Tests\system\Functional\Cache\AssertPageCacheContextsAndTagsTrait::assertCacheTags()
Ensures that some cache tags are present in the current response.
Parameters
string[] $expected_tags: The expected tags.
bool $include_default_tags: (optional) Whether the default cache tags should be included.
16 calls to AssertPageCacheContextsAndTagsTrait::assertCacheTags()
- AssertPageCacheContextsAndTagsTrait::assertPageCacheContextsAndTags in core/
modules/ system/ tests/ src/ Functional/ Cache/ AssertPageCacheContextsAndTagsTrait.php - Asserts page cache miss, then hit for the given URL; checks cache headers.
- CacheWebTest::testCacheOutputOnPage in core/
modules/ views/ tests/ src/ Functional/ Plugin/ CacheWebTest.php - Tests the output caching on an actual page.
- CommentRssTest::testCommentRss in core/
modules/ comment/ tests/ src/ Functional/ CommentRssTest.php - Tests comments as part of an RSS feed.
- DisplayBlockTest::testBlockEmptyRendering in core/
modules/ block/ tests/ src/ Functional/ Views/ DisplayBlockTest.php - Tests the various test cases of empty block rendering.
- DisplayBlockTest::testBlockRendering in core/
modules/ block/ tests/ src/ Functional/ Views/ DisplayBlockTest.php - Tests the actual rendering of the views block.
File
-
core/
modules/ system/ tests/ src/ Functional/ Cache/ AssertPageCacheContextsAndTagsTrait.php, line 104
Class
- AssertPageCacheContextsAndTagsTrait
- Provides test assertions for testing page-level cache contexts & tags.
Namespace
Drupal\Tests\system\Functional\CacheCode
protected function assertCacheTags(array $expected_tags, $include_default_tags = TRUE) {
// The anonymous role cache tag is only added if the user is anonymous.
if ($include_default_tags) {
if (\Drupal::currentUser()->isAnonymous()) {
$expected_tags = Cache::mergeTags($expected_tags, [
'config:user.role.anonymous',
]);
}
$expected_tags[] = 'http_response';
}
$actual_tags = $this->getCacheHeaderValues('X-Drupal-Cache-Tags');
$expected_tags = array_unique($expected_tags);
sort($expected_tags);
sort($actual_tags);
$this->assertSame($expected_tags, $actual_tags);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.