function RendererPlaceholdersTest::testCacheableParentWithPostRequest

Same name and namespace in other branches
  1. 8.9.x 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()
  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 766

Class

RendererPlaceholdersTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Render%21Renderer.php/class/Renderer/9" title="Turns a render array into an HTML string." class="local">\Drupal\Core\Render\Renderer</a> @covers <a href="/api/drupal/core%21lib%21Drupal%21Core%21Render%21RenderCache.php/class/RenderCache/9" title="Wraps the caching logic for the render caching system." class="local">\Drupal\Core\Render\RenderCache</a> @covers <a href="/api/drupal/core%21lib%21Drupal%21Core%21Render%21PlaceholderingRenderCache.php/class/PlaceholderingRenderCache/9" title="Adds automatic placeholdering to the RenderCache." class="local">\Drupal\Core\Render\PlaceholderingRenderCache</a> @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, [], []);
}

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