From 761ec74ffd9301a7e6ad1c1f2dfad82d773127f8 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Tue, 26 Oct 2010 15:24:50 +0000 Subject: =?UTF-8?q?-=20Patch=20#611786=20by=20G=C3=A1bor=20Hojtsy,=20tobia?= =?UTF-8?q?sb,=20Pasqualle:=20.po=20file=20should=20not=20be=20considered?= =?UTF-8?q?=20broken=20if=20last=20msgstr=20is=20empty.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/locale/locale.test | 95 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 85 insertions(+), 10 deletions(-) (limited to 'modules') diff --git a/modules/locale/locale.test b/modules/locale/locale.test index 004b332a0..2efa63d82 100644 --- a/modules/locale/locale.test +++ b/modules/locale/locale.test @@ -582,7 +582,7 @@ class LocaleImportFunctionalTest extends DrupalWebTestCase { public static function getInfo() { return array( 'name' => 'Translation import', - 'description' => 'Tests the importation of locale files.', + 'description' => 'Tests the import of locale files.', 'group' => 'Locale', ); } @@ -600,7 +600,7 @@ class LocaleImportFunctionalTest extends DrupalWebTestCase { } /** - * Test importation of standalone .po files. + * Test import of standalone .po files. */ function testStandalonePoFile() { // Try importing a .po file. @@ -698,8 +698,8 @@ class LocaleImportFunctionalTest extends DrupalWebTestCase { } /** - * Test automatic importation of a module's translation files when a language - * is enabled. + * Test automatic import of a module's translation files when a language is + * enabled. */ function testAutomaticModuleTranslationImportLanguageEnable() { // Code for the language - manually set to match the test translation file. @@ -737,8 +737,7 @@ class LocaleImportFunctionalTest extends DrupalWebTestCase { } /** - * Test automatic importation of a module's translation files when a language - * is enabled. + * Test msgctxt context support. */ function testLanguageContext() { // Try importing a .po file. @@ -750,6 +749,43 @@ class LocaleImportFunctionalTest extends DrupalWebTestCase { $this->assertIdentical(t('May', array(), array('langcode' => 'hr')), 'Svi.', t('Default context is working.')); } + /** + * Test empty msgstr at end of .po file see #611786. + */ + function testEmptyMsgstr() { + $langcode = 'hu'; + + // Try importing a .po file. + $this->importPoFile($this->getPoFileWithMsgstr(), array( + 'langcode' => $langcode, + )); + + $this->assertRaw(t('The translation was successfully imported. There are %number newly created translated strings, %update strings were updated and %delete strings were removed.', array('%number' => 1, '%update' => 0, '%delete' => 0)), t('The translation file was successfully imported.')); + $this->assertIdentical(t('Operations', array(), array('langcode' => $langcode)), 'Műveletek', t('String imported and translated.')); + + // Try importing a .po file. + $this->importPoFile($this->getPoFileWithEmptyMsgstr(), array( + 'langcode' => $langcode, + 'mode' => 0, + )); + $this->assertRaw(t('The translation was successfully imported. There are %number newly created translated strings, %update strings were updated and %delete strings were removed.', array('%number' => 0, '%update' => 0, '%delete' => 1)), t('The translation file was successfully imported.')); + // This is the language indicator on the translation search screen for + // untranslated strings. Copied straight from locale.inc. + $language_indicator = "$langcode "; + $str = "Operations"; + $search = array( + 'string' => $str, + 'language' => 'all', + 'translation' => 'all', + 'group' => 'all', + ); + $this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter')); + // assertText() seems to remove the input field where $str always could be + // found, so this is not a false assert. + $this->assertText($str, t('Search found the string.')); + $this->assertRaw($language_indicator, t('String is untranslated again.')); + } + /** * Helper function: import a standalone .po file in a given language. * @@ -773,7 +809,7 @@ class LocaleImportFunctionalTest extends DrupalWebTestCase { return <<< EOF msgid "" msgstr "" -"Project-Id-Version: Drupal 6\\n" +"Project-Id-Version: Drupal 7\\n" "MIME-Version: 1.0\\n" "Content-Type: text/plain; charset=UTF-8\\n" "Content-Transfer-Encoding: 8bit\\n" @@ -809,7 +845,7 @@ EOF; return <<< EOF msgid "" msgstr "" -"Project-Id-Version: Drupal 6\\n" +"Project-Id-Version: Drupal 7\\n" "MIME-Version: 1.0\\n" "Content-Type: text/plain; charset=UTF-8\\n" "Content-Transfer-Encoding: 8bit\\n" @@ -835,7 +871,7 @@ EOF; return <<< EOF msgid "" msgstr "" -"Project-Id-Version: Drupal 6\\n" +"Project-Id-Version: Drupal 7\\n" "MIME-Version: 1.0\\n" "Content-Type: text/plain; charset=UTF-8\\n" "Content-Transfer-Encoding: 8bit\\n" @@ -858,7 +894,7 @@ EOF; return <<< EOF msgid "" msgstr "" -"Project-Id-Version: Drupal 6\\n" +"Project-Id-Version: Drupal 7\\n" "MIME-Version: 1.0\\n" "Content-Type: text/plain; charset=UTF-8\\n" "Content-Transfer-Encoding: 8bit\\n" @@ -873,6 +909,45 @@ msgstr "Svi." EOF; } + /** + * Helper function that returns a .po file with an empty last item. + */ + function getPoFileWithEmptyMsgstr() { + return <<< EOF +msgid "" +msgstr "" +"Project-Id-Version: Drupal 7\\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 "Operations" +msgstr "" + +EOF; + } + /** + * Helper function that returns a .po file with an empty last item. + */ + function getPoFileWithMsgstr() { + return <<< EOF +msgid "" +msgstr "" +"Project-Id-Version: Drupal 7\\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 "Operations" +msgstr "Műveletek" + +msgid "Will not appear in Drupal core, so we can ensure the test passes" +msgstr "" + +EOF; + } } -- cgit v1.2.3