protected function EntityCacheTagsTestBase::verifyRenderCache in Drupal 10
Same name and namespace in other branches
- 8 core/modules/system/tests/src/Functional/Entity/EntityCacheTagsTestBase.php \Drupal\Tests\system\Functional\Entity\EntityCacheTagsTestBase::verifyRenderCache()
- 9 core/modules/system/tests/src/Functional/Entity/EntityCacheTagsTestBase.php \Drupal\Tests\system\Functional\Entity\EntityCacheTagsTestBase::verifyRenderCache()
Verify that a given render cache entry exists, with the correct cache tags.
Parameters
string $cid: The render cache item ID.
array $tags: An array of expected cache tags.
string|null $redirected_cid: (optional) The redirected render cache item ID.
2 calls to EntityCacheTagsTestBase::verifyRenderCache()
- EntityCacheTagsTestBase::testReferencedEntity in core/
modules/ system/ tests/ src/ Functional/ Entity/ EntityCacheTagsTestBase.php - Tests cache tags presence and invalidation of the entity when referenced.
- EntityWithUriCacheTagsTestBase::testEntityUri in core/
modules/ system/ tests/ src/ Functional/ Entity/ EntityWithUriCacheTagsTestBase.php - Tests cache tags presence and invalidation of the entity at its URI.
File
- core/
modules/ system/ tests/ src/ Functional/ Entity/ EntityCacheTagsTestBase.php, line 643
Class
- EntityCacheTagsTestBase
- Provides helper methods for Entity cache tags tests.
Namespace
Drupal\Tests\system\Functional\EntityCode
protected function verifyRenderCache($cid, array $tags, $redirected_cid = NULL) {
// Also verify the existence of an entity render cache entry.
$cache_entry = \Drupal::cache('render')
->get($cid);
$this
->assertInstanceOf(\stdClass::class, $cache_entry);
sort($cache_entry->tags);
sort($tags);
$this
->assertSame($cache_entry->tags, $tags);
$is_redirecting_cache_item = isset($cache_entry->data['#cache_redirect']);
if ($redirected_cid === NULL) {
$this
->assertFalse($is_redirecting_cache_item, 'Render cache entry is not a redirect.');
}
else {
// Verify that $cid contains a cache redirect.
$this
->assertTrue($is_redirecting_cache_item, 'Render cache entry is a redirect.');
// Verify that the cache redirect points to the expected CID.
$redirect_cache_metadata = $cache_entry->data['#cache'];
$actual_redirection_cid = $this
->createCacheId($redirect_cache_metadata['keys'], $redirect_cache_metadata['contexts']);
$this
->assertSame($redirected_cid, $actual_redirection_cid);
// Finally, verify that the redirected CID exists and has the same cache
// tags.
$this
->verifyRenderCache($redirected_cid, $tags);
}
}