protected function TwigTransTest::assertTwigTransTags in Drupal 10
Same name and namespace in other branches
- 8 core/modules/system/tests/src/Functional/Theme/TwigTransTest.php \Drupal\Tests\system\Functional\Theme\TwigTransTest::assertTwigTransTags()
- 9 core/modules/system/tests/src/Functional/Theme/TwigTransTest.php \Drupal\Tests\system\Functional\Theme\TwigTransTest::assertTwigTransTags()
Asserts Twig trans tags.
@internal
1 call to TwigTransTest::assertTwigTransTags()
- TwigTransTest::testTwigTransTags in core/
modules/ system/ tests/ src/ Functional/ Theme/ TwigTransTest.php - Tests Twig "trans" tags.
File
- core/
modules/ system/ tests/ src/ Functional/ Theme/ TwigTransTest.php, line 129
Class
- TwigTransTest
- Tests Twig "trans" tags.
Namespace
Drupal\Tests\system\Functional\ThemeCode
protected function assertTwigTransTags() : void {
// Assert that {% trans "Hello sun." %} is translated correctly.
$this
->assertSession()
->pageTextContains('OH HAI SUNZ');
// Assert that {% trans "Hello sun." %} with {"context": "Lolspeak"} is
// translated correctly.
$this
->assertSession()
->pageTextContains('O HAI SUNZZZZZZZ');
// Assert that {{ "Hello Earth."|trans }} is translated correctly.
$this
->assertSession()
->pageTextContains('O HERRO ERRRF.');
// Assert that {% trans %}Hello moon.{% endtrans %} is translated correctly.
$this
->assertSession()
->pageTextContains('OH HAI TEH MUUN');
// Assert that {% trans %} with {% plural count = 1 %} is translated
// correctly.
$this
->assertSession()
->pageTextContains('O HAI STARRRRR');
// Assert that {% trans %} with {% plural count = 2 %} is translated
// correctly.
$this
->assertSession()
->pageTextContains('O HAI 2 STARZZZZ');
// Assert that {{ token }} was successfully translated and prefixed
// with "@".
$this
->assertSession()
->responseContains('ESCAPEE: &"<>');
// Assert that {{ token|placeholder }} was successfully translated and
// prefixed with "%".
$this
->assertSession()
->responseContains('PLAYSHOLDR: <em class="placeholder">&"<></em>');
// Assert that {{ complex.tokens }} were successfully translated with
// appropriate prefixes.
$this
->assertSession()
->responseContains('DIS complex token HAZ LENGTH OV: 3. IT CONTAYNZ: <em class="placeholder">12345</em> AN &"<>.');
// Assert that {% trans %} with a context only msgid is excluded from
// translation.
$this
->assertSession()
->pageTextContains('I have context.');
// Assert that {% trans with {"context": "Lolspeak"} %} was successfully
// translated with context.
$this
->assertSession()
->pageTextContains('I HAZ KONTEX.');
// Assert that {% trans with {"langcode": "zz"} %} is successfully
// translated in specified language.
$this
->assertSession()
->pageTextContains('O HAI NU TXT.');
// Assert that {% trans with {"context": "Lolspeak", "langcode": "zz"} %}
// is successfully translated with context in specified language.
$this
->assertSession()
->pageTextContains('O HAI NU TXTZZZZ.');
// Makes sure https://www.drupal.org/node/2489024 doesn't happen without
// twig debug.
// Ensure that running php code inside a Twig trans is not possible.
$this
->assertSession()
->pageTextNotContains(pi());
}