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. 8.9.x core/tests/Drupal/Tests/Core/Render/RendererTestBase.php \Drupal\Tests\Core\Render\RendererTestBase::assertRenderCacheItem()
  3. 10 core/tests/Drupal/Tests/Core/Render/RendererTestBase.php \Drupal\Tests\Core\Render\RendererTestBase::assertRenderCacheItem()

Asserts a render cache item.

Parameters

string[] $keys: The expected cache keys.

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 267

Class

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

Namespace

Drupal\Tests\Core\Render

Code

protected function assertRenderCacheItem($keys, $data, $bin = 'render') {
    $cache_backend = $this->cacheFactory
        ->get($bin);
    $cached = $cache_backend->get($keys, CacheableMetadata::createFromRenderArray($data));
    $this->assertNotFalse($cached, sprintf('Expected cache item "%s" exists.', implode(':', $keys)));
    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.', implode(':', $keys)));
            }
            else {
                $this->assertEquals($value, $cached->data[$key], sprintf('Cache item "%s" has the expected data.', implode(':', $keys)));
            }
        }
        $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.