You are here

public function RendererPlaceholdersTest::testCacheableParentWithPostRequest in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php \Drupal\Tests\Core\Render\RendererPlaceholdersTest::testCacheableParentWithPostRequest()
  2. 10 core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php \Drupal\Tests\Core\Render\RendererPlaceholdersTest::testCacheableParentWithPostRequest()

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

@dataProvider providerPlaceholders

File

core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php, line 763
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 testCacheableParentWithPostRequest($test_element, $args) {
  $this
    ->setUpUnusedCache();

  // Verify behavior when handling a non-GET request, e.g. a POST request:
  // also in that case, placeholders must be replaced.
  $this
    ->setUpRequest('POST');

  // POST request: #cache enabled, cache miss.
  $element = $test_element;
  $element['#cache'] = [
    'keys' => [
      'placeholder_test_POST',
    ],
  ];
  $element['#prefix'] = '<p>#cache enabled, POST</p>';
  $output = $this->renderer
    ->renderRoot($element);
  $this
    ->assertSame('<p>#cache enabled, POST</p><p>This is a rendered placeholder!</p>', (string) $output, 'Output is overridden.');
  $this
    ->assertTrue(isset($element['#printed']), 'No cache hit');
  $this
    ->assertSame('<p>#cache enabled, POST</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.');

  // Even when the child element's placeholder is cacheable, it should not
  // generate a render cache item.
  $this
    ->assertPlaceholderRenderCache(FALSE, [], []);
}