From 16660934cc48f357b1322bce7869158db2f7cb58 Mon Sep 17 00:00:00 2001 From: wei <> Date: Fri, 6 Jan 2006 05:32:33 +0000 Subject: Adding I18N unit test cases. --- tests/UnitTests/framework/Data/test.db | Bin 0 -> 4096 bytes .../framework/I18N/TestOfDateTimeFormatInfo.php | 223 +++++++++++++++++++++ .../UnitTests/framework/I18N/messages/en/tests.mo | Bin 0 -> 403 bytes .../UnitTests/framework/I18N/messages/en/tests.po | 18 ++ .../UnitTests/framework/I18N/messages/en/tests.xml | 17 ++ .../framework/I18N/messages/en_AU/tests.mo | Bin 0 -> 371 bytes .../framework/I18N/messages/en_AU/tests.mo.bak | Bin 0 -> 371 bytes .../framework/I18N/messages/en_AU/tests.po | 15 ++ .../framework/I18N/messages/en_AU/tests.po.bak | 15 ++ .../framework/I18N/messages/en_AU/tests.xml | 13 ++ .../framework/I18N/messages/en_AU/tests.xml.bak | 13 ++ .../UnitTests/framework/I18N/messages/messages.db | Bin 0 -> 8192 bytes .../framework/I18N/messages/messages.db.bak | Bin 0 -> 8192 bytes .../framework/I18N/messages/messages.en.mo | Bin 0 -> 373 bytes .../framework/I18N/messages/messages.en.po | 15 ++ .../framework/I18N/messages/messages.en.xml | 19 ++ .../framework/I18N/messages/messages.en_AU.mo | Bin 0 -> 414 bytes .../framework/I18N/messages/messages.en_AU.mo.bak | Bin 0 -> 414 bytes .../framework/I18N/messages/messages.en_AU.po | 18 ++ .../framework/I18N/messages/messages.en_AU.po.bak | 18 ++ .../framework/I18N/messages/messages.en_AU.xml | 17 ++ .../framework/I18N/messages/messages.en_AU.xml.bak | 17 ++ .../UnitTests/framework/I18N/messages/messages.mo | Bin 0 -> 409 bytes .../UnitTests/framework/I18N/messages/messages.po | 18 ++ .../UnitTests/framework/I18N/messages/messages.xml | 23 +++ .../framework/I18N/messages/messages_mysql.sql | 69 +++++++ .../framework/I18N/messages/tests.en_AU.po | 7 + tests/UnitTests/framework/I18N/messages/tests.mo | Bin 0 -> 404 bytes tests/UnitTests/framework/I18N/messages/tests.po | 18 ++ tests/UnitTests/framework/I18N/messages/tests.xml | 17 ++ .../UnitTests/framework/I18N/testChoiceFormat.php | 34 ++++ tests/UnitTests/framework/I18N/testCultureInfo.php | 94 +++++++++ tests/UnitTests/framework/I18N/testDateFormat.php | 99 +++++++++ .../UnitTests/framework/I18N/testMessageFormat.php | 13 ++ .../framework/I18N/testMessageFormat_SQLite.php | 142 +++++++++++++ .../framework/I18N/testMessageFormat_XLIFF.php | 174 ++++++++++++++++ .../framework/I18N/testMessageFormat_gettext.php | 176 ++++++++++++++++ .../UnitTests/framework/I18N/testNumberFormat.php | 113 +++++++++++ .../framework/I18N/testNumberFormatInfo.php | 105 ++++++++++ tests/UnitTests/framework/I18N/tmp/cache.txt | 0 tests/UnitTests/framework/index.php | 5 +- 41 files changed, 1523 insertions(+), 2 deletions(-) create mode 100644 tests/UnitTests/framework/Data/test.db create mode 100644 tests/UnitTests/framework/I18N/TestOfDateTimeFormatInfo.php create mode 100644 tests/UnitTests/framework/I18N/messages/en/tests.mo create mode 100644 tests/UnitTests/framework/I18N/messages/en/tests.po create mode 100644 tests/UnitTests/framework/I18N/messages/en/tests.xml create mode 100644 tests/UnitTests/framework/I18N/messages/en_AU/tests.mo create mode 100644 tests/UnitTests/framework/I18N/messages/en_AU/tests.mo.bak create mode 100644 tests/UnitTests/framework/I18N/messages/en_AU/tests.po create mode 100644 tests/UnitTests/framework/I18N/messages/en_AU/tests.po.bak create mode 100644 tests/UnitTests/framework/I18N/messages/en_AU/tests.xml create mode 100644 tests/UnitTests/framework/I18N/messages/en_AU/tests.xml.bak create mode 100644 tests/UnitTests/framework/I18N/messages/messages.db create mode 100644 tests/UnitTests/framework/I18N/messages/messages.db.bak create mode 100644 tests/UnitTests/framework/I18N/messages/messages.en.mo create mode 100644 tests/UnitTests/framework/I18N/messages/messages.en.po create mode 100644 tests/UnitTests/framework/I18N/messages/messages.en.xml create mode 100644 tests/UnitTests/framework/I18N/messages/messages.en_AU.mo create mode 100644 tests/UnitTests/framework/I18N/messages/messages.en_AU.mo.bak create mode 100644 tests/UnitTests/framework/I18N/messages/messages.en_AU.po create mode 100644 tests/UnitTests/framework/I18N/messages/messages.en_AU.po.bak create mode 100644 tests/UnitTests/framework/I18N/messages/messages.en_AU.xml create mode 100644 tests/UnitTests/framework/I18N/messages/messages.en_AU.xml.bak create mode 100644 tests/UnitTests/framework/I18N/messages/messages.mo create mode 100644 tests/UnitTests/framework/I18N/messages/messages.po create mode 100644 tests/UnitTests/framework/I18N/messages/messages.xml create mode 100644 tests/UnitTests/framework/I18N/messages/messages_mysql.sql create mode 100644 tests/UnitTests/framework/I18N/messages/tests.en_AU.po create mode 100644 tests/UnitTests/framework/I18N/messages/tests.mo create mode 100644 tests/UnitTests/framework/I18N/messages/tests.po create mode 100644 tests/UnitTests/framework/I18N/messages/tests.xml create mode 100644 tests/UnitTests/framework/I18N/testChoiceFormat.php create mode 100644 tests/UnitTests/framework/I18N/testCultureInfo.php create mode 100644 tests/UnitTests/framework/I18N/testDateFormat.php create mode 100644 tests/UnitTests/framework/I18N/testMessageFormat.php create mode 100644 tests/UnitTests/framework/I18N/testMessageFormat_SQLite.php create mode 100644 tests/UnitTests/framework/I18N/testMessageFormat_XLIFF.php create mode 100644 tests/UnitTests/framework/I18N/testMessageFormat_gettext.php create mode 100644 tests/UnitTests/framework/I18N/testNumberFormat.php create mode 100644 tests/UnitTests/framework/I18N/testNumberFormatInfo.php create mode 100644 tests/UnitTests/framework/I18N/tmp/cache.txt (limited to 'tests') diff --git a/tests/UnitTests/framework/Data/test.db b/tests/UnitTests/framework/Data/test.db new file mode 100644 index 00000000..fcf08f16 Binary files /dev/null and b/tests/UnitTests/framework/Data/test.db differ diff --git a/tests/UnitTests/framework/I18N/TestOfDateTimeFormatInfo.php b/tests/UnitTests/framework/I18N/TestOfDateTimeFormatInfo.php new file mode 100644 index 00000000..a2d78807 --- /dev/null +++ b/tests/UnitTests/framework/I18N/TestOfDateTimeFormatInfo.php @@ -0,0 +1,223 @@ +UnitTestCase(); + } + + function setUp() + { + $this->format = DateTimeFormatInfo::getInstance('en'); + } + + function testAbbreviatedDayNames() + { + $names = $this->format->AbbreviatedDayNames; + $this->assertTrue(is_array($names),'Must be an array!'); + $this->assertEqual(count($names),7,'Must have 7 day names'); + + //assuming invariant culture. + $days = array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"); + $this->assertEqual($names, $days); + + //try to set the data + $data = array('Hel', 'wor'); + $this->format->AbbreviatedDayNames = $data; + $newNames = $this->format->AbbreviatedDayNames; + $this->assertTrue(is_array($newNames),'Must be an array!'); + $this->assertEqual(count($newNames),2,'Must have 2 entries'); + $this->assertEqual($newNames, $data); + } + + function testNarrowDayNames() + { + $names = $this->format->NarrowDayNames; + $this->assertTrue(is_array($names),'Must be an array!'); + $this->assertEqual(count($names),7,'Must have 7 day names'); + + //assuming invariant culture. + $days = array("S", "M", "T", "W", "T", "F", "S"); + $this->assertEqual($names, $days); + + //try to set the data + $data = array('H', 'w'); + $this->format->NarrowDayNames = $data; + $newNames = $this->format->NarrowDayNames; + $this->assertTrue(is_array($newNames),'Must be an array!'); + $this->assertEqual(count($newNames),2,'Must have 2 entries'); + $this->assertEqual($newNames, $data); + } + + function testDayNames() + { + $names = $this->format->DayNames; + $this->assertTrue(is_array($names),'Must be an array!'); + $this->assertEqual(count($names),7,'Must have 7 day names'); + + //assuming invariant culture. + $days = array( "Sunday","Monday", "Tuesday", "Wednesday", + "Thursday", "Friday", "Saturday"); + $this->assertEqual($names, $days); + + //try to set the data + $data = array('Hello', 'world'); + $this->format->DayNames = $data; + $newNames = $this->format->DayNames; + $this->assertTrue(is_array($newNames),'Must be an array!'); + $this->assertEqual(count($newNames),2,'Must have 2 entries'); + $this->assertEqual($newNames, $data); + } + + function testMonthNames() + { + $names = $this->format->MonthNames; + $this->assertTrue(is_array($names),'Must be an array!'); + $this->assertEqual(count($names),12,'Must have 12 month names'); + + //assuming invariant culture. + $days = array( "January", "February", "March", "April", + "May", "June", "July", "August", "September", + "October", "November", "December"); + $this->assertEqual($names, $days); + + //try to set the data + $data = array('Hello', 'world'); + $this->format->MonthNames = $data; + $newNames = $this->format->MonthNames; + $this->assertTrue(is_array($newNames),'Must be an array!'); + $this->assertEqual(count($newNames),2,'Must have 2 entries'); + $this->assertEqual($newNames, $data); + } + + function testNarrowMonthNames() + { + $names = $this->format->NarrowMonthNames; + $this->assertTrue(is_array($names),'Must be an array!'); + $this->assertEqual(count($names),12,'Must have 12 month names'); + + //assuming invariant culture. + $days = array( "J", "F", "M", "A", "M", "J", "J", + "A", "S", "O", "N", "D"); + $this->assertEqual($names, $days); + + //try to set the data + $data = array('Hello', 'world'); + $this->format->NarrowMonthNames = $data; + $newNames = $this->format->NarrowMonthNames; + $this->assertTrue(is_array($newNames),'Must be an array!'); + $this->assertEqual(count($newNames),2,'Must have 2 entries'); + $this->assertEqual($newNames, $data); + } + + function testAbbreviatedMonthNames() + { + $names = $this->format->AbbreviatedMonthNames; + $this->assertTrue(is_array($names),'Must be an array!'); + $this->assertEqual(count($names),12,'Must have 12 month names'); + + //assuming invariant culture. + $days = array( "Jan", "Feb", "Mar", "Apr", + "May", "Jun", "Jul", "Aug", "Sep", + "Oct", "Nov", "Dec"); + $this->assertEqual($names, $days); + + //try to set the data + $data = array('Hello', 'world'); + $this->format->AbbreviatedMonthNames = $data; + $newNames = $this->format->AbbreviatedMonthNames; + $this->assertTrue(is_array($newNames),'Must be an array!'); + $this->assertEqual(count($newNames),2,'Must have 2 entries'); + $this->assertEqual($newNames, $data); + } + + function testEra() + { + //era for invariant culture is assumed to have + // 1 for AD and 0 for BC + $this->assertEqual('AD', $this->format->getEra(1)); + $this->assertEqual('BC', $this->format->getEra(0)); + } + + function testAMPMMarkers() + { + $am_pm = array('AM','PM'); + $data = $this->format->AMPMMarkers; + $this->assertTrue(is_array($data)); + $this->assertEqual($am_pm, $data); + $this->assertEqual('AM', $this->format->AMDesignator); + $this->assertEqual('PM', $this->format->PMDesignator); + + //try to set the data + $data = array('Hello', 'world'); + $this->format->AMPMMarkers = $data; + $newNames = $this->format->AMPMMarkers; + $this->assertTrue(is_array($newNames),'Must be an array!'); + $this->assertEqual(count($newNames),2,'Must have 2 entries'); + $this->assertEqual($newNames, $data); + + $this->format->AMDesignator = 'TTTT'; + $this->assertEqual('TTTT',$this->format->AMDesignator); + + $this->format->PMDesignator = 'SSS'; + $this->assertEqual('SSS',$this->format->PMDesignator); + } + + function testPatterns() + { + //patterns for invariant + $patterns = array( + 'FullTimePattern' => 'h:mm:ss a z', + 'LongTimePattern' => 'h:mm:ss a z', + 'MediumTimePattern' => 'h:mm:ss a', + 'ShortTimePattern' => 'h:mm a', + 'FullDatePattern' => 'EEEE, MMMM d, yyyy', + 'LongDatePattern' => 'MMMM d, yyyy', + 'MediumDatePattern' => 'MMM d, yyyy', + 'ShortDatePattern' => 'M/d/yy', + 'DateTimeOrderPattern' => '{1} {0}' + ); + + foreach($patterns as $property => $pattern) + { + $this->assertEqual($pattern, $this->format->$property); + } + + $hello = 'Hello'; + $world = 'world'; + $expectedResult = $hello.' '.$world; + $this->assertEqual($expectedResult, + $this->format->formatDateTime($hello, $world)); + } + + function testInvariantInfo() + { + $format = DateTimeFormatInfo::getInstance(); + + //the variant datetime format for medium date + //should be the follow + $pattern = 'MMM d, yyyy'; + + $this->assertEqual($pattern, $format->MediumDatePattern); + + $invariant = $format->getInvariantInfo(); + + $this->assertIdentical($format, $invariant); + } + + function testGetInstance() + { + $format = DateTimeFormatInfo::getInstance('zh_CN'); + + $pattern = 'yyyy-M-d'; + $this->assertEqual($pattern, $format->MediumDatePattern); + } +} + + +?> \ No newline at end of file diff --git a/tests/UnitTests/framework/I18N/messages/en/tests.mo b/tests/UnitTests/framework/I18N/messages/en/tests.mo new file mode 100644 index 00000000..ee243202 Binary files /dev/null and b/tests/UnitTests/framework/I18N/messages/en/tests.mo differ diff --git a/tests/UnitTests/framework/I18N/messages/en/tests.po b/tests/UnitTests/framework/I18N/messages/en/tests.po new file mode 100644 index 00000000..07860851 --- /dev/null +++ b/tests/UnitTests/framework/I18N/messages/en/tests.po @@ -0,0 +1,18 @@ +msgid "" +msgstr "" +"Project-Id-Version: I18N Tests\n" +"POT-Creation-Date: \n" +"PO-Revision-Date: 2005-01-09 14:11+1000\n" +"Last-Translator: \n" +"Language-Team: Wei Zhuo\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Poedit-Basepath: F:\\www\\prado\\framework\\I18N\\tests\n" + +msgid "Hello" +msgstr "hello" + +msgid "Goodbye" +msgstr "Sayonara" + diff --git a/tests/UnitTests/framework/I18N/messages/en/tests.xml b/tests/UnitTests/framework/I18N/messages/en/tests.xml new file mode 100644 index 00000000..dbcd6831 --- /dev/null +++ b/tests/UnitTests/framework/I18N/messages/en/tests.xml @@ -0,0 +1,17 @@ + + + + + + + + Hello + hello + + + Goodbye + Sayonara + + + + diff --git a/tests/UnitTests/framework/I18N/messages/en_AU/tests.mo b/tests/UnitTests/framework/I18N/messages/en_AU/tests.mo new file mode 100644 index 00000000..a9a26db2 Binary files /dev/null and b/tests/UnitTests/framework/I18N/messages/en_AU/tests.mo differ diff --git a/tests/UnitTests/framework/I18N/messages/en_AU/tests.mo.bak b/tests/UnitTests/framework/I18N/messages/en_AU/tests.mo.bak new file mode 100644 index 00000000..a9a26db2 Binary files /dev/null and b/tests/UnitTests/framework/I18N/messages/en_AU/tests.mo.bak differ diff --git a/tests/UnitTests/framework/I18N/messages/en_AU/tests.po b/tests/UnitTests/framework/I18N/messages/en_AU/tests.po new file mode 100644 index 00000000..9f81f650 --- /dev/null +++ b/tests/UnitTests/framework/I18N/messages/en_AU/tests.po @@ -0,0 +1,15 @@ +msgid "" +msgstr "" +"Project-Id-Version: I18N Tests\n" +"POT-Creation-Date: \n" +"PO-Revision-Date: 2004-12-25 12:25+1000\n" +"Last-Translator: \n" +"Language-Team: Wei Zhuo\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Poedit-Basepath: F:\\www\\prado\\framework\\I18N\\tests\n" + +msgid "Hello" +msgstr "Howdy!" + diff --git a/tests/UnitTests/framework/I18N/messages/en_AU/tests.po.bak b/tests/UnitTests/framework/I18N/messages/en_AU/tests.po.bak new file mode 100644 index 00000000..9f81f650 --- /dev/null +++ b/tests/UnitTests/framework/I18N/messages/en_AU/tests.po.bak @@ -0,0 +1,15 @@ +msgid "" +msgstr "" +"Project-Id-Version: I18N Tests\n" +"POT-Creation-Date: \n" +"PO-Revision-Date: 2004-12-25 12:25+1000\n" +"Last-Translator: \n" +"Language-Team: Wei Zhuo\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Poedit-Basepath: F:\\www\\prado\\framework\\I18N\\tests\n" + +msgid "Hello" +msgstr "Howdy!" + diff --git a/tests/UnitTests/framework/I18N/messages/en_AU/tests.xml b/tests/UnitTests/framework/I18N/messages/en_AU/tests.xml new file mode 100644 index 00000000..7ed84220 --- /dev/null +++ b/tests/UnitTests/framework/I18N/messages/en_AU/tests.xml @@ -0,0 +1,13 @@ + + + + + + + + Hello + Howdy! + + + + diff --git a/tests/UnitTests/framework/I18N/messages/en_AU/tests.xml.bak b/tests/UnitTests/framework/I18N/messages/en_AU/tests.xml.bak new file mode 100644 index 00000000..7ed84220 --- /dev/null +++ b/tests/UnitTests/framework/I18N/messages/en_AU/tests.xml.bak @@ -0,0 +1,13 @@ + + + + + + + + Hello + Howdy! + + + + diff --git a/tests/UnitTests/framework/I18N/messages/messages.db b/tests/UnitTests/framework/I18N/messages/messages.db new file mode 100644 index 00000000..73b518c5 Binary files /dev/null and b/tests/UnitTests/framework/I18N/messages/messages.db differ diff --git a/tests/UnitTests/framework/I18N/messages/messages.db.bak b/tests/UnitTests/framework/I18N/messages/messages.db.bak new file mode 100644 index 00000000..73b518c5 Binary files /dev/null and b/tests/UnitTests/framework/I18N/messages/messages.db.bak differ diff --git a/tests/UnitTests/framework/I18N/messages/messages.en.mo b/tests/UnitTests/framework/I18N/messages/messages.en.mo new file mode 100644 index 00000000..db8838e3 Binary files /dev/null and b/tests/UnitTests/framework/I18N/messages/messages.en.mo differ diff --git a/tests/UnitTests/framework/I18N/messages/messages.en.po b/tests/UnitTests/framework/I18N/messages/messages.en.po new file mode 100644 index 00000000..9299045c --- /dev/null +++ b/tests/UnitTests/framework/I18N/messages/messages.en.po @@ -0,0 +1,15 @@ +msgid "" +msgstr "" +"Project-Id-Version: I18N Tests\n" +"POT-Creation-Date: \n" +"PO-Revision-Date: 2004-12-25 12:26+1000\n" +"Last-Translator: \n" +"Language-Team: Wei Zhuo\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Poedit-Basepath: F:\\www\\prado\\framework\\I18N\\tests\n" + +msgid "Hello" +msgstr "Hello :)" + diff --git a/tests/UnitTests/framework/I18N/messages/messages.en.xml b/tests/UnitTests/framework/I18N/messages/messages.en.xml new file mode 100644 index 00000000..c3eb465b --- /dev/null +++ b/tests/UnitTests/framework/I18N/messages/messages.en.xml @@ -0,0 +1,19 @@ + + + + + + + + Hello + Hello :) + + + + \ No newline at end of file diff --git a/tests/UnitTests/framework/I18N/messages/messages.en_AU.mo b/tests/UnitTests/framework/I18N/messages/messages.en_AU.mo new file mode 100644 index 00000000..f4822800 Binary files /dev/null and b/tests/UnitTests/framework/I18N/messages/messages.en_AU.mo differ diff --git a/tests/UnitTests/framework/I18N/messages/messages.en_AU.mo.bak b/tests/UnitTests/framework/I18N/messages/messages.en_AU.mo.bak new file mode 100644 index 00000000..f4822800 Binary files /dev/null and b/tests/UnitTests/framework/I18N/messages/messages.en_AU.mo.bak differ diff --git a/tests/UnitTests/framework/I18N/messages/messages.en_AU.po b/tests/UnitTests/framework/I18N/messages/messages.en_AU.po new file mode 100644 index 00000000..d795be2b --- /dev/null +++ b/tests/UnitTests/framework/I18N/messages/messages.en_AU.po @@ -0,0 +1,18 @@ +msgid "" +msgstr "" +"Project-Id-Version: I18N Tests\n" +"POT-Creation-Date: \n" +"PO-Revision-Date: 2005-01-09 14:02:25\n" +"Last-Translator: \n" +"Language-Team: Wei Zhuo\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Poedit-Basepath: F:\\www\\prado\\framework\\I18N\\ ests\n" + +msgid "Hello" +msgstr "G'day Mate!" + +msgid "Welcome" +msgstr "Welcome Mate!" + diff --git a/tests/UnitTests/framework/I18N/messages/messages.en_AU.po.bak b/tests/UnitTests/framework/I18N/messages/messages.en_AU.po.bak new file mode 100644 index 00000000..d795be2b --- /dev/null +++ b/tests/UnitTests/framework/I18N/messages/messages.en_AU.po.bak @@ -0,0 +1,18 @@ +msgid "" +msgstr "" +"Project-Id-Version: I18N Tests\n" +"POT-Creation-Date: \n" +"PO-Revision-Date: 2005-01-09 14:02:25\n" +"Last-Translator: \n" +"Language-Team: Wei Zhuo\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Poedit-Basepath: F:\\www\\prado\\framework\\I18N\\ ests\n" + +msgid "Hello" +msgstr "G'day Mate!" + +msgid "Welcome" +msgstr "Welcome Mate!" + diff --git a/tests/UnitTests/framework/I18N/messages/messages.en_AU.xml b/tests/UnitTests/framework/I18N/messages/messages.en_AU.xml new file mode 100644 index 00000000..cb4c4255 --- /dev/null +++ b/tests/UnitTests/framework/I18N/messages/messages.en_AU.xml @@ -0,0 +1,17 @@ + + + + + + + + Hello + G'day Mate! + + + Welcome + Welcome Mate! + + + + diff --git a/tests/UnitTests/framework/I18N/messages/messages.en_AU.xml.bak b/tests/UnitTests/framework/I18N/messages/messages.en_AU.xml.bak new file mode 100644 index 00000000..cb4c4255 --- /dev/null +++ b/tests/UnitTests/framework/I18N/messages/messages.en_AU.xml.bak @@ -0,0 +1,17 @@ + + + + + + + + Hello + G'day Mate! + + + Welcome + Welcome Mate! + + + + diff --git a/tests/UnitTests/framework/I18N/messages/messages.mo b/tests/UnitTests/framework/I18N/messages/messages.mo new file mode 100644 index 00000000..12cf1ff8 Binary files /dev/null and b/tests/UnitTests/framework/I18N/messages/messages.mo differ diff --git a/tests/UnitTests/framework/I18N/messages/messages.po b/tests/UnitTests/framework/I18N/messages/messages.po new file mode 100644 index 00000000..ade60e01 --- /dev/null +++ b/tests/UnitTests/framework/I18N/messages/messages.po @@ -0,0 +1,18 @@ +msgid "" +msgstr "" +"Project-Id-Version: I18N Tests\n" +"POT-Creation-Date: \n" +"PO-Revision-Date: 2004-12-25 12:25+1000\n" +"Last-Translator: \n" +"Language-Team: Wei Zhuo\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Poedit-Basepath: F:\\www\\prado\\framework\\I18N\\tests\n" + +msgid "Hello" +msgstr "Hello World" + +msgid "Welcome" +msgstr "Welcome!" + diff --git a/tests/UnitTests/framework/I18N/messages/messages.xml b/tests/UnitTests/framework/I18N/messages/messages.xml new file mode 100644 index 00000000..5fe588b6 --- /dev/null +++ b/tests/UnitTests/framework/I18N/messages/messages.xml @@ -0,0 +1,23 @@ + + + + + + + + Hello + Hello World + + + Welcome + Welcome! + + + + \ No newline at end of file diff --git a/tests/UnitTests/framework/I18N/messages/messages_mysql.sql b/tests/UnitTests/framework/I18N/messages/messages_mysql.sql new file mode 100644 index 00000000..811010c4 --- /dev/null +++ b/tests/UnitTests/framework/I18N/messages/messages_mysql.sql @@ -0,0 +1,69 @@ +# phpMyAdmin SQL Dump +# version 2.5.5-rc2 +# http://www.phpmyadmin.net +# +# Host: localhost +# Generation Time: Jan 09, 2005 at 09:24 PM +# Server version: 4.0.17 +# PHP Version: 5.0.2 +# +# Database : `messages` +# + +# -------------------------------------------------------- + +# +# Table structure for table `catalogue` +# + +DROP TABLE IF EXISTS catalogue; +CREATE TABLE catalogue ( + cat_id int(11) NOT NULL auto_increment, + name varchar(100) NOT NULL default '', + source_lang varchar(100) NOT NULL default '', + target_lang varchar(100) NOT NULL default '', + date_created int(11) NOT NULL default '0', + date_modified int(11) NOT NULL default '0', + author varchar(255) NOT NULL default '', + PRIMARY KEY (cat_id) +) TYPE=MyISAM AUTO_INCREMENT=7 ; + + +INSERT INTO catalogue VALUES ('1', 'messages', '', '', '', '1103936017', ''); +INSERT INTO catalogue VALUES ('2', 'messages.en', '', '', '', '1103936017', ''); +INSERT INTO catalogue VALUES ('3', 'messages.en_AU', '', '', '', '1105250301', ''); +INSERT INTO catalogue VALUES ('4', 'tests', '', '', '', '1103936017', ''); +INSERT INTO catalogue VALUES ('5', 'tests.en', '', '', '', '1103936017', ''); +INSERT INTO catalogue VALUES ('6', 'tests.en_AU', '', '', '', '1103936017', ''); + +# -------------------------------------------------------- + +# +# Table structure for table `trans_unit` +# + +DROP TABLE IF EXISTS trans_unit; +CREATE TABLE trans_unit ( + msg_id int(11) NOT NULL auto_increment, + cat_id int(11) NOT NULL default '1', + id varchar(255) NOT NULL default '', + source text NOT NULL, + target text NOT NULL, + comments text NOT NULL, + date_added int(11) NOT NULL default '0', + date_modified int(11) NOT NULL default '0', + author varchar(255) NOT NULL default '', + translated tinyint(1) NOT NULL default '0', + PRIMARY KEY (msg_id) +) TYPE=MyISAM AUTO_INCREMENT=19 ; + +INSERT INTO trans_unit VALUES ('1', '1', '1', 'Hello', 'Hello World', '', '', '', '', '1'); +INSERT INTO trans_unit VALUES ('2', '2', '1', 'Hello', 'Hello :)', '', '', '', '', '0'); +INSERT INTO trans_unit VALUES ('3', '1', '1', 'Welcome', 'Welcome!', '', '', '', '', '0'); +INSERT INTO trans_unit VALUES ('4', '3', '1', 'Hello', 'G''day Mate!', '', '', '', '', '0'); +INSERT INTO trans_unit VALUES ('5', '3', '2', 'Welcome', 'Welcome Mate!', '', '', '', '', '0'); +INSERT INTO trans_unit VALUES ('13', '4', '1', 'Goodbye', 'Aloha!', '', '', '', '', '0'); +INSERT INTO trans_unit VALUES ('14', '4', '2', 'Welcome', 'Ho Ho!', '', '', '', '', '0'); +INSERT INTO trans_unit VALUES ('15', '5', '1', 'Hello', 'hello', '', '', '', '', '0'); +INSERT INTO trans_unit VALUES ('16', '5', '2', 'Goodbye', 'Sayonara', '', '', '', '', '0'); +INSERT INTO trans_unit VALUES ('17', '6', '1', 'Hello', 'Howdy!', '', '', '', '', '0'); \ No newline at end of file diff --git a/tests/UnitTests/framework/I18N/messages/tests.en_AU.po b/tests/UnitTests/framework/I18N/messages/tests.en_AU.po new file mode 100644 index 00000000..fda7021d --- /dev/null +++ b/tests/UnitTests/framework/I18N/messages/tests.en_AU.po @@ -0,0 +1,7 @@ +msgid "" +msgstr "" +"PO-Revision-Date: 2005-01-09 14:17:13\n" + +msgid "Testing123" +msgstr "" + diff --git a/tests/UnitTests/framework/I18N/messages/tests.mo b/tests/UnitTests/framework/I18N/messages/tests.mo new file mode 100644 index 00000000..394b6196 Binary files /dev/null and b/tests/UnitTests/framework/I18N/messages/tests.mo differ diff --git a/tests/UnitTests/framework/I18N/messages/tests.po b/tests/UnitTests/framework/I18N/messages/tests.po new file mode 100644 index 00000000..4f5f3fbc --- /dev/null +++ b/tests/UnitTests/framework/I18N/messages/tests.po @@ -0,0 +1,18 @@ +msgid "" +msgstr "" +"Project-Id-Version: I18N Tests\n" +"POT-Creation-Date: \n" +"PO-Revision-Date: 2005-01-09 14:07+1000\n" +"Last-Translator: \n" +"Language-Team: Wei Zhuo\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Poedit-Basepath: F:\\www\\prado\\framework\\I18N\\tests\n" + +msgid "Goodbye" +msgstr "Aloha!" + +msgid "Welcome" +msgstr "Ho Ho!" + diff --git a/tests/UnitTests/framework/I18N/messages/tests.xml b/tests/UnitTests/framework/I18N/messages/tests.xml new file mode 100644 index 00000000..73f404b1 --- /dev/null +++ b/tests/UnitTests/framework/I18N/messages/tests.xml @@ -0,0 +1,17 @@ + + + + + + + + Goodbye + Aloha! + + + Welcome + Ho Ho! + + + + diff --git a/tests/UnitTests/framework/I18N/testChoiceFormat.php b/tests/UnitTests/framework/I18N/testChoiceFormat.php new file mode 100644 index 00000000..8cc3f1d3 --- /dev/null +++ b/tests/UnitTests/framework/I18N/testChoiceFormat.php @@ -0,0 +1,34 @@ +UnitTestCase(); + } + + function testChoices() + { + $choice = new ChoiceFormat(); + $string = '[0] are no files |[1] is one file |(1,Inf] are {number} files'; + + $want = 'are no files'; + $this->assertEqual($want, $choice->format($string, 0)); + + $want = 'is one file'; + $this->assertEqual($want, $choice->format($string, 1)); + + $want = 'are {number} files'; + $this->assertEqual($want, $choice->format($string, 5)); + + $this->assertFalse($choice->format($string, -1)); + + $string = '{1,2} one two |{3,4} three four |[2,5] two to five inclusive'; + $this->assertEqual($choice->format($string,1),'one two'); + $this->assertEqual($choice->format($string,2.1),'two to five inclusive'); + $this->assertEqual($choice->format($string,3),'three four'); + } +} + +?> \ No newline at end of file diff --git a/tests/UnitTests/framework/I18N/testCultureInfo.php b/tests/UnitTests/framework/I18N/testCultureInfo.php new file mode 100644 index 00000000..7e204ede --- /dev/null +++ b/tests/UnitTests/framework/I18N/testCultureInfo.php @@ -0,0 +1,94 @@ +UnitTestCase(); + } + + function setUp() + { + $this->culture = CultureInfo::getInvariantCulture(); + } + + function testCultureName() + { + $name = 'en'; + + $this->assertEqual($name, $this->culture->Name); + + //the default/invariant culture should be neutral + $this->assertTrue($this->culture->IsNeutralCulture); + } + + function testCultureList() + { + $allCultures = CultureInfo::getCultures(); + $neutralCultures = CultureInfo::getCultures(CultureInfo::NEUTRAL); + $specificCultures = CultureInfo::getCultures(CultureInfo::SPECIFIC); + + //there should be 246 cultures all together. + $this->assertEqual(count($allCultures),246); + $this->assertEqual(count($neutralCultures),76); + $this->assertEqual(count($specificCultures),170); + + } + + function testParentCultures() + { + $zh_CN = new CultureInfo('zh_CN'); + $parent = $zh_CN->Parent; + $grandparent = $parent->Parent; + + $this->assertEqual($zh_CN->Name, 'zh_CN'); + $this->assertEqual($parent->Name, 'zh'); + $this->assertEqual($grandparent->Name, 'en'); + $this->assertEqual($grandparent->Parent->Name, 'en'); + } + + function testCountryNames() + { + $culture = new CultureInfo('fr_FR'); + $this->assertEqual($culture->Countries['AE'], 'Émirats arabes unis'); + } + + function testCurrencies() + { + $culture = new CultureInfo('en_AU'); + $au = array('$', 'Australian Dollar'); + $this->assertEqual($au, $culture->Currencies['AUD']); + } + + function testLanguages() + { + $culture = new CultureInfo('fr_BE'); + $this->assertEqual($culture->Languages['fr'], 'français'); + } + + function testScripts() + { + $culture = new CultureInfo('fr'); + $this->assertEqual($culture->Scripts['Armn'], 'arménien'); + } + + function testTimeZones() + { + $culture = new CultureInfo('fi'); + $zone = array( + "America/Los_Angeles", + "Tyynenmeren normaaliaika", + "PST", + "Tyynenmeren kesäaika", + "PDT", + "Los Angeles"); + $this->assertEqual($culture->TimeZones[1],$zone); + } + +} + +?> \ No newline at end of file diff --git a/tests/UnitTests/framework/I18N/testDateFormat.php b/tests/UnitTests/framework/I18N/testDateFormat.php new file mode 100644 index 00000000..7e4259d6 --- /dev/null +++ b/tests/UnitTests/framework/I18N/testDateFormat.php @@ -0,0 +1,99 @@ +UnitTestCase(); + } + + function testStandardPatterns() + { + $dateFormatter = new DateFormat(); + + $time = @mktime(9, 9, 9, 9, 1, 2004); + $zone = @date('T', $time); + //var_dump(date('c',$time)); + //for ShortDatePattern "M/d/yy" + $this->assertEqual('9/1/04', $dateFormatter->format($time, 'd')); + //var_dump(date('c',strtotime($dateFormatter->format($time,'d')))); + + //for LongDatePattern "MMMM d, yyyy" + $wants = 'September 1, 2004'; + $this->assertEqual($wants, $dateFormatter->format($time, 'D')); + //var_dump(date('c',strtotime($dateFormatter->format($time,'D')))); + + //for Full date and time "MMMM d, yyyy h:mm a" + $wants = 'September 1, 2004 9:09 AM'; + $this->assertEqual($wants, $dateFormatter->format($time, 'f')); + //var_dump(date('c',strtotime($dateFormatter->format($time,'f')))); + + //for FullDateTimePattern "MMMM d, yyyy h:mm:ss a z" + $wants = 'September 1, 2004 9:09:09 AM '.$zone; + $this->assertEqual($wants, $dateFormatter->format($time, 'F')); + + //for General "M/d/yy h:mm a" + $wants = '9/1/04 9:09 AM'; + $this->assertEqual($wants, $dateFormatter->format($time, 'g')); + //var_dump(date('c',strtotime($dateFormatter->format($time,'g')))); + + //for General "M/d/yy h:mm:ss a z" + $wants = '9/1/04 9:09:09 AM '.$zone; + $this->assertEqual($wants, $dateFormatter->format($time, 'G')); + + //for MonthDayPattern "MMMM dd" (invariant) + $wants = 'September 01'; + $this->assertEqual($wants, $dateFormatter->format($time, 'm')); + //var_dump(date('c',strtotime($dateFormatter->format($time,'m')))); + + //for RFC1123Pattern "EEE, dd MMM yyyy HH:mm:ss" (invariant) + $wants = 'Wed, 01 Sep 2004 09:09:09'; + $this->assertEqual($wants, $dateFormatter->format($time, 'r')); + //var_dump(date('c',strtotime($dateFormatter->format($time,'r')))); + + //for SortableDateTimePattern "yyyy-MM-ddTHH:mm:ss" (invariant) + $wants = '2004-09-01T09:09:09'; + $this->assertEqual($wants, $dateFormatter->format($time, 's')); + //var_dump(date('c',strtotime($dateFormatter->format($time,'s')))); + + //for ShortTimePattern "H:mm a" + $wants = '9:09 AM'; + $this->assertEqual($wants, $dateFormatter->format($time, 't')); + //(date('c',strtotime($dateFormatter->format($time,'t')))); + + //for LongTimePattern "H:mm:ss a z" + $wants = '9:09:09 AM '.$zone; + $this->assertEqual($wants, $dateFormatter->format($time, 'T')); + + //for UniversalSortableDateTimePattern "yyyy-MM-dd HH:mm:ss z" + //(invariant) + $wants = '2004-09-01 09:09:09 '.$zone; + $this->assertEqual($wants, $dateFormatter->format($time, 'u')); + + //for Full date and time "EEEE dd MMMM yyyy HH:mm:ss" (invariant) + $wants = 'Wednesday 01 September 2004 09:09:09'; + $this->assertEqual($wants, $dateFormatter->format($time, 'U')); + //var_dump(date('c',strtotime($dateFormatter->format($time,'U')))); + + //for YearMonthPattern "yyyy MMMM" (invariant) + $wants = '2004 September'; + $this->assertEqual($wants, $dateFormatter->format($time, 'y')); + //var_dump(date('c',strtotime($dateFormatter->format($time,'y')))); + } + + function testCustomPatterns() + { + $dateFormatter = new DateFormat(); + + $time = @mktime(9, 9, 9, 9, 1, 2004); + + $pattern = "'Hello' EEEE, 'it should be' MMM yyyy HH:mm:ss!!!"; + $wants = 'Hello Wednesday, it should be Sep 2004 09:09:09!!!'; + $this->assertEqual($wants, $dateFormatter->format($time, $pattern)); + + } +} + +?> \ No newline at end of file diff --git a/tests/UnitTests/framework/I18N/testMessageFormat.php b/tests/UnitTests/framework/I18N/testMessageFormat.php new file mode 100644 index 00000000..74b6f23f --- /dev/null +++ b/tests/UnitTests/framework/I18N/testMessageFormat.php @@ -0,0 +1,13 @@ +UnitTestCase(); + } +} + +?> \ No newline at end of file diff --git a/tests/UnitTests/framework/I18N/testMessageFormat_SQLite.php b/tests/UnitTests/framework/I18N/testMessageFormat_SQLite.php new file mode 100644 index 00000000..5b75a0a7 --- /dev/null +++ b/tests/UnitTests/framework/I18N/testMessageFormat_SQLite.php @@ -0,0 +1,142 @@ +UnitTestCase(); + $this->dir = dirname(__FILE__); + $this->tmp = $this->dir.'/tmp/'; + $this->source = "sqlite:///{$this->dir}/messages/messages.db"; + + } + + function test1() + { + $source = MessageSource::factory($this->type, $this->source); + $source->setCulture('en_AU'); + $source->setCache(new MessageCache($this->tmp)); + + $formatter = new MessageFormat($source); + $this->assertEqual($formatter->format('Hello'),'G\'day Mate!'); + + $this->assertEqual($formatter->format('Goodbye'), 'Goodbye'); + + $formatter->setUntranslatedPS(array('[T]','[/T]')); + $this->assertEqual($formatter->format('Hi'), '[T]Hi[/T]'); + + $source->getCache()->clear(); + + //save the untranslated + + } + + function getAllContents($file) + { + $db = sqlite_open($file); + $rs = sqlite_query('SELECT * FROM trans_unit',$db); + $result = ''; + while($row = sqlite_fetch_array($rs,SQLITE_NUM)) + { + $result .= implode(', ',$row)."\n"; + } + sqlite_close($db); + return $result; + } + + function testSaveUpdateDelete() + { + $backup = $this->dir.'/messages/messages.db.bak'; + $dbfile = $this->dir.'/messages/messages.db'; + + //restore using the back file + copy($backup,$dbfile); + + //test that the back file doesn't contain the 'Testing123' string. + $contents = $this->getAllContents($dbfile); + $this->assertNoUnwantedPattern('/Testing123/',$contents); + + $source = MessageSource::factory($this->type, $this->source); + $source->setCulture('en_AU'); + $source->setCache(new MessageCache($this->tmp)); + + $formatter = new MessageFormat($source); + + $formatter->setUntranslatedPS(array('[t]','[/t]')); + + //add a untranslated string + $this->assertEqual($formatter->format('Testing123'), '[t]Testing123[/t]'); + + //save it + $this->assertTrue($formatter->getSource()->save()); + + //check the contents + $contents = $this->getAllContents($dbfile); + $this->assertWantedPattern('/Testing123/',$contents); + + //testing for update. + $this->assertTrue($formatter->getSource()->update( + 'Testing123', '123Test', 'update comments')); + + $contents = $this->getAllContents($dbfile); + $this->assertWantedPattern('/123Test/',$contents); + $this->assertWantedPattern('/update comments/',$contents); + + //var_dump(htmlspecialchars($contents)); + + //now doing some delete + //doesn't detect missing source + $this->assertTrue($formatter->getSource()->delete('Test123')); + $this->assertTrue($formatter->getSource()->delete('Testing123')); + + $contents = $this->getAllContents($dbfile); + $this->assertNoUnwantedPattern('/Testing123/',$contents); + + //restore using the backup file. + copy($backup,$dbfile); + $source->getCache()->clear(); + } + + function testCatalogueList() + { + $source = MessageSource::factory($this->type, $this->source); + $result[] = array('messages',NULL); + $result[] = array('messages', 'en'); + $result[] = array('messages','en_AU'); + $result[] = array('tests',NULL); + $result[] = array('tests','en'); + $result[] = array('tests','en_AU'); + + $this->assertEqual($result, $source->catalogues()); + } + + function testAltCatalogue() + { + $source = MessageSource::factory($this->type, $this->source); + $source->setCulture('en_AU'); + $source->setCache(new MessageCache($this->tmp)); + + $formatter = new MessageFormat($source); + $formatter->Catalogue = 'tests'; + + //from a different catalogue + $this->assertEqual($formatter->format('Hello'), 'Howdy!'); + $this->assertEqual($formatter->format('Welcome'), 'Ho Ho!'); + $this->assertEqual($formatter->format('Goodbye'), 'Sayonara'); + + //switch to 'messages' catalogue + $this->assertEqual($formatter->format('Hello',null,'messages'),'G\'day Mate!'); + + $source->getCache()->clear(); + } +} + +?> \ No newline at end of file diff --git a/tests/UnitTests/framework/I18N/testMessageFormat_XLIFF.php b/tests/UnitTests/framework/I18N/testMessageFormat_XLIFF.php new file mode 100644 index 00000000..4072c4ce --- /dev/null +++ b/tests/UnitTests/framework/I18N/testMessageFormat_XLIFF.php @@ -0,0 +1,174 @@ +UnitTestCase(); + $this->dir = dirname(__FILE__); + $this->tmp = $this->dir.'/tmp/'; + $this->source = $this->dir.'/messages'; + + } + + function test1() + { + $source = MessageSource::factory($this->type, $this->source); + $source->setCulture('en_AU'); + $source->setCache(new MessageCache($this->tmp)); + + $formatter = new MessageFormat($source); + $this->assertEqual($formatter->format('Hello'),'G\'day Mate!'); + + $this->assertEqual($formatter->format('Goodbye'), 'Goodbye'); + + $formatter->setUntranslatedPS(array('[T]','[/T]')); + $this->assertEqual($formatter->format('Hi'), '[T]Hi[/T]'); + + //clear cache + $source->getCache()->clear(); + + } + + function testSaveUpdateDelete() + { + $backup = $this->dir.'/messages/messages.en_AU.xml.bak'; + $xmlfile = $this->dir.'/messages/messages.en_AU.xml'; + + //restore using the back file + copy($backup,$xmlfile); + + //test that the back file doesn't contain the 'Testing123' string. + $contents = file_get_contents($xmlfile); + $this->assertNoUnwantedPattern('/Testing123/',$contents); + + $source = MessageSource::factory($this->type, $this->source); + $source->setCulture('en_AU'); + $source->setCache(new MessageCache($this->tmp)); + + $formatter = new MessageFormat($source); + + //add a untranslated string + $this->assertEqual($formatter->format('Testing123'), 'Testing123'); + + //save it + $this->assertTrue($formatter->getSource()->save()); + + //check the contents + $contents = file_get_contents($xmlfile); + $this->assertWantedPattern('/Testing123/',$contents); + + //testing for update. + $this->assertTrue($formatter->getSource()->update( + 'Testing123', '123Test', 'update comments')); + + $contents = file_get_contents($xmlfile); + $this->assertWantedPattern('/123Test/',$contents); + $this->assertWantedPattern('/update comments/',$contents); + + //var_dump(htmlspecialchars($contents)); + + //now doing some delete + $this->assertFalse($formatter->getSource()->delete('Test123')); + $this->assertTrue($formatter->getSource()->delete('Testing123')); + + $contents = file_get_contents($xmlfile); + $this->assertNoUnwantedPattern('/Testing123/',$contents); + + //restore using the backup file. + copy($backup,$xmlfile); + + $source->getCache()->clear(); + } + + function testCatalogueList() + { + $source = MessageSource::factory($this->type, $this->source); + $result[] = array('messages',NULL); + $result[] = array('messages', 'en'); + $result[] = array('messages','en_AU'); + $result[] = array('tests',NULL); + $result[] = array('tests','en'); + $result[] = array('tests','en_AU'); + + $this->assertEqual($result, $source->catalogues()); + } + + function testAltCatalogue() + { + $source = MessageSource::factory($this->type, $this->source); + $source->setCulture('en_AU'); + $source->setCache(new MessageCache($this->tmp)); + + $formatter = new MessageFormat($source); + $formatter->Catalogue = 'tests'; + + //from a different catalogue + $this->assertEqual($formatter->format('Hello'), 'Howdy!'); + $this->assertEqual($formatter->format('Welcome'), 'Ho Ho!'); + $this->assertEqual($formatter->format('Goodbye'), 'Sayonara'); + + //switch to 'messages' catalogue + $this->assertEqual($formatter->format('Hello',null,'messages'),'G\'day Mate!'); + + $source->getCache()->clear(); + } + + function testDirectoryTypeSaveUpdateDelete() + { + $backup = $this->dir.'/messages/en_AU/tests.xml.bak'; + $xmlfile = $this->dir.'/messages/en_AU/tests.xml'; + + //restore using the back file + copy($backup,$xmlfile); + + //test that the back file doesn't contain the 'Testing123' string. + $contents = file_get_contents($xmlfile); + $this->assertNoUnwantedPattern('/Testing123/',$contents); + + $source = MessageSource::factory($this->type, $this->source); + $source->setCulture('en_AU'); + $source->setCache(new MessageCache($this->tmp)); + + $formatter = new MessageFormat($source); + + //add a untranslated string, note, doesn't matter which catalogue + $this->assertEqual($formatter->format('Testing123'), 'Testing123'); + + //save it to the 'tests' catalgoue + $this->assertTrue($formatter->getSource()->save('tests')); + + //check the contents + $contents = file_get_contents($xmlfile); + $this->assertWantedPattern('/Testing123/',$contents); + + //testing for update. Update it to the 'tests' catalogue + $this->assertTrue($formatter->getSource()->update( + 'Testing123', '123Test', 'update comments','tests')); + + $contents = file_get_contents($xmlfile); + $this->assertWantedPattern('/123Test/',$contents); + $this->assertWantedPattern('/update comments/',$contents); + + //now doing some delete from the 'tests' catalogue + $this->assertFalse($formatter->getSource()->delete('Test123','tests')); + $this->assertTrue($formatter->getSource()->delete('Testing123','tests')); + + $contents = file_get_contents($xmlfile); + $this->assertNoUnwantedPattern('/Testing123/',$contents); + + //restore using the backup file. + copy($backup,$xmlfile); + + $source->getCache()->clear(); + } +} + +?> \ No newline at end of file diff --git a/tests/UnitTests/framework/I18N/testMessageFormat_gettext.php b/tests/UnitTests/framework/I18N/testMessageFormat_gettext.php new file mode 100644 index 00000000..6fa00e80 --- /dev/null +++ b/tests/UnitTests/framework/I18N/testMessageFormat_gettext.php @@ -0,0 +1,176 @@ +UnitTestCase(); + $this->dir = dirname(__FILE__); + $this->tmp = $this->dir.'/tmp/'; + $this->source = $this->dir.'/messages'; + } + + function test1() + { + $source = MessageSource::factory($this->type, $this->source); + $source->setCulture('en_AU'); + $source->setCache(new MessageCache($this->tmp)); + + $formatter = new MessageFormat($source); + $this->assertEqual($formatter->format('Hello'),'G\'day Mate!'); + + $this->assertEqual($formatter->format('Goodbye'), 'Goodbye'); + + $formatter->setUntranslatedPS(array('[T]','[/T]')); + $this->assertEqual($formatter->format('Hi'), '[T]Hi[/T]'); + + $source->getCache()->clear(); + } + + function testSaveUpdateDelete() + { + $MObackup = $this->dir.'/messages/messages.en_AU.mo.bak'; + $MOfile = $this->dir.'/messages/messages.en_AU.mo'; + $PObackup = $this->dir.'/messages/messages.en_AU.po.bak'; + $POfile = $this->dir.'/messages/messages.en_AU.po'; + + //restore using the back file + copy($MObackup,$MOfile); + copy($PObackup,$POfile); + + //test that the back file doesn't contain the 'Testing123' string. + $this->assertNoUnwantedPattern('/Testing123/',file_get_contents($MOfile)); + $this->assertNoUnwantedPattern('/Testing123/',file_get_contents($POfile)); + + $source = MessageSource::factory($this->type, $this->source); + $source->setCulture('en_AU'); + $source->setCache(new MessageCache($this->tmp)); + + $formatter = new MessageFormat($source); + + //add a untranslated string + $this->assertEqual($formatter->format('Testing123'), 'Testing123'); + + //save it + $this->assertTrue($formatter->getSource()->save()); + + //check the contents + //$this->assertWantedPattern('/Testing123/',file_get_contents($MOfile)); + $this->assertWantedPattern('/Testing123/',file_get_contents($POfile)); + + //testing for update. + $this->assertTrue($formatter->getSource()->update( + 'Testing123', '123Test', 'update comments')); + + $this->assertWantedPattern('/123Test/',file_get_contents($MOfile)); + + + //var_dump(htmlspecialchars($contents)); + + //now doing some delete + $this->assertFalse($formatter->getSource()->delete('Test123')); + $this->assertTrue($formatter->getSource()->delete('Testing123')); + + $this->assertNoUnwantedPattern('/Testing123/',file_get_contents($MOfile)); + $this->assertNoUnwantedPattern('/Testing123/',file_get_contents($POfile)); + + //restore using the backup file. + copy($MObackup,$MOfile); + copy($PObackup,$POfile); + + $source->getCache()->clear(); + } + + function testCatalogueList() + { + $source = MessageSource::factory($this->type, $this->source); + $result[] = array('messages',NULL); + $result[] = array('messages', 'en'); + $result[] = array('messages','en_AU'); + $result[] = array('tests',NULL); + $result[] = array('tests','en'); + $result[] = array('tests','en_AU'); + + $this->assertEqual($result, $source->catalogues()); + } + + function testAltCatalogue() + { + $source = MessageSource::factory($this->type, $this->source); + $source->setCulture('en_AU'); + $source->setCache(new MessageCache($this->tmp)); + + $formatter = new MessageFormat($source); + $formatter->Catalogue = 'tests'; + + //from a different catalogue + $this->assertEqual($formatter->format('Hello'), 'Howdy!'); + $this->assertEqual($formatter->format('Welcome'), 'Ho Ho!'); + $this->assertEqual($formatter->format('Goodbye'), 'Sayonara'); + + //switch to 'messages' catalogue + $this->assertEqual($formatter->format('Hello',null,'messages'),'G\'day Mate!'); + + $source->getCache()->clear(); + } + + function testDirectoryTypeSaveUpdateDelete() + { + $MObackup = $this->dir.'/messages/en_AU/tests.mo.bak'; + $MOfile = $this->dir.'/messages/en_AU/tests.mo'; + $PObackup = $this->dir.'/messages/en_AU/tests.po.bak'; + $POfile = $this->dir.'/messages/en_AU/tests.po'; + + //restore using the back file + copy($MObackup,$MOfile); + copy($PObackup,$POfile); + + //test that the back file doesn't contain the 'Testing123' string. + $this->assertNoUnwantedPattern('/Testing123/',file_get_contents($MOfile)); + $this->assertNoUnwantedPattern('/Testing123/',file_get_contents($POfile)); + + $source = MessageSource::factory($this->type, $this->source); + $source->setCulture('en_AU'); + $source->setCache(new MessageCache($this->tmp)); + + $formatter = new MessageFormat($source); + + //add a untranslated string, note, doesn't matter which catalogue + $this->assertEqual($formatter->format('Testing123'), 'Testing123'); + + //save it to the 'tests' catalgoue + $this->assertTrue($formatter->getSource()->save('tests')); + + //check the contents + //$this->assertWantedPattern('/Testing123/',file_get_contents($MOfile)); + $this->assertWantedPattern('/Testing123/',file_get_contents($POfile)); + + //testing for update. Update it to the 'tests' catalogue + $this->assertTrue($formatter->getSource()->update( + 'Testing123', '123Test', 'update comments','tests')); + + $this->assertWantedPattern('/123Test/',file_get_contents($MOfile)); + + //now doing some delete from the 'tests' catalogue + $this->assertFalse($formatter->getSource()->delete('Test123','tests')); + $this->assertTrue($formatter->getSource()->delete('Testing123','tests')); + + $this->assertNoUnwantedPattern('/Testing123/',file_get_contents($MOfile)); + $this->assertNoUnwantedPattern('/Testing123/',file_get_contents($POfile)); + + //restore using the backup file. + copy($MObackup,$MOfile); + copy($PObackup,$POfile); + + $source->getCache()->clear(); + } +} + +?> \ No newline at end of file diff --git a/tests/UnitTests/framework/I18N/testNumberFormat.php b/tests/UnitTests/framework/I18N/testNumberFormat.php new file mode 100644 index 00000000..48342d9c --- /dev/null +++ b/tests/UnitTests/framework/I18N/testNumberFormat.php @@ -0,0 +1,113 @@ +UnitTestCase(); + } + + function testDefaultFormats() + { + $formatter = new NumberFormat(); + $number = '123456789.125156'; + $wanted = '123,456,789.125156'; + $this->assertEqual($wanted, $formatter->format($number)); + + //currency + $wanted = 'US$123,456,789.13'; + $this->assertEqual($wanted, $formatter->format($number,'c')); + } + + function testLocalizedCurrencyFormats() + { + $fr = new NumberFormat('fr'); + $de = new NumberFormat('de'); + $ja = new NumberFormat('ja_JP'); + + $number = '123456789.125156'; + + //french + $wanted = '123 456 789,13 F'; + $this->assertEqual($wanted, $fr->format($number,'c','FRF')); + + //german + $wanted = 'DES 123.456.789,13'; + $this->assertEqual($wanted, $de->format($number,'c','DES')); + + //japanese + $wanted = '¥123,456,789'; + $this->assertEqual($wanted, $ja->format($number,'c','JPY')); + + //custom/unkown currency + $wanted = 'DLL123,456,789'; + $this->assertEqual($wanted, $ja->format($number,'c','DLL')); + } + + function testCustomFormat() + { + $formatter = new NumberFormat(); + $number = '123456789.125156'; + + //primay and secondary grouping test + $pattern = '#,###,##.###'; + $wanted = '1,234,567,89.125156'; + $this->assertEqual($wanted, $formatter->format($number, $pattern)); + + //4 digits grouping test + $pattern = '#,####.###'; + $wanted = '1,2345,6789.125156'; + $this->assertEqual($wanted, $formatter->format($number, $pattern)); + + //custom percentage + $pattern = '#,###.00%'; + $wanted = '123,456,789.13%'; + $this->assertEqual($wanted, $formatter->format($number, $pattern)); + } + + function testPercentageFormat() + { + $formatter = new NumberFormat(); + $number = '0.125156'; + $wanted = '12%'; + $this->assertEqual($wanted, $formatter->format($number, 'p')); + } + + function testQuotes() + { + $formatter = new NumberFormat(); + $number = '123456789.125156'; + + $pattern = "# o'clock"; + $wanted = "123456789 o'clock"; + $this->assertEqual($wanted, $formatter->format($number, $pattern)); + + } + + function testPadding() + { + $formatter = new NumberFormat(); + $number = '5'; + + $pattern = '0000'; + $wanted = '0005'; + + //this should fail!!! + $this->assertEqual($wanted, $formatter->format($number, $pattern)); + } + + function testNegativeValue() + { + $formatter = new NumberFormat(); + $number = "-1.2"; + + $wanted = "-1.2"; + $this->assertEqual($wanted, $formatter->format($number)); + } +} + +?> \ No newline at end of file diff --git a/tests/UnitTests/framework/I18N/testNumberFormatInfo.php b/tests/UnitTests/framework/I18N/testNumberFormatInfo.php new file mode 100644 index 00000000..0b0a3140 --- /dev/null +++ b/tests/UnitTests/framework/I18N/testNumberFormatInfo.php @@ -0,0 +1,105 @@ +UnitTestCase(); + } + + function testCurrencyPatterns() + { + $numberInfo = NumberFormatInfo::getCurrencyInstance(); + + //there should be 2 decimal places. + $this->assertEqual($numberInfo->DecimalDigits,2); + + $this->assertEqual($numberInfo->DecimalSeparator,'.'); + + $this->assertEqual($numberInfo->GroupSeparator,','); + + //there should be only 1 grouping of size 3 + $groupsize = array(3,false); + $this->assertEqual($numberInfo->GroupSizes, $groupsize); + + //the default negative pattern prefix and postfix + $negPattern = array('-¤',''); + $this->assertEqual($numberInfo->NegativePattern, $negPattern); + + //the default positive pattern prefix and postfix + $negPattern = array('¤',''); + $this->assertEqual($numberInfo->PositivePattern, $negPattern); + + //the default currency symbol + $this->assertEqual($numberInfo->CurrencySymbol, 'US$'); + + $this->assertEqual($numberInfo->getCurrencySymbol('JPY'), '¥'); + + $this->assertEqual($numberInfo->NegativeInfinitySymbol, '-∞'); + + $this->assertEqual($numberInfo->PositiveInfinitySymbol, '+∞'); + + $this->assertEqual($numberInfo->NegativeSign, '-'); + + $this->assertEqual($numberInfo->PositiveSign, '+'); + + $this->assertEqual($numberInfo->NaNSymbol, '�'); + + $this->assertEqual($numberInfo->PercentSymbol, '%'); + + $this->assertEqual($numberInfo->PerMilleSymbol, '‰'); + + } + + function testPatternsSet() + { + $numberInfo = NumberFormatInfo::getInstance(); + + $numberInfo->DecimalDigits = 0; + $this->assertEqual($numberInfo->DecimalDigits,0); + + $numberInfo->DecimalSeparator = ','; + $this->assertEqual($numberInfo->DecimalSeparator,','); + + $numberInfo->GroupSeparator = ' '; + $this->assertEqual($numberInfo->GroupSeparator,' '); + + $numberInfo->GroupSizes = array(2,3); + $groupsize = array(2,3); + $this->assertEqual($numberInfo->GroupSizes, $groupsize); + + $numberInfo->NegativePattern = array('-$$','.'); + $negPattern = array('-$$','.'); + $this->assertEqual($numberInfo->NegativePattern, $negPattern); + + $numberInfo->PositivePattern = array('YY','.'); + $negPattern = array('YY','.'); + $this->assertEqual($numberInfo->PositivePattern, $negPattern); + + //the default CurrencySymbol symbol + $numberInfo->CurrencySymbol = '$$$'; + $this->assertEqual($numberInfo->CurrencySymbol, '$$$'); + } + + function testLocalizedPatterns() + { + $fr = NumberFormatInfo::getInstance('fr'); + $de = NumberFormatInfo::getInstance('de'); + $en = NumberFormatInfo::getInstance('en_US'); + + $this->assertEqual($fr->DecimalSeparator, ','); + $this->assertEqual($de->DecimalSeparator, ','); + $this->assertEqual($en->DecimalSeparator, '.'); + + $this->assertEqual($fr->GroupSeparator, ' '); + $this->assertEqual($de->GroupSeparator, '.'); + $this->assertEqual($en->GroupSeparator, ','); + } + +} + +?> \ No newline at end of file diff --git a/tests/UnitTests/framework/I18N/tmp/cache.txt b/tests/UnitTests/framework/I18N/tmp/cache.txt new file mode 100644 index 00000000..e69de29b diff --git a/tests/UnitTests/framework/index.php b/tests/UnitTests/framework/index.php index 54706599..33c953f8 100644 --- a/tests/UnitTests/framework/index.php +++ b/tests/UnitTests/framework/index.php @@ -21,7 +21,8 @@ class TestFolder if(!empty($folder->subFolders) || !empty($folder->testFiles)) $this->subFolders[]=$folder; } - else if(is_file($fullpath) && strncmp($entry,'ut',2)===0) + else if(is_file($fullpath) && (strncmp($entry,'ut',2)===0 + || preg_match('/test.*\.php/', strtolower($entry)))) { $this->testFiles[$entry]="$rootUri/index.php?target=".strtr(substr($fullpath,strlen($rootPath)+1),"\\",'/'); } @@ -46,7 +47,7 @@ function addTests($test,$path,$recursive) $dir=opendir($path); while(($entry=readdir($dir))!==false) { - if(is_file($path.'/'.$entry) && strncmp($entry,'ut',2)===0) + if(is_file($path.'/'.$entry) && (strncmp($entry,'ut',2)===0||preg_match('/test.*\.php/', strtolower($entry)))) $test->addTestFile($path.'/'.$entry); else if($entry!=='.' && $entry!=='..' && $entry!=='.svn' && is_dir($path.'/'.$entry) && $recursive) addTests($test,$path.'/'.$entry,$recursive); -- cgit v1.2.3