function EntityCacheTagsTestBase::verifyRenderCache
Same name in this branch
- 8.9.x core/modules/system/tests/src/Functional/Entity/EntityCacheTagsTestBase.php \Drupal\Tests\system\Functional\Entity\EntityCacheTagsTestBase::verifyRenderCache()
Same name in other branches
- 9 core/modules/system/tests/src/Functional/Entity/EntityCacheTagsTestBase.php \Drupal\Tests\system\Functional\Entity\EntityCacheTagsTestBase::verifyRenderCache()
- 10 core/modules/system/tests/src/Functional/Entity/EntityCacheTagsTestBase.php \Drupal\Tests\system\Functional\Entity\EntityCacheTagsTestBase::verifyRenderCache()
- 11.x 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/ 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/ Entity/ EntityCacheTagsTestBase.php, line 686
Class
- EntityCacheTagsTestBase
- Provides helper methods for Entity cache tags tests.
Namespace
Drupal\system\Tests\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->assertTrue($cache_entry, 'A render cache entry exists.');
sort($cache_entry->tags);
sort($tags);
$this->assertIdentical($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.');
// If this is a redirecting cache item unlike we expected, log it.
if ($is_redirecting_cache_item) {
debug($cache_entry->data);
}
}
else {
// Verify that $cid contains a cache redirect.
$this->assertTrue($is_redirecting_cache_item, 'Render cache entry is a redirect.');
// If this is not a redirecting cache item unlike we expected, log it.
if (!$is_redirecting_cache_item) {
debug($cache_entry->data);
}
// 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->assertIdentical($redirected_cid, $actual_redirection_cid);
// Finally, verify that the redirected CID exists and has the same cache
// tags.
$this->verifyRenderCache($redirected_cid, $tags);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.