You are here

protected function TwigMarkupInterfaceTest::renderObjectWithTwig in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Theme/TwigMarkupInterfaceTest.php \Drupal\KernelTests\Core\Theme\TwigMarkupInterfaceTest::renderObjectWithTwig()

Return value

\Drupal\Component\Render\MarkupInterface The rendered HTML.

2 calls to TwigMarkupInterfaceTest::renderObjectWithTwig()
TwigMarkupInterfaceTest::testEmptyTranslation in core/tests/Drupal/KernelTests/Core/Theme/TwigMarkupInterfaceTest.php
Tests behaviour if a string is translated to become an empty string.
TwigMarkupInterfaceTest::testMarkupInterfaceEmpty in core/tests/Drupal/KernelTests/Core/Theme/TwigMarkupInterfaceTest.php
@dataProvider providerTestMarkupInterfaceEmpty

File

core/tests/Drupal/KernelTests/Core/Theme/TwigMarkupInterfaceTest.php, line 81
Contains \Drupal\KernelTests\Core\Theme\ThemeRenderAndAutoescapeTest.

Class

TwigMarkupInterfaceTest
Tests Twig with MarkupInterface objects.

Namespace

Drupal\KernelTests\Core\Theme

Code

protected function renderObjectWithTwig($variable) {

  /** @var \Drupal\Core\Render\RendererInterface $renderer */
  $renderer = \Drupal::service('renderer');
  $context = new RenderContext();
  return $renderer
    ->executeInRenderContext($context, function () use ($renderer, $variable) {
    $elements = [
      '#type' => 'inline_template',
      '#template' => '{%- if variable is not empty -%}<span>{{ variable }}</span>{%- endif -%}',
      '#context' => array(
        'variable' => $variable,
      ),
    ];
    return $renderer
      ->render($elements);
  });
}