function RendererPlaceholdersTest::testRenderLazyBuilderPreview

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

Tests the creation of an element with a lazy_builder_preview.

@covers ::render
@covers ::doRender
@covers \Drupal\Core\Render\RenderCache::get
@covers ::replacePlaceholders

File

core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php, line 1060

Class

RendererPlaceholdersTest
@coversDefaultClass \Drupal\Core\Render\Renderer[[api-linebreak]] @covers \Drupal\Core\Render\RenderCache[[api-linebreak]] @covers \Drupal\Core\Render\PlaceholderingRenderCache[[api-linebreak]] @group Render

Namespace

Drupal\Tests\Core\Render

Code

public function testRenderLazyBuilderPreview() : void {
  $this->setUpRequest();
  $this->setupMemoryCache();
  $this->renderCache = new TestPlaceholderingRenderCache($this->requestStack, $this->cacheFactory, $this->cacheContextsManager, $this->placeholderGenerator);
  $this->renderer = new Renderer($this->callableResolver, $this->themeManager, $this->elementInfo, $this->placeholderGenerator, $this->renderCache, $this->requestStack, $this->rendererConfig);
  $this->cacheContextsManager
    ->expects($this->any())
    ->method('convertTokensToKeys')
    ->willReturnArgument(0);
  $this->callableResolver
    ->expects($this->any())
    ->method('getCallableFromDefinition')
    ->willReturnArgument(0);
  $test_element = $this->generatePlaceholderWithLazyBuilderPreview();
  $element1 = $element2 = $test_element;
  // Render the element twice so that it is in the render cache.
  $result = $this->renderer
    ->renderRoot($element1);
  $result = $this->renderer
    ->renderRoot($element2);
  $placeholder_string = (string) $this->renderCache->placeholderElements[0]['#markup'];
  $this->assertSame($this->renderCache->placeholderElements[0]['#attached']['placeholders'][$placeholder_string]['#preview'], [
    '#markup' => 'Lazy Builder Preview',
  ]);
}

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