You are here

public function PotxTest::testDrupal8Twig in Translation template extractor 8

Test parsing of Drupal 8 Twig templates.

File

tests/src/Kernel/PotxTest.php, line 260

Class

PotxTest
Ensure that the translation template extractor functions properly.

Namespace

Drupal\Tests\potx\Kernel

Code

public function testDrupal8Twig() {
  $filename = $this->tests_root . '/potx_test_8.html.twig';
  $this
    ->parseFile($filename, POTX_API_8);
  $this
    ->assertMsgId('This is a translated string.');
  $this
    ->assertMsgId('A double-quoted string');
  $this
    ->assertMsgId('Here\'s a double-quoted "and escaped" string.');
  $this
    ->assertMsgId("Here's a string with an escaped quote.");
  $this
    ->assertNoMsgId('This is a concatenated string that should not be picked up.');
  $this
    ->assertNoMsgId('This is a concatenated string ');
  $this
    ->assertNoMsgId('that should not be picked up.');
  $this
    ->assertNoMsgId('This is an untranslated string.');
  $this
    ->assertMsgId('Variable string.');
  $this
    ->assertMsgId('Variable string with @placeholder.');
  $this
    ->assertMsgId('Variable string with @translatedPlaceholder.');
  $this
    ->assertMsgId('translatedPlaceholder');
  $this
    ->assertMsgId('An include component template');
  $this
    ->assertMsgId('Hello sun.');
  $this
    ->assertMsgIdContext('Hello sun, with context.', 'Lolspeak');
  $this
    ->assertMsgId('Hello Earth.');
  $this
    ->assertMsgId('Hello moon.');
  $this
    ->assertPluralId('Hello star.', 'Hello @count stars.');
  $this
    ->assertMsgId('Escaped: @string');
  $this
    ->assertMsgId('Placeholder: %string');
  $this
    ->assertMsgId('This @node.type is submitted by @author.name, and has a length of: @count. It contains: %node.numbers and @node.bad_text.');
  $this
    ->assertMsgIdContext('I have context.', 'Lolspeak');
  $this
    ->assertNoMsgIdContext('I have no context.', 'zz');
  $this
    ->assertMsgIdContext('I have context and another parameter.', 'Lolspeak');
  $this
    ->assertMsgId('A multiline\\n    trans block.');
  $this
    ->assertMsgId('Test string with @extra_filter');
  $this
    ->assertMsgId('Test string with @multiple_filters');
  $this
    ->assertMsgId('Test string with %multiple_filters');
  $this
    ->assertMsgID('Meta-data for a help topic title');
  $this
    ->assertNoMsgID('Meta-data that should not be translated');
  $this
    ->assertPotxErrors([
    'Concatenation error' => t('Uses of the t filter in Twig templates should start with a single literal string, and should not be chained.'),
  ]);
}