TimeHelperTest.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP(tm) Project
  12. * @since 1.2.0
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\View\Helper;
  16. use Cake\Core\Configure;
  17. use Cake\I18n\I18n;
  18. use Cake\I18n\Time;
  19. use Cake\TestSuite\TestCase;
  20. use Cake\View\Helper\TimeHelper;
  21. use Cake\View\View;
  22. /**
  23. * TimeHelperTest class
  24. */
  25. class TimeHelperTest extends TestCase
  26. {
  27. public $Time = null;
  28. /**
  29. * setUp method
  30. *
  31. * @return void
  32. */
  33. public function setUp()
  34. {
  35. parent::setUp();
  36. $this->View = new View();
  37. $this->Time = new TimeHelper($this->View);
  38. Time::$defaultLocale = 'en_US';
  39. $this->locale = I18n::locale();
  40. }
  41. /**
  42. * tearDown method
  43. *
  44. * @return void
  45. */
  46. public function tearDown()
  47. {
  48. parent::tearDown();
  49. Time::$defaultLocale = 'en_US';
  50. I18n::locale($this->locale);
  51. }
  52. /**
  53. * Test element wrapping in timeAgoInWords
  54. *
  55. * @return void
  56. */
  57. public function testTimeAgoInWords()
  58. {
  59. $Time = new TimeHelper($this->View);
  60. $timestamp = strtotime('+8 years, +4 months +2 weeks +3 days');
  61. $result = $Time->timeAgoInWords($timestamp, [
  62. 'end' => '1 years',
  63. 'element' => 'span'
  64. ]);
  65. $expected = [
  66. 'span' => [
  67. 'title' => $timestamp,
  68. 'class' => 'time-ago-in-words'
  69. ],
  70. 'on ' . date('n/j/y', $timestamp),
  71. '/span'
  72. ];
  73. $this->assertHtml($expected, $result);
  74. $result = $Time->timeAgoInWords($timestamp, [
  75. 'end' => '1 years',
  76. 'element' => [
  77. 'title' => 'testing',
  78. 'rel' => 'test'
  79. ]
  80. ]);
  81. $expected = [
  82. 'span' => [
  83. 'title' => 'testing',
  84. 'class' => 'time-ago-in-words',
  85. 'rel' => 'test'
  86. ],
  87. 'on ' . date('n/j/y', $timestamp),
  88. '/span'
  89. ];
  90. $this->assertHtml($expected, $result);
  91. $timestamp = strtotime('+2 weeks');
  92. $result = $Time->timeAgoInWords(
  93. $timestamp,
  94. ['end' => '1 years', 'element' => 'div']
  95. );
  96. $expected = [
  97. 'div' => [
  98. 'title' => $timestamp,
  99. 'class' => 'time-ago-in-words'
  100. ],
  101. '2 weeks',
  102. '/div'
  103. ];
  104. $this->assertHtml($expected, $result);
  105. }
  106. /**
  107. * Test output timezone with timeAgoInWords
  108. *
  109. * @return void
  110. */
  111. public function testTimeAgoInWordsOutputTimezone()
  112. {
  113. $Time = new TimeHelper($this->View, ['outputTimezone' => 'America/Vancouver']);
  114. $timestamp = new Time('+8 years, +4 months +2 weeks +3 days');
  115. $result = $Time->timeAgoInWords($timestamp, [
  116. 'end' => '1 years',
  117. 'element' => 'span'
  118. ]);
  119. $vancouver = clone $timestamp;
  120. $vancouver->timezone('America/Vancouver');
  121. $expected = [
  122. 'span' => [
  123. 'title' => $vancouver->__toString(),
  124. 'class' => 'time-ago-in-words'
  125. ],
  126. 'on ' . $vancouver->format('n/j/y'),
  127. '/span'
  128. ];
  129. $this->assertHtml($expected, $result);
  130. }
  131. /**
  132. * testToQuarter method
  133. *
  134. * @return void
  135. */
  136. public function testToQuarter()
  137. {
  138. $this->assertEquals(4, $this->Time->toQuarter('2007-12-25'));
  139. $this->assertEquals(['2007-10-01', '2007-12-31'], $this->Time->toQuarter('2007-12-25', true));
  140. }
  141. /**
  142. * testNice method
  143. *
  144. * @return void
  145. */
  146. public function testNice()
  147. {
  148. $time = '2014-04-20 20:00';
  149. $this->assertTimeFormat('Apr 20, 2014, 8:00 PM', $this->Time->nice($time));
  150. $result = $this->Time->nice($time, 'America/New_York');
  151. $this->assertTimeFormat('Apr 20, 2014, 4:00 PM', $result);
  152. }
  153. /**
  154. * test nice with outputTimezone
  155. *
  156. * @return void
  157. */
  158. public function testNiceOutputTimezone()
  159. {
  160. $this->Time->config('outputTimezone', 'America/Vancouver');
  161. $time = '2014-04-20 20:00';
  162. $this->assertTimeFormat('Apr 20, 2014, 1:00 PM', $this->Time->nice($time));
  163. }
  164. /**
  165. * testToUnix method
  166. *
  167. * @return void
  168. */
  169. public function testToUnix()
  170. {
  171. $this->assertEquals(1397980800, $this->Time->toUnix('2014-04-20 08:00:00'));
  172. }
  173. /**
  174. * testToAtom method
  175. *
  176. * @return void
  177. */
  178. public function testToAtom()
  179. {
  180. $dateTime = new \DateTime;
  181. $this->assertEquals($dateTime->format($dateTime::ATOM), $this->Time->toAtom($dateTime->getTimestamp()));
  182. }
  183. /**
  184. * testToAtom method
  185. *
  186. * @return void
  187. */
  188. public function testToAtomOutputTimezone()
  189. {
  190. $this->Time->config('outputTimezone', 'America/Vancouver');
  191. $dateTime = new Time;
  192. $vancouver = clone $dateTime;
  193. $vancouver->timezone('America/Vancouver');
  194. $this->assertEquals($vancouver->format(Time::ATOM), $this->Time->toAtom($vancouver));
  195. }
  196. /**
  197. * testToRss method
  198. *
  199. * @return void
  200. */
  201. public function testToRss()
  202. {
  203. $date = '2012-08-12 12:12:45';
  204. $time = strtotime($date);
  205. $this->assertEquals(date('r', $time), $this->Time->toRss($time));
  206. $timezones = ['Europe/London', 'Europe/Brussels', 'UTC', 'America/Denver', 'America/Caracas', 'Asia/Kathmandu'];
  207. foreach ($timezones as $timezone) {
  208. $yourTimezone = new \DateTimeZone($timezone);
  209. $yourTime = new \DateTime($date, $yourTimezone);
  210. $time = $yourTime->format('U');
  211. $this->assertEquals($yourTime->format('r'), $this->Time->toRss($time, $timezone), "Failed on $timezone");
  212. }
  213. }
  214. /**
  215. * test toRss with outputTimezone
  216. *
  217. * @return void
  218. */
  219. public function testToRssOutputTimezone()
  220. {
  221. $this->Time->config('outputTimezone', 'America/Vancouver');
  222. $dateTime = new Time;
  223. $vancouver = clone $dateTime;
  224. $vancouver->timezone('America/Vancouver');
  225. $this->assertEquals($vancouver->format('r'), $this->Time->toRss($vancouver));
  226. }
  227. /**
  228. * testOfGmt method
  229. *
  230. * @return void
  231. */
  232. public function testGmt()
  233. {
  234. $this->assertEquals(1397980800, $this->Time->gmt('2014-04-20 08:00:00'));
  235. }
  236. /**
  237. * testIsToday method
  238. *
  239. * @return void
  240. */
  241. public function testIsToday()
  242. {
  243. $result = $this->Time->isToday('+1 day');
  244. $this->assertFalse($result);
  245. $result = $this->Time->isToday('+1 days');
  246. $this->assertFalse($result);
  247. $result = $this->Time->isToday('+0 day');
  248. $this->assertTrue($result);
  249. $result = $this->Time->isToday('-1 day');
  250. $this->assertFalse($result);
  251. }
  252. /**
  253. * testIsFuture method
  254. *
  255. * @return void
  256. */
  257. public function testIsFuture()
  258. {
  259. $this->assertTrue($this->Time->isFuture('+1 month'));
  260. $this->assertTrue($this->Time->isFuture('+1 days'));
  261. $this->assertTrue($this->Time->isFuture('+1 minute'));
  262. $this->assertTrue($this->Time->isFuture('+1 second'));
  263. $this->assertFalse($this->Time->isFuture('-1 second'));
  264. $this->assertFalse($this->Time->isFuture('-1 day'));
  265. $this->assertFalse($this->Time->isFuture('-1 week'));
  266. $this->assertFalse($this->Time->isFuture('-1 month'));
  267. }
  268. /**
  269. * testIsPast method
  270. *
  271. * @return void
  272. */
  273. public function testIsPast()
  274. {
  275. $this->assertFalse($this->Time->isPast('+1 month'));
  276. $this->assertFalse($this->Time->isPast('+1 days'));
  277. $this->assertFalse($this->Time->isPast('+1 minute'));
  278. $this->assertFalse($this->Time->isPast('+1 second'));
  279. $this->assertTrue($this->Time->isPast('-1 second'));
  280. $this->assertTrue($this->Time->isPast('-1 day'));
  281. $this->assertTrue($this->Time->isPast('-1 week'));
  282. $this->assertTrue($this->Time->isPast('-1 month'));
  283. }
  284. /**
  285. * testIsThisWeek method
  286. *
  287. * @return void
  288. */
  289. public function testIsThisWeek()
  290. {
  291. // A map of days which goes from -1 day of week to +1 day of week
  292. $map = [
  293. 'Mon' => [-1, 7], 'Tue' => [-2, 6], 'Wed' => [-3, 5],
  294. 'Thu' => [-4, 4], 'Fri' => [-5, 3], 'Sat' => [-6, 2],
  295. 'Sun' => [-7, 1]
  296. ];
  297. $days = $map[date('D')];
  298. for ($day = $days[0] + 1; $day < $days[1]; $day++) {
  299. $this->assertTrue($this->Time->isThisWeek(($day > 0 ? '+' : '') . $day . ' days'));
  300. }
  301. $this->assertFalse($this->Time->isThisWeek($days[0] . ' days'));
  302. $this->assertFalse($this->Time->isThisWeek('+' . $days[1] . ' days'));
  303. }
  304. /**
  305. * testIsThisMonth method
  306. *
  307. * @return void
  308. */
  309. public function testIsThisMonth()
  310. {
  311. $result = $this->Time->isThisMonth('+0 day');
  312. $this->assertTrue($result);
  313. $result = $this->Time->isThisMonth($time = mktime(0, 0, 0, date('m'), mt_rand(1, 28), date('Y')));
  314. $this->assertTrue($result);
  315. $result = $this->Time->isThisMonth(mktime(0, 0, 0, date('m'), mt_rand(1, 28), date('Y') - mt_rand(1, 12)));
  316. $this->assertFalse($result);
  317. $result = $this->Time->isThisMonth(mktime(0, 0, 0, date('m'), mt_rand(1, 28), date('Y') + mt_rand(1, 12)));
  318. $this->assertFalse($result);
  319. }
  320. /**
  321. * testIsThisYear method
  322. *
  323. * @return void
  324. */
  325. public function testIsThisYear()
  326. {
  327. $result = $this->Time->isThisYear('+0 day');
  328. $this->assertTrue($result);
  329. $result = $this->Time->isThisYear(mktime(0, 0, 0, mt_rand(1, 12), mt_rand(1, 28), date('Y')));
  330. $this->assertTrue($result);
  331. }
  332. /**
  333. * testWasYesterday method
  334. *
  335. * @return void
  336. */
  337. public function testWasYesterday()
  338. {
  339. $result = $this->Time->wasYesterday('+1 day');
  340. $this->assertFalse($result);
  341. $result = $this->Time->wasYesterday('+1 days');
  342. $this->assertFalse($result);
  343. $result = $this->Time->wasYesterday('+0 day');
  344. $this->assertFalse($result);
  345. $result = $this->Time->wasYesterday('-1 day');
  346. $this->assertTrue($result);
  347. $result = $this->Time->wasYesterday('-1 days');
  348. $this->assertTrue($result);
  349. $result = $this->Time->wasYesterday('-2 days');
  350. $this->assertFalse($result);
  351. }
  352. /**
  353. * testIsTomorrow method
  354. *
  355. * @return void
  356. */
  357. public function testIsTomorrow()
  358. {
  359. $result = $this->Time->isTomorrow('+1 day');
  360. $this->assertTrue($result);
  361. $result = $this->Time->isTomorrow('+1 days');
  362. $this->assertTrue($result);
  363. $result = $this->Time->isTomorrow('+0 day');
  364. $this->assertFalse($result);
  365. $result = $this->Time->isTomorrow('-1 day');
  366. $this->assertFalse($result);
  367. }
  368. /**
  369. * testWasWithinLast method
  370. *
  371. * @return void
  372. */
  373. public function testWasWithinLast()
  374. {
  375. $this->assertTrue($this->Time->wasWithinLast('1 day', '-1 day'));
  376. $this->assertTrue($this->Time->wasWithinLast('1 week', '-1 week'));
  377. $this->assertTrue($this->Time->wasWithinLast('1 year', '-1 year'));
  378. $this->assertTrue($this->Time->wasWithinLast('1 second', '-1 second'));
  379. $this->assertTrue($this->Time->wasWithinLast('1 minute', '-1 minute'));
  380. $this->assertTrue($this->Time->wasWithinLast('1 year', '-1 year'));
  381. $this->assertTrue($this->Time->wasWithinLast('1 month', '-1 month'));
  382. $this->assertTrue($this->Time->wasWithinLast('1 day', '-1 day'));
  383. $this->assertTrue($this->Time->wasWithinLast('1 week', '-1 day'));
  384. $this->assertTrue($this->Time->wasWithinLast('2 week', '-1 week'));
  385. $this->assertFalse($this->Time->wasWithinLast('1 second', '-1 year'));
  386. $this->assertTrue($this->Time->wasWithinLast('10 minutes', '-1 second'));
  387. $this->assertTrue($this->Time->wasWithinLast('23 minutes', '-1 minute'));
  388. $this->assertFalse($this->Time->wasWithinLast('0 year', '-1 year'));
  389. $this->assertTrue($this->Time->wasWithinLast('13 month', '-1 month'));
  390. $this->assertTrue($this->Time->wasWithinLast('2 days', '-1 day'));
  391. $this->assertFalse($this->Time->wasWithinLast('1 week', '-2 weeks'));
  392. $this->assertFalse($this->Time->wasWithinLast('1 second', '-2 seconds'));
  393. $this->assertFalse($this->Time->wasWithinLast('1 day', '-2 days'));
  394. $this->assertFalse($this->Time->wasWithinLast('1 hour', '-2 hours'));
  395. $this->assertFalse($this->Time->wasWithinLast('1 month', '-2 months'));
  396. $this->assertFalse($this->Time->wasWithinLast('1 year', '-2 years'));
  397. $this->assertFalse($this->Time->wasWithinLast('1 day', '-2 weeks'));
  398. $this->assertFalse($this->Time->wasWithinLast('1 day', '-2 days'));
  399. $this->assertFalse($this->Time->wasWithinLast('0 days', '-2 days'));
  400. $this->assertTrue($this->Time->wasWithinLast('1 hour', '-20 seconds'));
  401. $this->assertTrue($this->Time->wasWithinLast('1 year', '-60 minutes -30 seconds'));
  402. $this->assertTrue($this->Time->wasWithinLast('3 years', '-2 months'));
  403. $this->assertTrue($this->Time->wasWithinLast('5 months', '-4 months'));
  404. $this->assertTrue($this->Time->wasWithinLast('5 ', '-3 days'));
  405. $this->assertTrue($this->Time->wasWithinLast('1 ', '-1 hour'));
  406. $this->assertTrue($this->Time->wasWithinLast('1 ', '-1 minute'));
  407. $this->assertTrue($this->Time->wasWithinLast('1 ', '-23 hours -59 minutes -59 seconds'));
  408. }
  409. /**
  410. * testWasWithinLast method
  411. *
  412. * @return void
  413. */
  414. public function testIsWithinNext()
  415. {
  416. $this->assertFalse($this->Time->isWithinNext('1 day', '-1 day'));
  417. $this->assertFalse($this->Time->isWithinNext('1 week', '-1 week'));
  418. $this->assertFalse($this->Time->isWithinNext('1 year', '-1 year'));
  419. $this->assertFalse($this->Time->isWithinNext('1 second', '-1 second'));
  420. $this->assertFalse($this->Time->isWithinNext('1 minute', '-1 minute'));
  421. $this->assertFalse($this->Time->isWithinNext('1 year', '-1 year'));
  422. $this->assertFalse($this->Time->isWithinNext('1 month', '-1 month'));
  423. $this->assertFalse($this->Time->isWithinNext('1 day', '-1 day'));
  424. $this->assertFalse($this->Time->isWithinNext('1 week', '-1 day'));
  425. $this->assertFalse($this->Time->isWithinNext('2 week', '-1 week'));
  426. $this->assertFalse($this->Time->isWithinNext('1 second', '-1 year'));
  427. $this->assertFalse($this->Time->isWithinNext('10 minutes', '-1 second'));
  428. $this->assertFalse($this->Time->isWithinNext('23 minutes', '-1 minute'));
  429. $this->assertFalse($this->Time->isWithinNext('0 year', '-1 year'));
  430. $this->assertFalse($this->Time->isWithinNext('13 month', '-1 month'));
  431. $this->assertFalse($this->Time->isWithinNext('2 days', '-1 day'));
  432. $this->assertFalse($this->Time->isWithinNext('1 week', '-2 weeks'));
  433. $this->assertFalse($this->Time->isWithinNext('1 second', '-2 seconds'));
  434. $this->assertFalse($this->Time->isWithinNext('1 day', '-2 days'));
  435. $this->assertFalse($this->Time->isWithinNext('1 hour', '-2 hours'));
  436. $this->assertFalse($this->Time->isWithinNext('1 month', '-2 months'));
  437. $this->assertFalse($this->Time->isWithinNext('1 year', '-2 years'));
  438. $this->assertFalse($this->Time->isWithinNext('1 day', '-2 weeks'));
  439. $this->assertFalse($this->Time->isWithinNext('1 day', '-2 days'));
  440. $this->assertFalse($this->Time->isWithinNext('0 days', '-2 days'));
  441. $this->assertFalse($this->Time->isWithinNext('1 hour', '-20 seconds'));
  442. $this->assertFalse($this->Time->isWithinNext('1 year', '-60 minutes -30 seconds'));
  443. $this->assertFalse($this->Time->isWithinNext('3 years', '-2 months'));
  444. $this->assertFalse($this->Time->isWithinNext('5 months', '-4 months'));
  445. $this->assertTrue($this->Time->isWithinNext('1 day', '+1 day'));
  446. $this->assertTrue($this->Time->isWithinNext('7 day', '+1 week'));
  447. $this->assertTrue($this->Time->isWithinNext('1 minute', '+1 second'));
  448. $this->assertTrue($this->Time->isWithinNext('1 month', '+1 month'));
  449. }
  450. /**
  451. * test formatting dates taking in account preferred i18n locale file
  452. *
  453. * @return void
  454. */
  455. public function testFormat()
  456. {
  457. $time = strtotime('Thu Jan 14 13:59:28 2010');
  458. $result = $this->Time->format($time);
  459. $expected = '1/14/10, 1:59 PM';
  460. $this->assertTimeFormat($expected, $result);
  461. $result = $this->Time->format($time, \IntlDateFormatter::FULL);
  462. $expected = 'Thursday, January 14, 2010 at 1:59:28 PM GMT';
  463. $this->assertTimeFormat($expected, $result);
  464. $result = $this->Time->format('invalid date', null, 'Date invalid');
  465. $expected = 'Date invalid';
  466. $this->assertEquals($expected, $result);
  467. I18n::locale('fr_FR');
  468. Time::$defaultLocale = 'fr_FR';
  469. $time = new \Cake\I18n\FrozenTime('Thu Jan 14 13:59:28 2010');
  470. $result = $this->Time->format($time, \IntlDateFormatter::FULL);
  471. $expected = 'jeudi 14 janvier 2010 13:59:28 UTC';
  472. $this->assertTimeFormat($expected, $result);
  473. }
  474. /**
  475. * test format with outputTimezone
  476. *
  477. * @return void
  478. */
  479. public function testFormatOutputTimezone()
  480. {
  481. $this->Time->config('outputTimezone', 'America/Vancouver');
  482. $time = strtotime('Thu Jan 14 8:59:28 2010 UTC');
  483. $result = $this->Time->format($time);
  484. $expected = '1/14/10, 12:59 AM';
  485. $this->assertTimeFormat($expected, $result);
  486. $time = new Time('Thu Jan 14 8:59:28 2010', 'UTC');
  487. $result = $this->Time->format($time);
  488. $expected = '1/14/10, 12:59 AM';
  489. $this->assertTimeFormat($expected, $result);
  490. }
  491. /**
  492. * test i18nFormat with outputTimezone
  493. *
  494. * @return void
  495. */
  496. public function testI18nFormatOutputTimezone()
  497. {
  498. $this->Time->config('outputTimezone', 'America/Vancouver');
  499. $time = strtotime('Thu Jan 14 8:59:28 2010 UTC');
  500. $result = $this->Time->i18nFormat($time, \IntlDateFormatter::SHORT);
  501. $expected = '1/14/10, 12:59:28 AM';
  502. $this->assertStringStartsWith($expected, $result);
  503. }
  504. /**
  505. * Test format() with a string.
  506. *
  507. * @return void
  508. */
  509. public function testFormatString()
  510. {
  511. $time = '2010-01-14 13:59:28';
  512. $result = $this->Time->format($time);
  513. $this->assertTimeFormat('1/14/10 1:59 PM', $result);
  514. $result = $this->Time->format($time, 'HH:mm', null, 'America/New_York');
  515. $this->assertTimeFormat('08:59', $result);
  516. }
  517. /**
  518. * Test format() with a Time instance.
  519. *
  520. * @return void
  521. */
  522. public function testFormatTimeInstance()
  523. {
  524. $time = new Time('2010-01-14 13:59:28', 'America/New_York');
  525. $result = $this->Time->format($time, 'HH:mm', null, 'America/New_York');
  526. $this->assertTimeFormat('13:59', $result);
  527. $time = new Time('2010-01-14 13:59:28', 'UTC');
  528. $result = $this->Time->format($time, 'HH:mm', null, 'America/New_York');
  529. $this->assertTimeFormat('08:59', $result);
  530. }
  531. /**
  532. * Custom assert to allow for variation in the version of the intl library, where
  533. * some translations contain a few extra commas.
  534. *
  535. * @param string $expected
  536. * @param string $result
  537. * @return void
  538. */
  539. public function assertTimeFormat($expected, $result)
  540. {
  541. return $this->assertEquals(
  542. str_replace([',', '(', ')', ' at', ' à'], '', $expected),
  543. str_replace([',', '(', ')', ' at', ' à'], '', $result)
  544. );
  545. }
  546. /**
  547. * Test formatting in case the $time parameter is not set
  548. *
  549. * @return void
  550. */
  551. public function testNullDateFormat()
  552. {
  553. $result = $this->Time->format(null);
  554. $this->assertSame(false, $result);
  555. $fallback = 'Date invalid or not set';
  556. $result = $this->Time->format(null, \IntlDateFormatter::FULL, $fallback);
  557. $this->assertEquals($fallback, $result);
  558. }
  559. }