]> git.mjollnir.org Git - moodle.git/commitdiff
get_string: MDL-18813 get_string was broken for strings that were ''
authortjhunt <tjhunt>
Wed, 8 Apr 2009 11:45:53 +0000 (11:45 +0000)
committertjhunt <tjhunt>
Wed, 8 Apr 2009 11:45:53 +0000 (11:45 +0000)
lib/moodlelib.php
lib/simpletest/get_string_fixtures/moodle/lang/en_utf8/test.php
lib/simpletest/get_string_fixtures/moodledata/lang/fr_utf8/test.php
lib/simpletest/teststringmanager.php

index 77a8470addf430e1c87c19557e9d06ba4d692a22..bd3cb8062a9fe1616d18ff0b38f300081b5a74f4 100644 (file)
@@ -5553,7 +5553,8 @@ class string_manager {
             foreach ($locations as $location => $ignored) {
                 foreach (array('_local', '') as $suffix) {
                     $file = $location . $lang . $suffix . '/' . $module . '.php';
-                    if ($result = $this->get_string_from_file($identifier, $file, $a)) {
+                    $result = $this->get_string_from_file($identifier, $file, $a);
+                    if ($result !== false) {
                         return $result;
                     }
                 }
index e0795062818f5fd0f5ead23e7fe5e9127cf18b09..7928995e56c7a166c14eb5bba248c6a1ffe2d882 100644 (file)
@@ -2,4 +2,6 @@
 $string['hello'] = 'Hello \'world\'!';
 $string['hellox'] = 'Hello $a!';
 $string['results'] = 'Dear $a->firstname $a->lastname,\n\nOn test \"$a->testname\" you scored $a->grade%% which earns you \$100.';
+$string['emptyen'] = '';
+$string['emptyfr'] = 'This string is defined as \'\' in the fr lang pack';
 ?>
\ No newline at end of file
index 0a0fbd1d6d2643566b64288d2b1ff943429ba639..3300aea2850e9bef80c1335bce134ce4c0ee035c 100644 (file)
@@ -1,4 +1,5 @@
 <?php
 $string['hello'] = 'Bonjour tout le monde!';
 $string['hellox'] = 'Bonjour $a!';
+$string['emptyfr'] = '';
 ?>
\ No newline at end of file
index 880f2a42cab2f8593a600cd1cb34930fea9b1739..fe8781e0679c40370bf5ae09bb71975e5e8a8c34 100644 (file)
@@ -75,6 +75,8 @@ $string['locallyoverridden'] = 'Not used';
 $string['hello'] = 'Hello \'world\'!';
 $string['hellox'] = 'Hello $a!';
 $string['results'] = 'Dear $a->firstname $a->lastname,\n\nOn test \"$a->testname\" you scored $a->grade%% which earns you \$100.';
+$string['emptyen'] = '';
+$string['emptyfr'] = 'This string is defined as \'\' in the fr lang pack';
 
 .../moodle/lang/en_utf8_local/moodle.php:
 $string['locallyoverridden'] = 'Should see this';
@@ -91,6 +93,7 @@ $string['parentlanguage'] = 'es_mx_utf8';
 .../moodledata/lang/fr_utf8/test.php
 $string['hello'] = 'Bonjour tout le monde!';
 $string['hellox'] = 'Bonjour $a!';
+$string['emptyfr'] = '';
 
 .../moodledata/lang/fr_ca_utf8/test.php
 $string['hello'] = 'Bonjour Québec!';
@@ -242,9 +245,21 @@ class string_manager_test extends UnitTestCase {
                 'hello' => "Hello 'world'!",
                 'hellox' => 'Hello $a!',
                 'results' => 'Dear $a->firstname $a->lastname,\n\nOn test \"$a->testname\" you scored $a->grade%% which earns you \$100.',
+                'emptyen' => '',
+                'emptyfr' => 'This string is defined as \'\' in the fr lang pack'
         ));
     }
 
+    public function test_get_string_from_file_empty() {
+        // From the shared fixture:
+        //.../moodle/lang/en_utf8/test.php:
+        //$string['emptyen'] = '';
+        // ...
+        $this->assertIdentical($this->stringmanager->get_string_from_file(
+                'emptyen', $this->basedir . 'moodle/lang/en_utf8/test.php', NULL),
+                '');
+    }
+
     public function test_get_string_from_file_simple() {
         // From the shared fixture:
         //.../moodle/lang/en_utf8/test.php:
@@ -289,6 +304,7 @@ class string_manager_test extends UnitTestCase {
         $this->assertEqual($this->stringmanager->get_string('hellox', 'test', 'Tim'), 'Hello Tim!');
         $this->assertEqual($this->stringmanager->get_string('yes', 'block_mrbs'), 'Yes');
         $this->assertEqual($this->stringmanager->get_string('stringnotdefinedanywhere'), '[[stringnotdefinedanywhere]]');
+        $this->assertEqual($this->stringmanager->get_string('emptyen', 'test'), '');
     }
 
     public function test_non_default_no_parent() {
@@ -299,6 +315,7 @@ class string_manager_test extends UnitTestCase {
         $this->assertEqual($this->stringmanager->get_string('hellox', 'test', 'Jean-Paul'), 'Bonjour Jean-Paul!');
         $this->assertEqual($this->stringmanager->get_string('yes', 'block_mrbs'), 'Oui');
         $this->assertEqual($this->stringmanager->get_string('stringnotdefinedanywhere'), '[[stringnotdefinedanywhere]]');
+        $this->assertEqual($this->stringmanager->get_string('emptyfr', 'test'), '');
     }
 
     public function test_lang_with_parent() {
@@ -310,6 +327,7 @@ class string_manager_test extends UnitTestCase {
         $this->assertEqual($this->stringmanager->get_string('yes', 'block_mrbs'), 'Oui');
         $this->assertEqual($this->stringmanager->get_string('stringnotdefinedanywhere'), '[[stringnotdefinedanywhere]]');
     }
+
 }
 
 ?>