function RendererTestBase::assertRenderCacheItem

Same name in other branches
  1. 8.9.x 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 249

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->assertEqualsCanonicalizing(array_keys($data), array_keys($cached->data), 'The cache item contains the same parent array keys.');
        foreach ($data as $key => $value) {
            // We do not want to assert on the order of cacheability information.
            // @see https://www.drupal.org/project/drupal/issues/3225328
            if ($key === '#cache') {
                $this->assertEqualsCanonicalizing($value, $cached->data[$key], sprintf('Cache item "%s" has the expected data.', $cid));
            }
            else {
                $this->assertEquals($value, $cached->data[$key], sprintf('Cache item "%s" has the expected data.', $cid));
            }
        }
        $this->assertEqualsCanonicalizing(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.