function RendererTestBase::assertRenderCacheItem

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Render/RendererTestBase.php \Drupal\Tests\Core\Render\RendererTestBase::assertRenderCacheItem()
  2. 10 core/tests/Drupal/Tests/Core/Render/RendererTestBase.php \Drupal\Tests\Core\Render\RendererTestBase::assertRenderCacheItem()
  3. 11.x 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

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

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