function RendererTest::testRenderTwice

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Render/RendererTest.php \Drupal\Tests\Core\Render\RendererTest::testRenderTwice()
  2. 8.9.x core/tests/Drupal/Tests/Core/Render/RendererTest.php \Drupal\Tests\Core\Render\RendererTest::testRenderTwice()
  3. 11.x core/tests/Drupal/Tests/Core/Render/RendererTest.php \Drupal\Tests\Core\Render\RendererTest::testRenderTwice()

Tests rendering same render array twice.

Tests that a first render returns the rendered output and a second doesn't because of the #printed property. Also tests that correct metadata has been set for re-rendering.

@covers ::render @covers ::doRender

@dataProvider providerRenderTwice

File

core/tests/Drupal/Tests/Core/Render/RendererTest.php, line 654

Class

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

Namespace

Drupal\Tests\Core\Render

Code

public function testRenderTwice($build) : void {
    $this->assertEquals('kittens', $this->renderer
        ->renderRoot($build));
    $this->assertEquals('kittens', $build['#markup']);
    $this->assertEquals([
        'kittens-147',
    ], $build['#cache']['tags']);
    $this->assertTrue($build['#printed']);
    // We don't want to reprint already printed render arrays.
    $this->assertEquals('', $this->renderer
        ->renderRoot($build));
}

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