public function TwigExtensionFunctionsTest::testTemplate in Components! 3.x
Same name and namespace in other branches
- 8.2 tests/src/Unit/TwigExtensionFunctionsTest.php \Drupal\Tests\components\Unit\TwigExtensionFunctionsTest::testTemplate()
Tests creating #theme render arrays within a Twig template.
@covers ::template
@dataProvider providerTestTemplate
Parameters
string $template: The inline template to render.
array $variables: An array of variables to provide to the template.
array $expected: The render array expected to be returned.
string $rendered_output: The HTML output from the rendered $expected array.
File
- tests/
src/ Unit/ TwigExtensionFunctionsTest.php, line 101
Class
- TwigExtensionFunctionsTest
- @coversDefaultClass \Drupal\components\Template\TwigExtension @group components
Namespace
Drupal\Tests\components\UnitCode
public function testTemplate(string $template, array $variables, array $expected, string $rendered_output) {
$this->renderer
->expects($this
->exactly(1))
->method('render')
->with($expected)
->willReturn($rendered_output);
$result = NULL;
try {
$result = $this->twigEnvironment
->render($template, $variables);
} catch (\Exception $e) {
$this
->fail('No Exception expected; "' . $e
->getMessage() . '" thrown during: ' . $this
->getName());
}
$this
->assertEquals($rendered_output, $result, $this
->getName());
}