Browse Source

initial resources tests

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@20721 44c647ce-9c0f-0410-b52a-842ac1e357ba
mabe 16 years ago
parent
commit
76602d39fb

+ 2 - 0
tests/AllTests.php

@@ -27,6 +27,7 @@ if (!defined('PHPUnit_MAIN_METHOD')) {
 }
 
 require_once 'Zend/AllTests.php';
+require_once 'resources/AllTests.php';
 
 /**
  * @category   Zend
@@ -89,6 +90,7 @@ class AllTests
         $suite = new PHPUnit_Framework_TestSuite('Zend Framework');
 
         $suite->addTest(Zend_AllTests::suite());
+        $suite->addTest(resources_AllTests::suite());
 
         return $suite;
     }

+ 65 - 0
tests/resources/AllTests.php

@@ -0,0 +1,65 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'TestHelper.php';
+
+if (!defined('PHPUnit_MAIN_METHOD')) {
+    define('PHPUnit_MAIN_METHOD', 'resources_AllTests::main');
+}
+
+require_once dirname(__FILE__) . '/languages/AllTests.php';
+
+/**
+ * @category   Zend
+ * @package    Zend_recources
+ * @subpackage UnitTests
+ * @group      Zend
+ * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class resources_AllTests
+{
+    public static function main()
+    {
+        PHPUnit_TextUI_TestRunner::run(self::suite());
+    }
+
+    /**
+     * Regular suite
+     *
+     * All tests except those that require output buffering.
+     *
+     * @return PHPUnit_Framework_TestSuite
+     */
+    public static function suite()
+    {
+        $suite = new PHPUnit_Framework_TestSuite('Zend Framework - resources');
+
+        $suite->addTest(resources_languages_AllTests::suite());
+
+        return $suite;
+    }
+}
+
+if (PHPUnit_MAIN_METHOD == 'resources_AllTests::main') {
+    resources_AllTests::main();
+}

+ 65 - 0
tests/resources/languages/AllTests.php

@@ -0,0 +1,65 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+require_once dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'TestHelper.php';
+
+if (!defined('PHPUnit_MAIN_METHOD')) {
+    define('PHPUnit_MAIN_METHOD', 'resources_languages_AllTests::main');
+}
+
+require_once dirname(__FILE__) . '/Zend_ValidateTest.php';
+
+/**
+ * @category   Zend
+ * @package    Zend_recource
+ * @subpackage UnitTests
+ * @group      Zend
+ * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class resources_languages_AllTests
+{
+    public static function main()
+    {
+        PHPUnit_TextUI_TestRunner::run(self::suite());
+    }
+
+    /**
+     * Regular suite
+     *
+     * All tests except those that require output buffering.
+     *
+     * @return PHPUnit_Framework_TestSuite
+     */
+    public static function suite()
+    {
+        $suite = new PHPUnit_Framework_TestSuite('Zend Framework - resources - languages');
+
+        $suite->addTestSuite('resources_languages_Zend_ValidateTest');
+
+        return $suite;
+    }
+}
+
+if (PHPUnit_MAIN_METHOD == 'resources_languages_AllTests::main') {
+    resources_languages_AllTests::main();
+}

+ 143 - 0
tests/resources/languages/Zend_ValidateTest.php

@@ -0,0 +1,143 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Exception
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/**
+ * @see Zend_Locale
+ */
+require_once 'Zend/Locale.php';
+
+/**
+ * @category   Zend
+ * @package    Zend_resources
+ * @subpackage UnitTests
+ * @group      Zend_Exception
+ * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class resources_languages_Zend_ValidateTest extends PHPUnit_Framework_TestCase
+{
+
+    protected $_langDir      = null;
+    protected $_languages    = array();
+    protected $_translations = array();
+
+    public function setUp()
+    {
+        $this->_langDir = dirname(dirname(dirname(dirname(__FILE__))))
+                        . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'languages';
+        if (!is_readable($this->_langDir)) {
+            throw new Exception('Language resource directory "'.$this->_langDir.'" not readable.');
+        }
+
+        // detect languages
+        foreach (new DirectoryIterator($this->_langDir) as $entry) {
+            if (!$entry->isDir()) {
+                continue;
+            }
+
+            // skip "." or ".." or ".svn"
+            $fname = $entry->getFilename();
+            if ($fname[0] == '.') {
+                continue;
+            }
+
+            // add all languages for testIsLocale
+            $this->_languages[] = $fname;
+
+            // include Zend_Validate translation tables
+            $translationFile = $entry->getPathname() . DIRECTORY_SEPARATOR . 'Zend_Validate.php';
+            if (file_exists($translationFile)) {
+                $translation = include $translationFile;
+                if (!is_array($translation)) {
+                    $this->fail("Invalid or empty translation table found for language '{$fname}'");
+                }
+                $this->_translations[$fname] = $translation;
+            }
+        }
+    }
+
+    public function testIsLocale()
+    {
+        foreach ($this->_languages as $lang) {
+            if (!Zend_Locale::isLocale($lang, true, false)) {
+                $this->fail("Language directory '{$lang}' not a valid locale");
+            }
+        }
+    }
+
+    public function testEnglishKeySameAsValue()
+    {
+        foreach ($this->_translations['en'] as $k => $v) {
+            $this->assertEquals($k, $v);
+        }
+    }
+
+    public function testTranslationAvailableAtEngligh()
+    {
+        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'
+                );
+            }
+        }
+    }
+
+    public function testTranslationDifferFromEnglish()
+    {
+        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'
+                );
+            }
+        }
+    }
+
+    public function testPlaceholder()
+    {
+        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 ($matches as $match) {
+                        $this->assertContains($match[1], $v,
+                            $lang . ': Missing placeholder "' . $match[1] . '" within "' . $v . '"');
+                    }
+                }
+            }
+        }
+    }
+
+}