You are here

public function RendererPlaceholdersTest::testUncacheableParent 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::testUncacheableParent()
  2. 9 core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php \Drupal\Tests\Core\Render\RendererPlaceholdersTest::testUncacheableParent()

@covers ::render @covers ::doRender

@dataProvider providerPlaceholders

File

core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php, line 588
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 testUncacheableParent($element, $args, array $expected_placeholder_render_array, $placeholder_cid_parts, array $bubbled_cache_contexts, array $bubbled_cache_tags, array $placeholder_expected_render_cache_array) {
  if ($placeholder_cid_parts) {
    $this
      ->setupMemoryCache();
  }
  else {
    $this
      ->setUpUnusedCache();
  }
  $this
    ->setUpRequest('GET');

  // No #cache on parent element.
  $element['#prefix'] = '<p>#cache disabled</p>';
  $output = $this->renderer
    ->renderRoot($element);
  $this
    ->assertSame('<p>#cache disabled</p><p>This is a rendered placeholder!</p>', (string) $output, 'Output is overridden.');
  $this
    ->assertSame('<p>#cache disabled</p><p>This is a rendered placeholder!</p>', (string) $element['#markup'], '#markup is overridden.');
  $expected_js_settings = [
    'foo' => 'bar',
    'dynamic_animal' => $args[0],
  ];
  $this
    ->assertSame($element['#attached']['drupalSettings'], $expected_js_settings, '#attached is modified; both the original JavaScript setting and the one added by the placeholder #lazy_builder callback exist.');
  $this
    ->assertPlaceholderRenderCache($placeholder_cid_parts, $bubbled_cache_contexts, $placeholder_expected_render_cache_array);
}