function RendererBubblingTest::testOverWriteCacheKeys

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

Tests that an element's cache keys cannot be changed during its rendering.

File

core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php, line 532

Class

RendererBubblingTest
@coversDefaultClass \Drupal\Core\Render\Renderer @group Render

Namespace

Drupal\Tests\Core\Render

Code

public function testOverWriteCacheKeys() : void {
    $this->setUpRequest();
    $this->setUpMemoryCache();
    // Ensure a logic exception
    $data = [
        '#cache' => [
            'keys' => [
                'llama',
                'bar',
            ],
        ],
        '#pre_render' => [
            __NAMESPACE__ . '\\BubblingTest::bubblingCacheOverwritePrerender',
        ],
    ];
    $this->expectException(\LogicException::class);
    $this->expectExceptionMessage('Cache keys may not be changed after initial setup. Use the contexts property instead to bubble additional metadata.');
    $this->renderer
        ->renderRoot($data);
}

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