You are here

public function RendererTest::testRenderTwice in Drupal 10

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

Class

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

Namespace

Drupal\Tests\Core\Render

Code

public function testRenderTwice($build) {
  $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));
}