You are here

public function TwigExtensionTest::testAddFilter in Components! 3.x

Same name and namespace in other branches
  1. 8.2 tests/src/Kernel/TwigExtensionTest.php \Drupal\Tests\components\Kernel\TwigExtensionTest::testAddFilter()

Ensures the Twig "add" filter works inside a Drupal instance.

@covers ::addFilter

@dataProvider providerTestAddFilter

File

tests/src/Kernel/TwigExtensionTest.php, line 153

Class

TwigExtensionTest
@coversDefaultClass \Drupal\components\Template\TwigExtension @group components

Namespace

Drupal\Tests\components\Kernel

Code

public function testAddFilter(string $theme_hook, string $expected) {
  try {
    $element = [
      '#theme' => $theme_hook,
      'list' => [
        '#theme' => 'item_list',
        '#items' => [
          [
            '#type' => 'container',
            '#attributes' => [
              'class' => [
                'original-container-class',
              ],
            ],
          ],
        ],
      ],
    ];
    $result = $this
      ->render($element);
  } catch (\Exception $e) {
    $this
      ->fail('No Exception expected; "' . $e
      ->getMessage() . '" thrown during: ' . $this
      ->getName());
  }
  $this
    ->assertStringContainsString($expected, $result);
}