Add unit test.
authorJan Schneider <jan@horde.org>
Tue, 12 Oct 2010 22:16:20 +0000 (00:16 +0200)
committerJan Schneider <jan@horde.org>
Wed, 13 Oct 2010 00:34:41 +0000 (02:34 +0200)
framework/Translation/test/Horde/Translation/AllTests.php [new file with mode: 0644]
framework/Translation/test/Horde/Translation/GettextTest.php [new file with mode: 0644]
framework/Translation/test/Horde/Translation/locale/de/LC_MESSAGES/Horde_Translation.mo [new file with mode: 0644]
framework/Translation/test/Horde/Translation/locale/de/LC_MESSAGES/Horde_Translation.po [new file with mode: 0644]

diff --git a/framework/Translation/test/Horde/Translation/AllTests.php b/framework/Translation/test/Horde/Translation/AllTests.php
new file mode 100644 (file)
index 0000000..22e60a8
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+/**
+ * Horde_Translation test suite.
+ *
+ * @author     Jan Schneider <jan@horde.org>
+ * @license    http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @category   Horde
+ * @package    Translation
+ * @subpackage UnitTests
+ */
+
+/**
+ * Define the main method
+ */
+if (!defined('PHPUnit_MAIN_METHOD')) {
+    define('PHPUnit_MAIN_METHOD', 'Horde_Translation_AllTests::main');
+}
+
+/**
+ * Prepare the test setup.
+ */
+require_once 'Horde/Test/AllTests.php';
+
+/**
+ * @package    Horde_Translation
+ * @subpackage UnitTests
+ */
+class Horde_Translation_AllTests extends Horde_Test_AllTests
+{
+}
+
+Horde_Translation_AllTests::init('Horde_Translation', __FILE__);
+
+if (PHPUnit_MAIN_METHOD == 'Horde_Translation_AllTests::main') {
+    Horde_Translation_AllTests::main();
+}
diff --git a/framework/Translation/test/Horde/Translation/GettextTest.php b/framework/Translation/test/Horde/Translation/GettextTest.php
new file mode 100644 (file)
index 0000000..7d8cd4d
--- /dev/null
@@ -0,0 +1,34 @@
+<?php
+/**
+ * @author     Jan Schneider <jan@horde.org>
+ * @license    http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @category   Horde
+ * @package    Translation
+ * @subpackage UnitTests
+ */
+
+class Horde_Translation_GettextTest extends PHPUnit_Framework_TestCase
+{
+    private $_dict;
+
+    public function setUp()
+    {
+        putenv('LC_ALL=de_DE.UTF-8');
+        putenv('LANG=de_DE.UTF-8');
+        putenv('LANGUAGE=de_DE.UTF-8');
+        $this->_dict = new Horde_Translation_Gettext('Horde_Translation', dirname(__FILE__) . '/locale');
+    }
+
+    public function testGettext()
+    {
+        $this->assertEquals('Heute', $this->_dict->t('Today'));
+        $this->assertEquals('Schön', $this->_dict->t('Beautiful'));
+        $this->assertEquals('2 Tage', sprintf($this->_dict->t('%d days'), 2));
+    }
+
+    public function testNgettext()
+    {
+        $this->assertEquals('1 Woche', sprintf($this->_dict->ngettext('%d week', '%d weeks', 1), 1));
+        $this->assertEquals('2 Wochen', sprintf($this->_dict->ngettext('%d week', '%d weeks', 2), 2));
+    }
+}
diff --git a/framework/Translation/test/Horde/Translation/locale/de/LC_MESSAGES/Horde_Translation.mo b/framework/Translation/test/Horde/Translation/locale/de/LC_MESSAGES/Horde_Translation.mo
new file mode 100644 (file)
index 0000000..19b919a
Binary files /dev/null and b/framework/Translation/test/Horde/Translation/locale/de/LC_MESSAGES/Horde_Translation.mo differ
diff --git a/framework/Translation/test/Horde/Translation/locale/de/LC_MESSAGES/Horde_Translation.po b/framework/Translation/test/Horde/Translation/locale/de/LC_MESSAGES/Horde_Translation.po
new file mode 100644 (file)
index 0000000..6221e5f
--- /dev/null
@@ -0,0 +1,31 @@
+# German test translation for Horde_Translation.
+# Copyright 2010 The Horde Project (http://www.horde.org/)
+# Jan Schneider <jan@horde.org>, 2010.
+msgid ""
+msgstr ""
+"Project-Id-Version: Horde_Translation\n"
+"Report-Msgid-Bugs-To: dev@lists.horde.org\n"
+"POT-Creation-Date: 2010-08-17 18:32+0200\n"
+"PO-Revision-Date: 2010-08-25 13:24+0200\n"
+"Last-Translator: Jan Schneider <jan@horde.org>\n"
+"Language-Team: German <dev@lists.horde.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8-bit\n"
+"Plural-Forms: nplurals=2; plural=(n != 1);\n"
+
+msgid "Today"
+msgstr "Heute"
+
+msgid "Beautiful"
+msgstr "Schön"
+
+#, php-format
+msgid "%d days"
+msgstr "%d Tage"
+
+#, php-format
+msgid "%d week"
+msgid_plural "%d weeks"
+msgstr[0] "%d Woche"
+msgstr[1] "%d Wochen"