function RendererPlaceholdersTest::testUncacheableParent

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

@covers ::render @covers ::doRender

@dataProvider providerPlaceholders

File

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

Class

RendererPlaceholdersTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Render%21Renderer.php/class/Renderer/11.x" title="Turns a render array into an HTML string." class="local">\Drupal\Core\Render\Renderer</a> @covers <a href="/api/drupal/core%21lib%21Drupal%21Core%21Render%21RenderCache.php/class/RenderCache/11.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/11.x" title="Adds automatic placeholdering to the RenderCache." class="local">\Drupal\Core\Render\PlaceholderingRenderCache</a> @group Render

Namespace

Drupal\Tests\Core\Render

Code

public function testUncacheableParent(array $element, array $args, array $expected_placeholder_render_array, array|false $placeholder_cache_keys, array $bubbled_cache_contexts, array $bubbled_cache_tags, array $placeholder_expected_render_cache_array) : void {
    if ($placeholder_cache_keys) {
        $this->setUpMemoryCache();
    }
    else {
        $this->setUpUnusedCache();
    }
    $this->setUpRequest('GET');
    // No #cache on parent element.
    $element['#prefix'] = '<p>#cache disabled</p>';
    $output = $this->renderer
        ->renderRoot($element);
    $this->assertSame('<p>#cache disabled</p><p>This is a rendered placeholder!</p>', (string) $output, 'Output is overridden.');
    $this->assertSame('<p>#cache disabled</p><p>This is a rendered placeholder!</p>', (string) $element['#markup'], '#markup is overridden.');
    $expected_js_settings = [
        'foo' => 'bar',
        'dynamic_animal' => $args[0],
    ];
    $this->assertSame($element['#attached']['drupalSettings'], $expected_js_settings, '#attached is modified; both the original JavaScript setting and the one added by the placeholder #lazy_builder callback exist.');
    $this->assertPlaceholderRenderCache($placeholder_cache_keys, $placeholder_expected_render_cache_array);
}

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