function ThemeRenderAndAutoescapeTest::testBubblingMetadataWithRenderable

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Theme/ThemeRenderAndAutoescapeTest.php \Drupal\KernelTests\Core\Theme\ThemeRenderAndAutoescapeTest::testBubblingMetadataWithRenderable()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Theme/ThemeRenderAndAutoescapeTest.php \Drupal\KernelTests\Core\Theme\ThemeRenderAndAutoescapeTest::testBubblingMetadataWithRenderable()
  3. 11.x core/tests/Drupal/KernelTests/Core/Theme/ThemeRenderAndAutoescapeTest.php \Drupal\KernelTests\Core\Theme\ThemeRenderAndAutoescapeTest::testBubblingMetadataWithRenderable()

Ensure cache metadata is bubbled when using theme_render_and_autoescape().

File

core/tests/Drupal/KernelTests/Core/Theme/ThemeRenderAndAutoescapeTest.php, line 116

Class

ThemeRenderAndAutoescapeTest
Tests the theme_render_and_autoescape() function.

Namespace

Drupal\KernelTests\Core\Theme

Code

public function testBubblingMetadataWithRenderable() : void {
    $link = new Link('', Url::fromRoute('<current>'));
    $context = new RenderContext();
    // Use a closure here since we need to render with a render context.
    $theme_render_and_autoescape = function () use ($link) {
        return theme_render_and_autoescape($link);
    };
    
    /** @var \Drupal\Core\Render\RendererInterface $renderer */
    $renderer = \Drupal::service('renderer');
    $output = $renderer->executeInRenderContext($context, $theme_render_and_autoescape);
    $this->assertEquals('<a href="/' . urlencode('<none>') . '"></a>', $output);
    
    /** @var \Drupal\Core\Render\BubbleableMetadata $metadata */
    $metadata = $context->pop();
    $this->assertEquals([
        'route',
    ], $metadata->getCacheContexts());
}

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