public function TwigExtensionTest::testSetFilter in Components! 8.2
Same name and namespace in other branches
- 3.x tests/src/Kernel/TwigExtensionTest.php \Drupal\Tests\components\Kernel\TwigExtensionTest::testSetFilter()
Ensures the Twig "set" filter works inside a Drupal instance.
@covers ::setFilter
@dataProvider providerTestSetFilter
File
- tests/
src/ Kernel/ TwigExtensionTest.php, line 110
Class
- TwigExtensionTest
- @coversDefaultClass \Drupal\components\Template\TwigExtension @group components
Namespace
Drupal\Tests\components\KernelCode
public function testSetFilter(string $theme_hook, string $expected) {
$result = NULL;
try {
$element = [
'#theme' => $theme_hook,
'list' => [
'#theme' => 'item_list',
'#items' => [
[
'#type' => 'container',
'#attributes' => [
'id' => 'the_element_id',
'class' => [
'original-container-class',
],
],
],
],
],
];
$result = $this
->render($element);
} catch (\Exception $e) {
$this
->fail('No Exception expected; "' . $e
->getMessage() . '" thrown during: ' . $this
->getName());
}
if (method_exists($this, 'assertStringContainsString')) {
$this
->assertStringContainsString($expected, $result);
}
else {
$this
->assertContains($expected, $result);
}
}