function EntityCacheTagsTestBase::verifyRenderCache

Same name in other branches
  1. 8.9.x core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php \Drupal\system\Tests\Entity\EntityCacheTagsTestBase::verifyRenderCache()
  2. 8.9.x core/modules/system/tests/src/Functional/Entity/EntityCacheTagsTestBase.php \Drupal\Tests\system\Functional\Entity\EntityCacheTagsTestBase::verifyRenderCache()
  3. 10 core/modules/system/tests/src/Functional/Entity/EntityCacheTagsTestBase.php \Drupal\Tests\system\Functional\Entity\EntityCacheTagsTestBase::verifyRenderCache()
  4. 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.

5 calls to EntityCacheTagsTestBase::verifyRenderCache()
BlockContentCacheTagsTest::testBlock in core/modules/block_content/tests/src/Functional/BlockContentCacheTagsTest.php
Tests that the block is cached with the correct contexts and tags.
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.
ItemCacheTagsTest::testEntityCreation in core/modules/aggregator/tests/src/Functional/ItemCacheTagsTest.php
Tests that when creating a feed item, the feed tag is invalidated.
ShortcutCacheTagsTest::testEntityCreation in core/modules/shortcut/tests/src/Functional/ShortcutCacheTagsTest.php
Tests that when creating a shortcut, the shortcut set tag is invalidated.

File

core/modules/system/tests/src/Functional/Entity/EntityCacheTagsTestBase.php, line 663

Class

EntityCacheTagsTestBase
Provides helper methods for Entity cache tags tests.

Namespace

Drupal\Tests\system\Functional\Entity

Code

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);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.