You are here

public function RendererRecursionTest::testRenderRecursionWithNestedRender in Drupal 8

Same name and namespace in other branches
  1. 9 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() {
  list($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', (string) $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.');
}