You are here

public function RendererRecursionTest::testRenderRecursionWithNestedRender in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 75
Contains \Drupal\Tests\Core\Render\RendererRecursionTest.

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
      ->assertTrue(strpos($markup, '<drupal-render-placeholder') === 0, '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
    ->assertTrue(in_array('test:complex_child', $page['#cache']['tags']), 'Cache tag bubbling performed.');
  $this
    ->assertTrue(in_array('dynamic_animal', array_keys($page['#attached']['drupalSettings'])), 'Asset bubbling performed.');
}