Skip to content

Commit cf1a848

Browse files
committed
Implement incomplete tests for I18n\Date.
1 parent 2ea2cf3 commit cf1a848

File tree

1 file changed

+51
-4
lines changed

1 file changed

+51
-4
lines changed

tests/TestCase/I18n/DateTest.php

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
use Cake\I18n\Date;
1818
use Cake\TestSuite\TestCase;
19+
use DateTimeZone;
1920

2021
/**
2122
* DateTest class
@@ -86,23 +87,69 @@ public function testI18nFormat()
8687
$this->assertEquals($expected, $result, 'Default locale should not be used');
8788
}
8889

90+
/**
91+
* test __toString
92+
*
93+
* @return void
94+
*/
8995
public function testToString()
9096
{
91-
$this->markTestIncomplete();
97+
$date = new Date('2015-11-06 11:32:45');
98+
$this->assertEquals('11/6/15', (string)$date);
99+
}
100+
101+
/**
102+
* test nice()
103+
*
104+
* @return void
105+
*/
106+
public function testNice()
107+
{
108+
$date = new Date('2015-11-06 11:32:45');
109+
110+
$this->assertEquals('Nov 6, 2015', $date->nice());
111+
$this->assertEquals('Nov 6, 2015', $date->nice(new DateTimeZone('America/New_York')));
112+
$this->assertEquals('6 nov. 2015', $date->nice(null, 'fr-FR'));
92113
}
93114

115+
/**
116+
* test jsonSerialize()
117+
*
118+
* @return void
119+
*/
94120
public function testJsonSerialize()
95121
{
96-
$this->markTestIncomplete();
122+
$date = new Date('2015-11-06 11:32:45');
123+
$this->assertEquals('"2015-11-06T00:00:00+0000"', json_encode($date));
97124
}
98125

126+
/**
127+
* test parseDate()
128+
*
129+
* @return void
130+
*/
99131
public function testParseDate()
100132
{
101-
$this->markTestIncomplete();
133+
$date = Date::parseDate('11/6/15');
134+
$this->assertEquals('2015-11-06 00:00:00', $date->format('Y-m-d H:i:s'));
135+
136+
Date::$defaultLocale = 'fr-FR';
137+
$date = Date::parseDate('13 10, 2015');
138+
$this->assertEquals('2015-10-13 00:00:00', $date->format('Y-m-d H:i:s'));
102139
}
103140

141+
/**
142+
* test parseDateTime()
143+
*
144+
* @return void
145+
*/
104146
public function testParseDateTime()
105147
{
106-
$this->markTestIncomplete();
148+
$date = Date::parseDate('11/6/15 12:33:12');
149+
$this->assertEquals('2015-11-06 00:00:00', $date->format('Y-m-d H:i:s'));
150+
151+
Date::$defaultLocale = 'fr-FR';
152+
$date = Date::parseDate('13 10, 2015 12:54:12');
153+
$this->assertEquals('2015-10-13 00:00:00', $date->format('Y-m-d H:i:s'));
107154
}
108155
}

0 commit comments

Comments
 (0)