protected function TwigMarkupInterfaceTest::renderObjectWithTwig in Drupal 8
Same name and namespace in other branches
- 9 core/tests/Drupal/KernelTests/Core/Theme/TwigMarkupInterfaceTest.php \Drupal\KernelTests\Core\Theme\TwigMarkupInterfaceTest::renderObjectWithTwig()
- 10 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 behavior 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 85 - Contains \Drupal\KernelTests\Core\Theme\TwigMarkupInterfaceTest.
Class
- TwigMarkupInterfaceTest
- Tests Twig with MarkupInterface objects.
Namespace
Drupal\KernelTests\Core\ThemeCode
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' => [
'variable' => $variable,
],
];
return $renderer
->render($elements);
});
}