From 926465223486b1c705b8414a203c0a72abef760f Mon Sep 17 00:00:00 2001 From: knut <> Date: Thu, 2 Feb 2006 22:40:22 +0000 Subject: ported two more unit tests --- tests/unit/I18N/core/DateFormatTest.php | 95 +++++++++++ tests/unit/I18N/core/DateTimeFormatInfoTest.php | 207 ++++++++++++++++++++++++ 2 files changed, 302 insertions(+) create mode 100644 tests/unit/I18N/core/DateFormatTest.php create mode 100644 tests/unit/I18N/core/DateTimeFormatInfoTest.php (limited to 'tests/unit/I18N') diff --git a/tests/unit/I18N/core/DateFormatTest.php b/tests/unit/I18N/core/DateFormatTest.php new file mode 100644 index 00000000..3f5c9449 --- /dev/null +++ b/tests/unit/I18N/core/DateFormatTest.php @@ -0,0 +1,95 @@ +assertEquals('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->assertEquals($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->assertEquals($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->assertEquals($wants, $dateFormatter->format($time, 'F')); + + //for General "M/d/yy h:mm a" + $wants = '9/1/04 9:09 AM'; + $this->assertEquals($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->assertEquals($wants, $dateFormatter->format($time, 'G')); + + //for MonthDayPattern "MMMM dd" (invariant) + $wants = 'September 01'; + $this->assertEquals($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->assertEquals($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->assertEquals($wants, $dateFormatter->format($time, 's')); + //var_dump(date('c',strtotime($dateFormatter->format($time,'s')))); + + //for ShortTimePattern "H:mm a" + $wants = '9:09 AM'; + $this->assertEquals($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->assertEquals($wants, $dateFormatter->format($time, 'T')); + + //for UniversalSortableDateTimePattern "yyyy-MM-dd HH:mm:ss z" + //(invariant) + $wants = '2004-09-01 09:09:09 '.$zone; + $this->assertEquals($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->assertEquals($wants, $dateFormatter->format($time, 'U')); + //var_dump(date('c',strtotime($dateFormatter->format($time,'U')))); + + //for YearMonthPattern "yyyy MMMM" (invariant) + $wants = '2004 September'; + $this->assertEquals($wants, $dateFormatter->format($time, 'y')); + //var_dump(date('c',strtotime($dateFormatter->format($time,'y')))); + } + + public 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->assertEquals($wants, $dateFormatter->format($time, $pattern)); + } +} + +?> \ No newline at end of file diff --git a/tests/unit/I18N/core/DateTimeFormatInfoTest.php b/tests/unit/I18N/core/DateTimeFormatInfoTest.php new file mode 100644 index 00000000..dcef6ba1 --- /dev/null +++ b/tests/unit/I18N/core/DateTimeFormatInfoTest.php @@ -0,0 +1,207 @@ +format = DateTimeFormatInfo::getInstance('en'); + } + + function testAbbreviatedDayNames() { + $names = $this->format->AbbreviatedDayNames; + $this->assertTrue(is_array($names),'Must be an array!'); + $this->assertEquals(count($names),7,'Must have 7 day names'); + + //assuming invariant culture. + $days = array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"); + $this->assertEquals($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->assertEquals(count($newNames),2,'Must have 2 entries'); + $this->assertEquals($newNames, $data); + } + + function testNarrowDayNames() { + $names = $this->format->NarrowDayNames; + $this->assertTrue(is_array($names),'Must be an array!'); + $this->assertEquals(count($names),7,'Must have 7 day names'); + + //assuming invariant culture. + $days = array("S", "M", "T", "W", "T", "F", "S"); + $this->assertEquals($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->assertEquals(count($newNames),2,'Must have 2 entries'); + $this->assertEquals($newNames, $data); + } + + function testDayNames() { + $names = $this->format->DayNames; + $this->assertTrue(is_array($names),'Must be an array!'); + $this->assertEquals(count($names),7,'Must have 7 day names'); + + //assuming invariant culture. + $days = array( "Sunday","Monday", "Tuesday", "Wednesday", + "Thursday", "Friday", "Saturday"); + $this->assertEquals($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->assertEquals(count($newNames),2,'Must have 2 entries'); + $this->assertEquals($newNames, $data); + } + + function testMonthNames() { + $names = $this->format->MonthNames; + $this->assertTrue(is_array($names),'Must be an array!'); + $this->assertEquals(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->assertEquals($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->assertEquals(count($newNames),2,'Must have 2 entries'); + $this->assertEquals($newNames, $data); + } + + function testNarrowMonthNames() { + $names = $this->format->NarrowMonthNames; + $this->assertTrue(is_array($names),'Must be an array!'); + $this->assertEquals(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->assertEquals($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->assertEquals(count($newNames),2,'Must have 2 entries'); + $this->assertEquals($newNames, $data); + } + + function testAbbreviatedMonthNames() { + $names = $this->format->AbbreviatedMonthNames; + $this->assertTrue(is_array($names),'Must be an array!'); + $this->assertEquals(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->assertEquals($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->assertEquals(count($newNames),2,'Must have 2 entries'); + $this->assertEquals($newNames, $data); + } + + function testEra() { + //era for invariant culture is assumed to have + // 1 for AD and 0 for BC + $this->assertEquals('AD', $this->format->getEra(1)); + $this->assertEquals('BC', $this->format->getEra(0)); + } + + function testAMPMMarkers() { + $am_pm = array('AM','PM'); + $data = $this->format->AMPMMarkers; + $this->assertTrue(is_array($data)); + $this->assertEquals($am_pm, $data); + $this->assertEquals('AM', $this->format->AMDesignator); + $this->assertEquals('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->assertEquals(count($newNames),2,'Must have 2 entries'); + $this->assertEquals($newNames, $data); + + $this->format->AMDesignator = 'TTTT'; + $this->assertEquals('TTTT',$this->format->AMDesignator); + + $this->format->PMDesignator = 'SSS'; + $this->assertEquals('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->assertEquals($pattern, $this->format->$property); + } + + $hello = 'Hello'; + $world = 'world'; + $expectedResult = $hello.' '.$world; + $this->assertEquals($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->assertEquals($pattern, $format->MediumDatePattern); + + $invariant = $format->getInvariantInfo(); + + $this->assertSame($format, $invariant); + } + + function testGetInstance() { + $format = DateTimeFormatInfo::getInstance('zh_CN'); + + $pattern = 'yyyy-M-d'; + $this->assertEquals($pattern, $format->MediumDatePattern); + } +} +?> \ No newline at end of file -- cgit v1.2.3