You are here

public function PotxTest::testDrupal8ShippedConfiguration in Translation template extractor 8

Test parsing of Drupal 8 shipped configuration files.

File

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

Class

PotxTest
Ensure that the translation template extractor functions properly.

Namespace

Drupal\Tests\potx\Kernel

Code

public function testDrupal8ShippedConfiguration() {
  potx_status('set', POTX_STATUS_STRUCTURED);
  global $_potx_store, $_potx_strings, $_potx_install;
  $_potx_store = $_potx_strings = $_potx_install = [];
  $test_d8_path = $this->tests_root . '/drupal8';
  $files = _potx_explore_dir($test_d8_path, '*', POTX_API_8, TRUE);
  foreach ($files as $file) {
    _potx_process_file($file, 0, '_potx_save_string', '_potx_save_version', POTX_API_8);
  }
  _potx_parse_shipped_configuration('_potx_save_string', POTX_API_8);
  $this
    ->buildOutput(POTX_API_8);
  for ($i = 1; $i < 8; $i++) {
    $this
      ->assertNoMsgId($i . '');
  }

  // Test extraction of config schema labels.
  // Make sure all the 'label' strings are extracted.
  $this
    ->assertMsgId('Test integer');
  $this
    ->assertMsgId('Test string with "quotes"');
  $this
    ->assertMsgId('Mapping integer');
  $this
    ->assertMsgId('Test string in sequence');

  // Make sure other strings are not extracted.
  $this
    ->assertNoMsgId('mapping');
  $this
    ->assertNoMsgId('sequence');

  // Test extraction of shipped config translatables.
  $this
    ->assertMsgId('A string with "translatable: true" property');
  $this
    ->assertMsgIdContext('Y-m-d', 'PHP date format');
  $this
    ->assertMsgIdContext('Test string with context', 'Test context');
  $this
    ->assertMsgIdContext('Test label with context', 'Test label with context');
  $this
    ->assertMsgIdContext('Test overriding context', 'Test context override');
  $this
    ->assertMsgId('Simple mapping name');
  $this
    ->assertMsgId('Simple mapping code');
  $this
    ->assertMsgId('Mapping with type - name');
  $this
    ->assertMsgId('Mapping with type - code');
  $this
    ->assertMsgId('Mapping with type - extra label');
  $this
    ->assertMsgId('Simple sequence - Item 1');
  $this
    ->assertMsgId('Simple sequence - Item 2');
  $this
    ->assertMsgId('Typed sequence - Item 1 name');
  $this
    ->assertMsgId('Typed sequence - Item 1 code');
  $this
    ->assertMsgId('Typed sequence - Item 2 name');
  $this
    ->assertMsgId('Typed sequence - Item 2 code');
  $this
    ->assertMsgId('Sequence of sequence - Description 1');
  $this
    ->assertMsgId('Sequence of sequence - Description 2');
  $this
    ->assertMsgId('BC sequence item 1');
  $this
    ->assertMsgId('BC sequence item 2');
  $this
    ->assertMsgId('Basic variable (text)');
  $this
    ->assertMsgId('Parent variable (text)');
  $this
    ->assertMsgId('Key variable (text)');
  $this
    ->assertMsgId('Complex variable test');
  $this
    ->assertMsgId('Optional config translatable string');
  $this
    ->assertMsgIdContext('Optional config test string with context', 'Test context');
  $this
    ->assertNoMsgId('A simple string');
  $this
    ->assertNoMsgId('A text with "translatable: false" property');
  $this
    ->assertNoMsgId('text');
  $this
    ->assertNoMsgId('custom');
  $this
    ->assertNoMsgId('Basic variable (custom)');
  $this
    ->assertNoMsgId('Parent variable (custom)');
  $this
    ->assertNoMsgId('Key variable (custom)');
  $this
    ->assertPluralId('1 place', '@count places');
  $this
    ->assertPluralId('1 comment', '@count comments', 'Test context');
  $this
    ->assertMsgId('Test boolean based variable');
  $broken_twig_path = __DIR__ . '/../../../tests/drupal8/broken_twig.html.twig';
  $this
    ->assertPotxErrors([
    'Broken twig error' => t("Twig parsing error on file @path: @error", [
      '@path' => $broken_twig_path,
      '@error' => 'Unexpected character "&" in "' . $broken_twig_path . '" at line 1.',
    ]),
  ]);
}