You are here

protected function RendererTestBase::assertRenderCacheItem in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Render/RendererTestBase.php \Drupal\Tests\Core\Render\RendererTestBase::assertRenderCacheItem()

Asserts a render cache item.

Parameters

string $cid: The expected cache ID.

mixed $data: The expected data for that cache ID.

string $bin: The expected cache bin.

3 calls to RendererTestBase::assertRenderCacheItem()
RendererBubblingTest::testConditionalCacheContextBubblingSelfHealing in core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php
Tests the self-healing of the redirect with conditional cache contexts.
RendererBubblingTest::testContextBubblingCustomCacheBin in core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php
Tests cache context bubbling with a custom cache bin.
RendererBubblingTest::testContextBubblingEdgeCases in core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php
Tests cache context bubbling in edge cases, because it affects the CID.

File

core/tests/Drupal/Tests/Core/Render/RendererTestBase.php, line 248
Contains \Drupal\Tests\Core\Render\RendererTestBase.

Class

RendererTestBase
Base class for the actual unit tests testing \Drupal\Core\Render\Renderer.

Namespace

Drupal\Tests\Core\Render

Code

protected function assertRenderCacheItem($cid, $data, $bin = 'render') {
  $cache_backend = $this->cacheFactory
    ->get($bin);
  $cached = $cache_backend
    ->get($cid);
  $this
    ->assertNotFalse($cached, sprintf('Expected cache item "%s" exists.', $cid));
  if ($cached !== FALSE) {
    $this
      ->assertEquals($data, $cached->data, sprintf('Cache item "%s" has the expected data.', $cid));
    $this
      ->assertSame(Cache::mergeTags($data['#cache']['tags'], [
      'rendered',
    ]), $cached->tags, "The cache item's cache tags also has the 'rendered' cache tag.");
  }
}