2 namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format;
13 use TYPO3\CMS\Core\Tests\UnitTestCase;
37 protected function setUp()
41 $this->backupLocales = array(
42 'LC_COLLATE' => setlocale(LC_COLLATE, 0),
43 'LC_CTYPE' => setlocale(LC_CTYPE, 0),
44 'LC_MONETARY' => setlocale(LC_MONETARY, 0),
45 'LC_TIME' => setlocale(LC_TIME, 0),
47 $this->timezone = @date_default_timezone_get();
48 $GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'ddmmyy'] =
'Y-m-d';
49 $this->subject = $this->getAccessibleMock(DateViewHelper::class, array(
'renderChildren'));
51 $renderingContext = $this->getMock(RenderingContext::class);
52 $this->subject->_set(
'renderingContext', $renderingContext);
57 foreach ($this->backupLocales as $category => $locale) {
58 setlocale(constant($category), $locale);
60 date_default_timezone_set($this->timezone);
69 $actualResult = $this->subject->render(
new \DateTime(
'1980-12-13'));
70 $this->assertEquals(
'1980-12-13', $actualResult);
78 $actualResult = $this->subject->render(
'1980-12-13');
79 $this->assertEquals(
'1980-12-13', $actualResult);
87 $actualResult = $this->subject->render(
new \DateTime(
'1980-02-01'),
'd.m.Y');
88 $this->assertEquals(
'01.02.1980', $actualResult);
96 $this->subject->expects($this->once())->method(
'renderChildren')->will($this->returnValue(null));
97 $actualResult = $this->subject->render();
98 $this->assertEquals(
'', $actualResult);
106 $actualResult = $this->subject->render(
'');
107 $expectedResult = (new \DateTime())->format(
'Y-m-d');
108 $this->assertEquals($expectedResult, $actualResult);
116 $this->subject->expects($this->once())->method(
'renderChildren')->will($this->returnValue(
''));
117 $actualResult = $this->subject->render();
118 $expectedResult = (new \DateTime())->format(
'Y-m-d');
119 $this->assertEquals($expectedResult, $actualResult);
127 $GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'ddmmyy'] =
'';
128 $actualResult = $this->subject->render(
'@1391876733');
129 $this->assertEquals(
'2014-02-08', $actualResult);
137 $GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'ddmmyy'] =
'l, j. M y';
138 $actualResult = $this->subject->render(
'@1391876733');
139 $this->assertEquals(
'Saturday, 8. Feb 14', $actualResult);
149 $this->subject->render(
'foo');
157 $this->subject->expects($this->once())->method(
'renderChildren')->will($this->returnValue(
new \DateTime(
'1980-12-13')));
158 $actualResult = $this->subject->render();
159 $this->assertEquals(
'1980-12-13', $actualResult);
167 $this->subject->expects($this->once())->method(
'renderChildren')->will($this->returnValue(
'1359891658'));
168 $actualResult = $this->subject->render();
169 $this->assertEquals(
'2013-02-03', $actualResult);
177 $this->subject->expects($this->never())->method(
'renderChildren');
178 $actualResult = $this->subject->render(
'1980-12-12');
179 $this->assertEquals(
'1980-12-12', $actualResult);
187 $this->subject->expects($this->never())->method(
'renderChildren');
188 $actualResult = $this->subject->render(
'now',
'Y');
189 $this->assertEquals(date(
'Y'), $actualResult);
197 $this->subject->expects($this->never())->method(
'renderChildren');
198 $actualResult = $this->subject->render(
'-1 year',
'Y',
'2017-01-01');
199 $this->assertEquals(
'2016', $actualResult);
207 $this->subject->expects($this->never())->method(
'renderChildren');
208 $actualResult = $this->subject->render(
'-1 year',
'Y',
new \DateTime(
'2017-01-01'));
209 $this->assertEquals(
'2016', $actualResult);
217 $this->subject->expects($this->never())->method(
'renderChildren');
218 $actualResult = $this->subject->render(
'@1435784732',
'Y', 1485907200);
219 $this->assertEquals(
'2015', $actualResult);
230 'Europe/Berlin' => array(
234 'Asia/Riyadh' => array(
248 $format =
'Y-m-d H:i';
251 $this->assertEquals($expected, $this->subject->render($date, $format));
262 'Europe/Berlin UTC' => array(
267 'Europe/Berlin Moscow' => array(
269 '03/Oct/2000:14:55:36 +0400',
272 'Asia/Riyadh UTC' => array(
277 'Asia/Riyadh Moscow' => array(
279 '03/Oct/2000:14:55:36 +0400',
292 $format =
'Y-m-d H:i';
294 date_default_timezone_set($timeZone);
295 $this->assertEquals($expected, $this->subject->render($date, $format));
306 'de_DE.UTF-8' => array(
310 'en_ZW.utf8' => array(
324 $format =
'%d. %B %Y';
326 $timestamp =
'@1359891658';
328 if (!setlocale(LC_COLLATE, $locale)) {
329 $this->markTestSkipped(
'Locale ' . $locale .
' is not available.');
332 $this->assertEquals($expected, $this->subject->render($timestamp, $format));
340 setlocale(LC_CTYPE, $locale);
341 setlocale(LC_MONETARY, $locale);
342 setlocale(LC_TIME, $locale);