You are here

public function TwigTransTest::testEmptyTwigTransTags in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/system/tests/src/Functional/Theme/TwigTransTest.php \Drupal\Tests\system\Functional\Theme\TwigTransTest::testEmptyTwigTransTags()

Tests empty Twig "trans" tags.

File

core/modules/system/tests/src/Functional/Theme/TwigTransTest.php, line 103

Class

TwigTransTest
Tests Twig "trans" tags.

Namespace

Drupal\Tests\system\Functional\Theme

Code

public function testEmptyTwigTransTags() {
  $elements = [
    '#type' => 'inline_template',
    '#template' => '{% trans %}{% endtrans %}',
  ];

  /** @var \Drupal\Core\Render\RendererInterface $renderer */
  $renderer = \Drupal::service('renderer');
  try {
    $renderer
      ->renderPlain($elements);
    $this
      ->fail('{% trans %}{% endtrans %} did not throw an exception.');
  } catch (SyntaxError $e) {
    $this
      ->assertStringContainsString('{% trans %} tag cannot be empty', $e
      ->getMessage());
  } catch (\Exception $e) {
    $this
      ->fail('{% trans %}{% endtrans %} threw an unexpected exception.');
  }
}