|
16 | 16 |
|
17 | 17 | use Cake\I18n\Date;
|
18 | 18 | use Cake\TestSuite\TestCase;
|
| 19 | +use DateTimeZone; |
19 | 20 |
|
20 | 21 | /**
|
21 | 22 | * DateTest class
|
@@ -86,23 +87,69 @@ public function testI18nFormat()
|
86 | 87 | $this->assertEquals($expected, $result, 'Default locale should not be used');
|
87 | 88 | }
|
88 | 89 |
|
| 90 | + /** |
| 91 | + * test __toString |
| 92 | + * |
| 93 | + * @return void |
| 94 | + */ |
89 | 95 | public function testToString()
|
90 | 96 | {
|
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')); |
92 | 113 | }
|
93 | 114 |
|
| 115 | + /** |
| 116 | + * test jsonSerialize() |
| 117 | + * |
| 118 | + * @return void |
| 119 | + */ |
94 | 120 | public function testJsonSerialize()
|
95 | 121 | {
|
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)); |
97 | 124 | }
|
98 | 125 |
|
| 126 | + /** |
| 127 | + * test parseDate() |
| 128 | + * |
| 129 | + * @return void |
| 130 | + */ |
99 | 131 | public function testParseDate()
|
100 | 132 | {
|
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')); |
102 | 139 | }
|
103 | 140 |
|
| 141 | + /** |
| 142 | + * test parseDateTime() |
| 143 | + * |
| 144 | + * @return void |
| 145 | + */ |
104 | 146 | public function testParseDateTime()
|
105 | 147 | {
|
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')); |
107 | 154 | }
|
108 | 155 | }
|
0 commit comments