function RendererPlaceholdersTest::assertPlaceholderRenderCache

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php \Drupal\Tests\Core\Render\RendererPlaceholdersTest::assertPlaceholderRenderCache()
  2. 10 core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php \Drupal\Tests\Core\Render\RendererPlaceholdersTest::assertPlaceholderRenderCache()
  3. 11.x core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php \Drupal\Tests\Core\Render\RendererPlaceholdersTest::assertPlaceholderRenderCache()

Parameters

false|array $cid_parts:

string[] $bubbled_cache_contexts: Additional cache contexts that were bubbled when the placeholder was rendered.

array $expected_data: A render array with the expected values.

3 calls to RendererPlaceholdersTest::assertPlaceholderRenderCache()
RendererPlaceholdersTest::testCacheableParent in core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php
@covers ::render @covers ::doRender @covers \Drupal\Core\Render\RenderCache::get @covers \Drupal\Core\Render\RenderCache::set @covers \Drupal\Core\Render\RenderCache::createCacheID
RendererPlaceholdersTest::testCacheableParentWithPostRequest in core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php
@covers ::render @covers ::doRender @covers \Drupal\Core\Render\RenderCache::get @covers ::replacePlaceholders
RendererPlaceholdersTest::testUncacheableParent in core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php
@covers ::render @covers ::doRender

File

core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php, line 557

Class

RendererPlaceholdersTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Render%21Renderer.php/class/Renderer/8.9.x" title="Turns a render array into a HTML string." class="local">\Drupal\Core\Render\Renderer</a> @covers <a href="/api/drupal/core%21lib%21Drupal%21Core%21Render%21RenderCache.php/class/RenderCache/8.9.x" title="Wraps the caching logic for the render caching system." class="local">\Drupal\Core\Render\RenderCache</a> @covers <a href="/api/drupal/core%21lib%21Drupal%21Core%21Render%21PlaceholderingRenderCache.php/class/PlaceholderingRenderCache/8.9.x" title="Adds automatic placeholdering to the RenderCache." class="local">\Drupal\Core\Render\PlaceholderingRenderCache</a> @group Render

Namespace

Drupal\Tests\Core\Render

Code

protected function assertPlaceholderRenderCache($cid_parts, array $bubbled_cache_contexts, array $expected_data) {
    if ($cid_parts !== FALSE) {
        if ($bubbled_cache_contexts) {
            // Verify render cached placeholder.
            $cached_element = $this->memoryCache
                ->get(implode(':', $cid_parts))->data;
            $expected_redirect_element = [
                '#cache_redirect' => TRUE,
                '#cache' => $expected_data['#cache'] + [
                    'keys' => $cid_parts,
                    'bin' => 'render',
                ],
            ];
            $this->assertEquals($expected_redirect_element, $cached_element, 'The correct cache redirect exists.');
        }
        // Verify render cached placeholder.
        $cached = $this->memoryCache
            ->get(implode(':', array_merge($cid_parts, $bubbled_cache_contexts)));
        $cached_element = $cached->data;
        $this->assertEquals($expected_data, $cached_element, 'The correct data is cached: the stored #markup and #attached properties are not affected by the placeholder being replaced.');
    }
}

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