You are here

protected function EntityCacheTagsTestBase::verifyRenderCache in Drupal 8

Same name in this branch
  1. 8 core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php \Drupal\system\Tests\Entity\EntityCacheTagsTestBase::verifyRenderCache()
  2. 8 core/modules/system/tests/src/Functional/Entity/EntityCacheTagsTestBase.php \Drupal\Tests\system\Functional\Entity\EntityCacheTagsTestBase::verifyRenderCache()
Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Functional/Entity/EntityCacheTagsTestBase.php \Drupal\Tests\system\Functional\Entity\EntityCacheTagsTestBase::verifyRenderCache()
  2. 10 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
    ->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);
  }
}