summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2008-11-11 20:22:17 +0000
committerDries Buytaert <dries@buytaert.net>2008-11-11 20:22:17 +0000
commita80672230f33cba6b8c29bdb1ec9c908d35d4ff8 (patch)
tree0994fc9092b181a47584defeab00fb6ddad8fcdf
parent5d85d16a752a640016601f36fc51a80e2c56c6ca (diff)
downloadbrdo-a80672230f33cba6b8c29bdb1ec9c908d35d4ff8.tar.gz
brdo-a80672230f33cba6b8c29bdb1ec9c908d35d4ff8.tar.bz2
- Patch #332623 by Damien Tournoud: fixed importing translations and added a test.
-rw-r--r--includes/locale.inc2
-rw-r--r--modules/locale/locale.test82
2 files changed, 83 insertions, 1 deletions
diff --git a/includes/locale.inc b/includes/locale.inc
index 248731cbb..793e50010 100644
--- a/includes/locale.inc
+++ b/includes/locale.inc
@@ -1046,7 +1046,7 @@ function _locale_import_po($file, $langcode, $mode, $group = NULL) {
*/
function _locale_import_read_po($op, $file, $mode = NULL, $lang = NULL, $group = 'default') {
- $fd = fopen(DRUPAL_ROOT . '/' . $file->filepath, "rb"); // File will get closed by PHP on return
+ $fd = fopen($file->filepath, "rb"); // File will get closed by PHP on return
if (!$fd) {
_locale_import_message('The translation import failed, because the file %filename could not be read.', $file);
return FALSE;
diff --git a/modules/locale/locale.test b/modules/locale/locale.test
index bdcfd7996..3daf79f5e 100644
--- a/modules/locale/locale.test
+++ b/modules/locale/locale.test
@@ -114,3 +114,85 @@ class LocaleTestCase extends DrupalWebTestCase {
$this->assertNoText($name, 'Search now can not find the name');
}
}
+
+/**
+ * Functional tests for the import of translation files.
+ */
+class LocaleImportFunctionalTest extends DrupalWebTestCase {
+
+ function getInfo() {
+ return array(
+ 'name' => t('Translation import'),
+ 'description' => t('Tests the importation of locale files.'),
+ 'group' => t('Locale'),
+ );
+ }
+
+ /**
+ * A user able to create languages and import translations.
+ */
+ protected $admin_user = NULL;
+
+ function setUp() {
+ parent::setUp('locale');
+
+ $this->admin_user = $this->drupalCreateUser(array('administer languages', 'translate interface', 'access administration pages'));
+ $this->drupalLogin($this->admin_user);
+ }
+
+ /**
+ * Test importation of standalone .po files.
+ */
+ function testStandalonePoFile() {
+ // Try importing a .po file.
+ $name = tempnam(file_directory_temp(), "po_");
+ file_put_contents($name, $this->getPoFile());
+ $this->drupalPost('admin/build/translate/import', array(
+ 'langcode' => 'fr',
+ 'files[file]' => $name,
+ ), t('Import'));
+ unlink($name);
+
+ // The importation should automatically create the corresponding language.
+ $this->assertRaw(t('The language %language has been created.', array('%language' => 'French')), t('The language has been automatically created'));
+
+ // The importation should have create 7 strings.
+ $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' => 7, '%update' => 0, '%delete' => 0)), t('The translation file was successfully imported'));
+ }
+
+ /**
+ * Helper function that returns a proper .po file.
+ */
+ function getPoFile() {
+ return <<< EOF
+msgid ""
+msgstr ""
+"Project-Id-Version: Drupal 6\\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"
+
+msgid "Tuesday"
+msgstr "mardi"
+
+msgid "Wednesday"
+msgstr "mercredi"
+
+msgid "Thursday"
+msgstr "jeudi"
+
+msgid "Friday"
+msgstr "vendredi"
+
+msgid "Saturday"
+msgstr "samedi"
+
+msgid "Sunday"
+msgstr "dimanche"
+EOF;
+ }
+}