diff options
author | ArthurHoaro <arthur@hoa.ro> | 2017-01-07 14:30:42 +0100 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2017-03-06 21:11:12 +0100 |
commit | 52b503105d389d1796698114573ff618b2ad34a2 (patch) | |
tree | d636098fe0864db98c175cd7dfda19a1c069eb82 /tests/UtilsTest.php | |
parent | 1255a42cfed9ce419962c6cf29181a66c7e22bb8 (diff) | |
download | Shaarli-52b503105d389d1796698114573ff618b2ad34a2.tar.gz Shaarli-52b503105d389d1796698114573ff618b2ad34a2.tar.zst Shaarli-52b503105d389d1796698114573ff618b2ad34a2.zip |
Improve datetime display
Use php-intl extension to display datetimes a bit more nicely, depending on the locale.
What changes:
* the day is no longer displayed
* day number and month are ordered according to the locale
* the timezone is more readable (UTC+1 instead of CET)
Diffstat (limited to 'tests/UtilsTest.php')
-rw-r--r-- | tests/UtilsTest.php | 46 |
1 files changed, 35 insertions, 11 deletions
diff --git a/tests/UtilsTest.php b/tests/UtilsTest.php index b8f608b9..e70cc1ae 100644 --- a/tests/UtilsTest.php +++ b/tests/UtilsTest.php | |||
@@ -23,7 +23,12 @@ class UtilsTest extends PHPUnit_Framework_TestCase | |||
23 | 23 | ||
24 | // Expected log date format | 24 | // Expected log date format |
25 | protected static $dateFormat = 'Y/m/d H:i:s'; | 25 | protected static $dateFormat = 'Y/m/d H:i:s'; |
26 | 26 | ||
27 | /** | ||
28 | * @var string Save the current timezone. | ||
29 | */ | ||
30 | protected static $defaultTimeZone; | ||
31 | |||
27 | 32 | ||
28 | /** | 33 | /** |
29 | * Assign reference data | 34 | * Assign reference data |
@@ -31,6 +36,17 @@ class UtilsTest extends PHPUnit_Framework_TestCase | |||
31 | public static function setUpBeforeClass() | 36 | public static function setUpBeforeClass() |
32 | { | 37 | { |
33 | self::$sidHashes = ReferenceSessionIdHashes::getHashes(); | 38 | self::$sidHashes = ReferenceSessionIdHashes::getHashes(); |
39 | self::$defaultTimeZone = date_default_timezone_get(); | ||
40 | // Timezone without DST for test consistency | ||
41 | date_default_timezone_set('Africa/Nairobi'); | ||
42 | } | ||
43 | |||
44 | /** | ||
45 | * Reset the timezone | ||
46 | */ | ||
47 | public static function tearDownAfterClass() | ||
48 | { | ||
49 | date_default_timezone_set(self::$defaultTimeZone); | ||
34 | } | 50 | } |
35 | 51 | ||
36 | /** | 52 | /** |
@@ -286,20 +302,28 @@ class UtilsTest extends PHPUnit_Framework_TestCase | |||
286 | /** | 302 | /** |
287 | * Test arrays_combine | 303 | * Test arrays_combine |
288 | */ | 304 | */ |
289 | public function testArraysCombination() | 305 | public function testCartesianProductGenerator() |
290 | { | 306 | { |
291 | $arr = [['ab', 'cd'], ['ef', 'gh'], ['ij', 'kl'], ['m']]; | 307 | $arr = [['ab', 'cd'], ['ef', 'gh'], ['ij', 'kl'], ['m']]; |
292 | $expected = [ | 308 | $expected = [ |
293 | 'abefijm', | 309 | ['ab', 'ef', 'ij', 'm'], |
294 | 'cdefijm', | 310 | ['ab', 'ef', 'kl', 'm'], |
295 | 'abghijm', | 311 | ['ab', 'gh', 'ij', 'm'], |
296 | 'cdghijm', | 312 | ['ab', 'gh', 'kl', 'm'], |
297 | 'abefklm', | 313 | ['cd', 'ef', 'ij', 'm'], |
298 | 'cdefklm', | 314 | ['cd', 'ef', 'kl', 'm'], |
299 | 'abghklm', | 315 | ['cd', 'gh', 'ij', 'm'], |
300 | 'cdghklm', | 316 | ['cd', 'gh', 'kl', 'm'], |
301 | ]; | 317 | ]; |
302 | $this->assertEquals($expected, arrays_combination($arr)); | 318 | $this->assertEquals($expected, iterator_to_array(cartesian_product_generator($arr))); |
303 | } | 319 | } |
304 | 320 | ||
321 | /** | ||
322 | * Test date_format() with invalid parameter. | ||
323 | */ | ||
324 | public function testDateFormatInvalid() | ||
325 | { | ||
326 | $this->assertFalse(format_date([])); | ||
327 | $this->assertFalse(format_date(null)); | ||
328 | } | ||
305 | } | 329 | } |