X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Flocale%2Fsrc%2FTests%2FLocaleExportTest.php;fp=web%2Fcore%2Fmodules%2Flocale%2Fsrc%2FTests%2FLocaleExportTest.php;h=0000000000000000000000000000000000000000;hb=bfbba508964731508b9bd6d5835c2edc858db95b;hp=54d36e2bc80c123759a94e1a5a1dc054b1f9111f;hpb=cb9a80db11fc6b014e5b1e693a5a391c95eb5d9a;p=yaffs-website diff --git a/web/core/modules/locale/src/Tests/LocaleExportTest.php b/web/core/modules/locale/src/Tests/LocaleExportTest.php deleted file mode 100644 index 54d36e2bc..000000000 --- a/web/core/modules/locale/src/Tests/LocaleExportTest.php +++ /dev/null @@ -1,176 +0,0 @@ -adminUser = $this->drupalCreateUser(['administer languages', 'translate interface', 'access administration pages']); - $this->drupalLogin($this->adminUser); - - // Copy test po files to the translations directory. - file_unmanaged_copy(__DIR__ . '/../../tests/test.de.po', 'translations://', FILE_EXISTS_REPLACE); - file_unmanaged_copy(__DIR__ . '/../../tests/test.xx.po', 'translations://', FILE_EXISTS_REPLACE); - } - - /** - * Test exportation of translations. - */ - public function testExportTranslation() { - // First import some known translations. - // This will also automatically add the 'fr' language. - $name = \Drupal::service('file_system')->tempnam('temporary://', "po_") . '.po'; - file_put_contents($name, $this->getPoFile()); - $this->drupalPostForm('admin/config/regional/translate/import', [ - 'langcode' => 'fr', - 'files[file]' => $name, - ], t('Import')); - drupal_unlink($name); - - // Get the French translations. - $this->drupalPostForm('admin/config/regional/translate/export', [ - '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 = \Drupal::service('file_system')->tempnam('temporary://', "po2_") . '.po'; - file_put_contents($name, $this->getCustomPoFile()); - $this->drupalPostForm('admin/config/regional/translate/import', [ - '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', [ - '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', [ - '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.'); - } - - /** - * Test exportation of translation template file. - */ - public function testExportTranslationTemplateFile() { - // Load an admin page with JavaScript so _drupal_add_library() fires at - // least once and _locale_parse_js_file() gets to run at least once so that - // the locales_source table gets populated with something. - $this->drupalGet('admin/config/regional/language'); - // Get the translation template file. - $this->drupalPostForm('admin/config/regional/translate/export', [], t('Export')); - // Ensure we have a translation file. - $this->assertRaw('# LANGUAGE translation of PROJECT', 'Exported translation template file.'); - } - - /** - * Helper function that returns a proper .po file. - */ - public function getPoFile() { - return <<< EOF -msgid "" -msgstr "" -"Project-Id-Version: Drupal 8\\n" -"MIME-Version: 1.0\\n" -"Content-Type: text/plain; charset=UTF-8\\n" -"Content-Transfer-Encoding: 8bit\\n" -"Plural-Forms: nplurals=2; plural=(n > 1);\\n" - -msgid "Monday" -msgstr "lundi" -EOF; - } - - /** - * Helper function that returns a .po file which strings will be marked - * as customized. - */ - public function getCustomPoFile() { - return <<< EOF -msgid "" -msgstr "" -"Project-Id-Version: Drupal 8\\n" -"MIME-Version: 1.0\\n" -"Content-Type: text/plain; charset=UTF-8\\n" -"Content-Transfer-Encoding: 8bit\\n" -"Plural-Forms: nplurals=2; plural=(n > 1);\\n" - -msgid "January" -msgstr "janvier" -EOF; - } - - /** - * Returns a .po file fragment with an untranslated string. - * - * @return string - * A .po file fragment with an untranslated string. - */ - public function getUntranslatedString() { - return <<< EOF -msgid "February" -msgstr "" -EOF; - } - -}