function RendererPlaceholdersTest::testPlaceholderingDisabledForPostRequests

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php \Drupal\Tests\Core\Render\RendererPlaceholdersTest::testPlaceholderingDisabledForPostRequests()
  2. 8.9.x core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php \Drupal\Tests\Core\Render\RendererPlaceholdersTest::testPlaceholderingDisabledForPostRequests()
  3. 10 core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php \Drupal\Tests\Core\Render\RendererPlaceholdersTest::testPlaceholderingDisabledForPostRequests()

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

@dataProvider providerPlaceholders

File

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

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 testPlaceholderingDisabledForPostRequests(array $test_element, array $args, array $expected_placeholder_render_array, array|false $placeholder_cache_keys) : void {
    if ($placeholder_cache_keys && !empty($test_element['placeholder']['#cache']['keys'])) {
        $this->setUpMemoryCache();
    }
    else {
        $this->setUpUnusedCache();
    }
    $this->setUpRequest('POST');
    $element = $test_element;
    // Render without replacing placeholders, to allow this test to see which
    // #attached[placeholders] there are, if any.
    $this->renderer
        ->executeInRenderContext(new RenderContext(), function () use (&$element) {
        return $this->renderer
            ->render($element);
    });
    // Only test cases where the placeholders have been specified manually are
    // allowed to have placeholders. This means that of the different situations
    // listed in providerPlaceholders(), only type B can have attached
    // placeholders. Everything else, whether:
    // 1. manual placeholdering
    // 2. automatic placeholdering via already-present cacheability metadata
    // 3. automatic placeholdering via bubbled cacheability metadata
    // All three of those should NOT result in placeholders.
    if (!isset($test_element['#attached']['placeholders'])) {
        $this->assertFalse(isset($element['#attached']['placeholders']), 'No placeholders created.');
    }
}

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