You are here

public function PotxTest::testDrupal5 in Translation template extractor 8

Test parsing of Drupal 5 module.

File

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

Class

PotxTest
Ensure that the translation template extractor functions properly.

Namespace

Drupal\Tests\potx\Kernel

Code

public function testDrupal5() {

  // Parse and build the Drupal 5 module file.
  $filename = $this->tests_root . '/potx_test_5.module';
  $this
    ->parseFile($filename, POTX_API_5);

  // Assert strings found in module source code.
  $this
    ->assertMsgId('Test menu item in 5');
  $this
    ->assertMsgId('This is a test menu item in 5');
  $this
    ->assertMsgId('This is a test string.');
  $this
    ->assertMsgId('test watchdog type');

  // No support for instant t() in watchdog.
  $this
    ->assertNoMsgId('My watchdog message');
  $this
    ->assertMsgId('test potx permission');
  $this
    ->assertMsgId('one more test potx permission');
  $this
    ->assertPluralId('1 test string', '@count test strings');

  // Installer string should not appear in runtime output.
  $this
    ->assertNoMsgId('Installer only test string');
  $this
    ->assertMsgId('Dynamic callback test string');
  $this
    ->assertNoMsgId('Installer string in context');

  // No context support yet.
  $this
    ->assertNoMsgIdContext('Test string in context', 'Test context');
  $this
    ->assertMsgId('Test string in context');
  $this
    ->assertNoMsgIdContext('Dynamic string in context', 'Dynamic context');
  $this
    ->assertMsgId('Dynamic string in context');

  // The singular/plural will not even be found without context, because
  // Drupal 5 does not have support for args on format_plural.
  $this
    ->assertNoMsgId('1 test string in context');
  $this
    ->assertNoPluralIdContext('1 test string in context', '@count test strings in context', 'Test context');

  // Look at installer strings.
  $this
    ->parseFile($filename, POTX_API_5, POTX_STRING_INSTALLER);
  $this
    ->assertMsgId('Installer only test string');
  $this
    ->assertMsgId('Dynamic callback test string');
  $this
    ->assertNoMsgId('1 test string');
  $this
    ->assertNoMsgId('This is a test string.');
  $this
    ->assertNoMsgIdContext('Installer string in context', 'Installer context');
  $this
    ->assertMsgId('Installer string in context');
  $this
    ->assertNoMsgIdContext('Dynamic string in context', 'Dynamic context');
  $this
    ->assertMsgId('Dynamic string in context');
  $this
    ->assertPotxErrors([
    'First empty error' => $this->empty_error,
    'Second empty error' => $this->empty_error,
    'Third empty error' => $this->empty_error,
    'Fourth error' => t('In @function(), the singular and plural strings should be literal strings. There should be no variables, concatenation, constants or even a t() call there.', [
      '@function' => 'format_plural',
    ]),
  ]);
}