You are here

public function ThemeRenderAndAutoescapeTest::testThemeRenderAndAutoescape in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 41
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
    ->assertInternalType('string', $output);
}