function TwigTransTest::testEmptyTwigTransTags

Same name in other branches
  1. 9 core/modules/system/tests/src/Functional/Theme/TwigTransTest.php \Drupal\Tests\system\Functional\Theme\TwigTransTest::testEmptyTwigTransTags()
  2. 10 core/modules/system/tests/src/Functional/Theme/TwigTransTest.php \Drupal\Tests\system\Functional\Theme\TwigTransTest::testEmptyTwigTransTags()
  3. 11.x core/modules/system/tests/src/Functional/Theme/TwigTransTest.php \Drupal\Tests\system\Functional\Theme\TwigTransTest::testEmptyTwigTransTags()

Test empty Twig "trans" tags.

File

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

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 (\Twig_Error_Syntax $e) {
        $this->assertStringContainsString('{% trans %} tag cannot be empty', $e->getMessage());
    } catch (\Exception $e) {
        $this->fail('{% trans %}{% endtrans %} threw an unexpected exception.');
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.