You are here

public function RendererPlaceholdersTest::testRecursivePlaceholder in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php \Drupal\Tests\Core\Render\RendererPlaceholdersTest::testRecursivePlaceholder()

Tests a placeholder that adds another placeholder.

E.g. when rendering a node in a placeholder the rendering of that node needs a placeholder of its own to be executed (to render the node links).

@covers ::render @covers ::doRender @covers ::replacePlaceholders

File

core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php, line 795
Contains \Drupal\Tests\Core\Render\RendererPlaceholdersTest.

Class

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

Namespace

Drupal\Tests\Core\Render

Code

public function testRecursivePlaceholder() {
  $args = [
    $this
      ->randomContextValue(),
  ];
  $element = [];
  $element['#create_placeholder'] = TRUE;
  $element['#lazy_builder'] = [
    'Drupal\\Tests\\Core\\Render\\RecursivePlaceholdersTest::callback',
    $args,
  ];
  $output = $this->renderer
    ->renderRoot($element);
  $this
    ->assertEquals('<p>This is a rendered placeholder!</p>', $output, 'The output has been modified by the indirect, recursive placeholder #lazy_builder callback.');
  $this
    ->assertSame((string) $element['#markup'], '<p>This is a rendered placeholder!</p>', '#markup is overridden by the indirect, recursive placeholder #lazy_builder callback.');
  $expected_js_settings = [
    'dynamic_animal' => $args[0],
  ];
  $this
    ->assertSame($element['#attached']['drupalSettings'], $expected_js_settings, '#attached is modified by the indirect, recursive placeholder #lazy_builder callback.');
}