You are here

public function PotxTest::testDrupal7 in Translation template extractor 8

Test parsing of Drupal 7 module.

File

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

Class

PotxTest
Ensure that the translation template extractor functions properly.

Namespace

Drupal\Tests\potx\Kernel

Code

public function testDrupal7() {

  // Parse and build the Drupal 7 module file.
  $filename = $this->tests_root . '/potx_test_7.module';
  $this
    ->parseFile($filename, POTX_API_7);

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

  // No support for hook_perm() anymore. t() in hook_permissions().
  $this
    ->assertNoMsgId('test potx permission');
  $this
    ->assertNoMsgId('one more test potx permission');
  $this
    ->assertMsgId('Test potx permission');
  $this
    ->assertMsgId('Test potx permission description');
  $this
    ->assertMsgId('One more test potx permission');
  $this
    ->assertMsgId('One more test potx permission description');
  $this
    ->assertPluralId('1 test string', '@count test strings');
  $this
    ->assertPluralIdContext('1 test string in context', '@count test strings in context', 'Test context');
  $this
    ->assertMsgId('Test menu item description');
  $this
    ->assertMsgId('Test menu item description altered (1)');
  $this
    ->assertMsgId('Test menu item description altered (2)');
  $this
    ->assertMsgId('Test menu item title altered');
  $this
    ->assertNoMsgId('Installer only test string');
  $this
    ->assertMsgId('Dynamic callback test string');
  $this
    ->assertNoMsgIdContext('Installer string in context', 'Installer context');
  $this
    ->assertMsgIdContext('Dynamic string in context', 'Dynamic context');

  // Context support added.
  $this
    ->assertMsgIdContext('Test string in context', 'Test context');

  // Drush support.
  $this
    ->assertMsgId('This could have been in a drush file');

  // Look at installer strings.
  $this
    ->parseFile($filename, POTX_API_7, 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
    ->assertMsgIdContext('Installer string in context', 'Installer context');
  $this
    ->assertMsgIdContext('Dynamic string in context', 'Dynamic context');
  $this
    ->assertPotxErrors([
    'First empty error' => $this->empty_error,
    'Second empty error' => $this->empty_error,
  ]);
}