You are here

public function RendererPlaceholdersTest::testRecursivePlaceholder in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php \Drupal\Tests\Core\Render\RendererPlaceholdersTest::testRecursivePlaceholder()
  2. 9 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 836
Contains \Drupal\Tests\Core\Render\RendererPlaceholdersTest.

Class

RendererPlaceholdersTest
@coversDefaultClass \Drupal\Core\Render\Renderer @covers \Drupal\Core\Render\RenderCache @covers \Drupal\Core\Render\PlaceholderingRenderCache @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.');
}