function ThemeRenderAndAutoescapeTest::testThemeRenderAndAutoescape

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

@dataProvider providerTestThemeRenderAndAutoescape

File

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

Class

ThemeRenderAndAutoescapeTest
Tests the theme_render_and_autoescape() function.

Namespace

Drupal\KernelTests\Core\Theme

Code

public function testThemeRenderAndAutoescape($arg, $expected) {
    if (is_array($arg) && isset($arg['#type']) && $arg['#type'] === 'link') {
        $arg = Link::createFromRoute($arg['#title'], $arg['#url']);
    }
    $context = new RenderContext();
    // Use a closure here since we need to render with a render context.
    $theme_render_and_autoescape = function () use ($arg) {
        return theme_render_and_autoescape($arg);
    };
    
    /** @var \Drupal\Core\Render\RendererInterface $renderer */
    $renderer = \Drupal::service('renderer');
    $output = $renderer->executeInRenderContext($context, $theme_render_and_autoescape);
    $this->assertEquals($expected, $output);
    $this->assertIsString($output);
}

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