function RendererPlaceholdersTest::testRecursivePlaceholder

Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php \Drupal\Tests\Core\Render\RendererPlaceholdersTest::testRecursivePlaceholder()
  2. 10 core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php \Drupal\Tests\Core\Render\RendererPlaceholdersTest::testRecursivePlaceholder()
  3. 11.x 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

Class

RendererPlaceholdersTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Render%21Renderer.php/class/Renderer/9" title="Turns a render array into an HTML string." class="local">\Drupal\Core\Render\Renderer</a> @covers <a href="/api/drupal/core%21lib%21Drupal%21Core%21Render%21RenderCache.php/class/RenderCache/9" title="Wraps the caching logic for the render caching system." class="local">\Drupal\Core\Render\RenderCache</a> @covers <a href="/api/drupal/core%21lib%21Drupal%21Core%21Render%21PlaceholderingRenderCache.php/class/PlaceholderingRenderCache/9" title="Adds automatic placeholdering to the RenderCache." class="local">\Drupal\Core\Render\PlaceholderingRenderCache</a> @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.');
}

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