function RendererRecursionTest::testRenderRecursionWithNestedRenderInIsolation

Same name and namespace in other branches
  1. 10 core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php \Drupal\Tests\Core\Render\RendererRecursionTest::testRenderRecursionWithNestedRenderInIsolation()

::renderInIsolation() may be called from anywhere.

Including from inside of another ::renderRoot() call.

@covers ::renderRoot @covers ::renderInIsolation

File

core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php, line 103

Class

RendererRecursionTest
@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> @group Render

Namespace

Drupal\Tests\Core\Render

Code

public function testRenderRecursionWithNestedRenderInIsolation() : void {
    [
        $complex_child_markup,
        $parent_markup,
        $complex_child_template,
    ] = $this->setUpRenderRecursionComplexElements();
    $renderer = $this->renderer;
    $this->setUpRequest();
    $complex_child = $complex_child_template;
    $callable = function ($elements) use ($renderer, $complex_child) {
        $elements['#markup'] = $renderer->renderInIsolation($complex_child);
        $this->assertEquals('<p>This is a rendered placeholder!</p>', $elements['#markup'], 'Rendered complex child output as expected, with the placeholder replaced.');
        return $elements;
    };
    $page = [
        'content' => [
            '#pre_render' => [
                $callable,
            ],
            '#suffix' => $parent_markup,
        ],
    ];
    $output = $renderer->renderRoot($page);
    $this->assertEquals('<p>This is a rendered placeholder!</p>' . $parent_markup, $output, 'Rendered output as expected, with the placeholder replaced.');
    $this->assertNotContains('test:complex_child', $page['#cache']['tags'], 'Cache tag bubbling not performed.');
    $this->assertEmpty($page['#attached'], 'Asset bubbling not performed.');
}

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