You are here

public function TwigExtensionTest::testTemplateFunction in Components! 8.2

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

Ensures the Twig template() function works inside a Drupal instance.

@covers ::template

Throws

\Exception

File

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

Class

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

Namespace

Drupal\Tests\components\Kernel

Code

public function testTemplateFunction() {
  $result = NULL;
  try {
    $element = [
      '#theme' => 'components_twig_extension_test_template_function',
      '#items' => [
        'first item',
        'second item',
      ],
    ];
    $result = $this
      ->render($element);
  } catch (\Exception $e) {
    $this
      ->fail('No Exception expected; "' . $e
      ->getMessage() . '" thrown during: ' . $this
      ->getName());
  }
  $expected = '<ul><li>first item</li><li>second item</li></ul>';
  if (method_exists($this, 'assertStringContainsString')) {
    $this
      ->assertStringContainsString($expected, $result);
  }
  else {
    $this
      ->assertContains($expected, $result);
  }
}