function RendererRecursionTest::testRenderRecursionWithNestedRender

Same name in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php \Drupal\Tests\Core\Render\RendererRecursionTest::testRenderRecursionWithNestedRender()
  2. 10 core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php \Drupal\Tests\Core\Render\RendererRecursionTest::testRenderRecursionWithNestedRender()
  3. 11.x core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php \Drupal\Tests\Core\Render\RendererRecursionTest::testRenderRecursionWithNestedRender()

::render() may be called from anywhere.

Including from inside of another ::renderRoot() call. Bubbling must be performed.

@covers ::renderRoot @covers ::render @covers ::doRender

File

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

Class

RendererRecursionTest
@coversDefaultClass \Drupal\Core\Render\Renderer @group Render

Namespace

Drupal\Tests\Core\Render

Code

public function testRenderRecursionWithNestedRender() {
    [
        $complex_child_markup,
        $parent_markup,
        $complex_child_template,
    ] = $this->setUpRenderRecursionComplexElements();
    $renderer = $this->renderer;
    $this->setUpRequest();
    $callable = function ($markup) use ($renderer, $complex_child_template) {
        $this->assertStringStartsWith('<drupal-render-placeholder', $markup, 'Rendered complex child output as expected, without the placeholder replaced, i.e. with just the placeholder.');
        return $markup;
    };
    $page = [
        'content' => [
            'complex_child' => $complex_child_template,
            '#post_render' => [
                $callable,
            ],
            '#suffix' => $parent_markup,
        ],
    ];
    $output = $renderer->renderRoot($page);
    $this->assertEquals('<p>This is a rendered placeholder!</p><p>Rendered!</p>', $output, 'Rendered output as expected, with the placeholder replaced.');
    $this->assertContains('test:complex_child', $page['#cache']['tags'], 'Cache tag bubbling performed.');
    $this->assertContains('dynamic_animal', array_keys($page['#attached']['drupalSettings']), 'Asset bubbling performed.');
}

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