Преглед на файлове

[GENERIC] Resources:

- fixed the testbed to throw out ALL problems instead of only the first one

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@22358 44c647ce-9c0f-0410-b52a-842ac1e357ba
thomas преди 15 години
родител
ревизия
97812e4c33
променени са 1 файла, в които са добавени 75 реда и са изтрити 19 реда
  1. 75 19
      tests/resources/languages/Zend_ValidateTest.php

+ 75 - 19
tests/resources/languages/Zend_ValidateTest.php

@@ -72,11 +72,15 @@ class resources_languages_Zend_ValidateTest extends PHPUnit_Framework_TestCase
                 if (!is_array($translation)) {
                     $this->fail("Invalid or empty translation table found for language '{$fname}'");
                 }
+
                 $this->_translations[$fname] = $translation;
             }
         }
     }
 
+    /**
+     * Tests if the given language is really a language
+     */
     public function testIsLocale()
     {
         foreach ($this->_languages as $lang) {
@@ -86,74 +90,126 @@ class resources_languages_Zend_ValidateTest extends PHPUnit_Framework_TestCase
         }
     }
 
+    /**
+     * Tests if all english original keys have the same translations
+     */
     public function testEnglishKeySameAsValue()
     {
-        foreach ($this->_translations['en'] as $k => $v) {
-            $this->assertEquals($k, $v);
+        $errors = array();
+        $cnt    = 0;
+        foreach ($this->_translations['en'] as $key => $value) {
+            if ($key !== $value) {
+                ++$cnt;
+                $errors['en ' . $cnt] = "The key $key is not identical in the english original";
+            }
+        }
+
+        if (!empty($errors)) {
+            $this->fail(var_export($errors, true));
         }
     }
 
+    /**
+     * Tests if all translation keys are also available in the english original
+     */
     public function testTranslationAvailableInEnglish()
     {
+        $errors = array();
+        $cnt    = 0;
         foreach ($this->_translations as $lang => $translation) {
             if ($lang == 'en') {
                 continue;
             }
 
-            foreach ($translation as $k => $v) {
-                $this->assertTrue(
-                    isset($this->_translations['en'][$k]),
-                    $lang . ': The key "' . $k . '" isn\'t available within english translation file'
-                );
+            foreach ($translation as $key => $value) {
+                if (!isset($this->_translations['en'][$key])) {
+                    ++$cnt;
+                    $errors[$lang . ' ' . $cnt] = "The key \"" . $key . "\" isn't available within english translation file";
+                }
             }
         }
+
+        if (!empty($errors)) {
+            $this->fail(var_export($errors, true));
+        }
     }
 
+    /**
+     * Tests if the key is translated
+     */
     public function testTranslationDiffersFromEnglish()
     {
+        $errors = array();
+        $cnt    = 0;
         foreach ($this->_translations as $lang => $translation) {
             if ($lang == 'en') {
                 continue;
             }
 
-            foreach ($translation as $k => $v) {
-                $this->assertTrue( ($k != $v),
-                    $lang . ': The translated message "' . $v . '" is the same the english version'
-                );
+            foreach ($translation as $key => $value) {
+                if ($key == $value) {
+                    ++$cnt;
+                    $errors[$lang . ' ' . $cnt] = "The translated message \"" . $value . "\" is the same the english version";
+                }
             }
         }
+
+        if (!empty($errors)) {
+            $this->fail(var_export($errors, true));
+        }
     }
 
+    /**
+     * Tests if all placeholders from the original are also available within the translation
+     */
     public function testPlaceholder()
     {
+        $errors = array();
+        $cnt    = 0;
         foreach ($this->_translations as $lang => $translation) {
             if ($lang == 'en') { // not needed to test - see testEnglishKeySameAsValue
                 continue;
             }
 
-            foreach ($translation as $k => $v) {
-                if (preg_match_all('/(\%.+\%)/U', $k, $matches, PREG_SET_ORDER)) {
+            foreach ($translation as $key => $value) {
+                if (preg_match_all('/(\%.+\%)/U', $key, $matches, PREG_SET_ORDER)) {
                     foreach ($matches as $match) {
-                        $this->assertContains($match[1], $v,
-                            $lang . ': Missing placeholder "' . $match[1] . '" within "' . $v . '"');
+                        if (!strpos($value, $match[1])) {
+                            ++$cnt;
+                            $errors[$lang . ' ' . $cnt] = "Missing placeholder \"" . $match[1] . "\" within \"" . $value . "\"";
+                        }
                     }
                 }
             }
         }
+
+        if (!empty($errors)) {
+            $this->fail(var_export($errors, true));
+        }
     }
 
+    /**
+     * Tests if all english originals are translated
+     */
     public function testAllTranslated()
     {
-        foreach ($this->_translations['en'] as $enK => $enV) {
+        $errors = array();
+        $cnt    = 0;
+        foreach ($this->_translations['en'] as $key => $value) {
             foreach ($this->_translations as $lang => $translation) {
                 if ($lang == 'en') {
                     continue;
                 }
 
-                $this->assertTrue(isset($translation[$enK]),
-                    $lang . ': Message "' . $enK . '" not translated');
+                if (!isset($translation[$key])) {
+                    ++$cnt;
+                    $errors[$lang . ' ' . $cnt] = "Message \"" . $key . "\" not translated";
+                }
             }
         }
-    }
 
+        if (!empty($errors)) {
+            $this->fail(var_export($errors, true));
+        }
+    }
 }