function RendererPlaceholdersTest::testCacheableParentWithPostRequest

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php \Drupal\Tests\Core\Render\RendererPlaceholdersTest::testCacheableParentWithPostRequest()
  2. 8.9.x core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php \Drupal\Tests\Core\Render\RendererPlaceholdersTest::testCacheableParentWithPostRequest()
  3. 11.x 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 731

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 testCacheableParentWithPostRequest(array $test_element, array $args) : void {
  $this->setUpMemoryCache();
  // 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, []);
}

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