You are here

public function ThemeRenderAndAutoescapeTest::testThemeRenderAndAutoescape in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Theme/ThemeRenderAndAutoescapeTest.php \Drupal\KernelTests\Core\Theme\ThemeRenderAndAutoescapeTest::testThemeRenderAndAutoescape()
  2. 9 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 33
Contains \Drupal\KernelTests\Core\Theme\ThemeRenderAndAutoescapeTest.

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);
}