You are here

public function LocaleExportTest::testExportTranslation in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/locale/src/Tests/LocaleExportTest.php \Drupal\locale\Tests\LocaleExportTest::testExportTranslation()

Test exportation of translations.

File

core/modules/locale/src/Tests/LocaleExportTest.php, line 48
Contains \Drupal\locale\Tests\LocaleExportTest.

Class

LocaleExportTest
Tests the exportation of locale files.

Namespace

Drupal\locale\Tests

Code

public function testExportTranslation() {

  // First import some known translations.
  // This will also automatically add the 'fr' language.
  $name = tempnam('temporary://', "po_") . '.po';
  file_put_contents($name, $this
    ->getPoFile());
  $this
    ->drupalPostForm('admin/config/regional/translate/import', array(
    'langcode' => 'fr',
    'files[file]' => $name,
  ), t('Import'));
  drupal_unlink($name);

  // Get the French translations.
  $this
    ->drupalPostForm('admin/config/regional/translate/export', array(
    'langcode' => 'fr',
  ), t('Export'));

  // Ensure we have a translation file.
  $this
    ->assertRaw('# French translation of Drupal', 'Exported French translation file.');

  // Ensure our imported translations exist in the file.
  $this
    ->assertRaw('msgstr "lundi"', 'French translations present in exported file.');

  // Import some more French translations which will be marked as customized.
  $name = tempnam('temporary://', "po2_") . '.po';
  file_put_contents($name, $this
    ->getCustomPoFile());
  $this
    ->drupalPostForm('admin/config/regional/translate/import', array(
    'langcode' => 'fr',
    'files[file]' => $name,
    'customized' => 1,
  ), t('Import'));
  drupal_unlink($name);

  // Create string without translation in the locales_source table.
  $this->container
    ->get('locale.storage')
    ->createString()
    ->setString('February')
    ->save();

  // Export only customized French translations.
  $this
    ->drupalPostForm('admin/config/regional/translate/export', array(
    'langcode' => 'fr',
    'content_options[not_customized]' => FALSE,
    'content_options[customized]' => TRUE,
    'content_options[not_translated]' => FALSE,
  ), t('Export'));

  // Ensure we have a translation file.
  $this
    ->assertRaw('# French translation of Drupal', 'Exported French translation file with only customized strings.');

  // Ensure the customized translations exist in the file.
  $this
    ->assertRaw('msgstr "janvier"', 'French custom translation present in exported file.');

  // Ensure no untranslated strings exist in the file.
  $this
    ->assertNoRaw('msgid "February"', 'Untranslated string not present in exported file.');

  // Export only untranslated French translations.
  $this
    ->drupalPostForm('admin/config/regional/translate/export', array(
    'langcode' => 'fr',
    'content_options[not_customized]' => FALSE,
    'content_options[customized]' => FALSE,
    'content_options[not_translated]' => TRUE,
  ), t('Export'));

  // Ensure we have a translation file.
  $this
    ->assertRaw('# French translation of Drupal', 'Exported French translation file with only untranslated strings.');

  // Ensure no customized translations exist in the file.
  $this
    ->assertNoRaw('msgstr "janvier"', 'French custom translation not present in exported file.');

  // Ensure the untranslated strings exist in the file, and with right quotes.
  $this
    ->assertRaw($this
    ->getUntranslatedString(), 'Empty string present in exported file.');
}