diff options
author | ArthurHoaro <arthur@hoa.ro> | 2017-03-06 21:13:48 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-06 21:13:48 +0100 |
commit | 9971f7c82cc47446b457464cec5b4fefcae470e1 (patch) | |
tree | 87b01fc1dd9d0ca1f0c874aad847029eab74d0d8 /tests | |
parent | 236239be752a7bb24547237b5751ac4fcbc0e549 (diff) | |
parent | 36c8fb1ef869c29e783f0dd5ebef2fb5566e2611 (diff) | |
download | Shaarli-9971f7c82cc47446b457464cec5b4fefcae470e1.tar.gz Shaarli-9971f7c82cc47446b457464cec5b4fefcae470e1.tar.zst Shaarli-9971f7c82cc47446b457464cec5b4fefcae470e1.zip |
Merge pull request #750 from ArthurHoaro/feature/intl-dates
Improve datetime display
Diffstat (limited to 'tests')
-rw-r--r-- | tests/UtilsTest.php | 46 | ||||
-rw-r--r-- | tests/languages/bootstrap.php | 7 | ||||
-rw-r--r-- | tests/languages/de/UtilsDeTest.php | 25 | ||||
-rw-r--r-- | tests/languages/en/UtilsEnTest.php | 25 | ||||
-rw-r--r-- | tests/languages/fr/UtilsFrTest.php | 25 |
5 files changed, 127 insertions, 1 deletions
diff --git a/tests/UtilsTest.php b/tests/UtilsTest.php index c885f552..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 | /** |
@@ -282,4 +298,32 @@ class UtilsTest extends PHPUnit_Framework_TestCase | |||
282 | $this->assertEquals('', normalize_spaces('')); | 298 | $this->assertEquals('', normalize_spaces('')); |
283 | $this->assertEquals(null, normalize_spaces(null)); | 299 | $this->assertEquals(null, normalize_spaces(null)); |
284 | } | 300 | } |
301 | |||
302 | /** | ||
303 | * Test arrays_combine | ||
304 | */ | ||
305 | public function testCartesianProductGenerator() | ||
306 | { | ||
307 | $arr = [['ab', 'cd'], ['ef', 'gh'], ['ij', 'kl'], ['m']]; | ||
308 | $expected = [ | ||
309 | ['ab', 'ef', 'ij', 'm'], | ||
310 | ['ab', 'ef', 'kl', 'm'], | ||
311 | ['ab', 'gh', 'ij', 'm'], | ||
312 | ['ab', 'gh', 'kl', 'm'], | ||
313 | ['cd', 'ef', 'ij', 'm'], | ||
314 | ['cd', 'ef', 'kl', 'm'], | ||
315 | ['cd', 'gh', 'ij', 'm'], | ||
316 | ['cd', 'gh', 'kl', 'm'], | ||
317 | ]; | ||
318 | $this->assertEquals($expected, iterator_to_array(cartesian_product_generator($arr))); | ||
319 | } | ||
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 | } | ||
285 | } | 329 | } |
diff --git a/tests/languages/bootstrap.php b/tests/languages/bootstrap.php new file mode 100644 index 00000000..95609210 --- /dev/null +++ b/tests/languages/bootstrap.php | |||
@@ -0,0 +1,7 @@ | |||
1 | <?php | ||
2 | if (! empty('UT_LOCALE')) { | ||
3 | setlocale(LC_ALL, getenv('UT_LOCALE')); | ||
4 | } | ||
5 | |||
6 | require_once 'vendor/autoload.php'; | ||
7 | |||
diff --git a/tests/languages/de/UtilsDeTest.php b/tests/languages/de/UtilsDeTest.php new file mode 100644 index 00000000..8a740389 --- /dev/null +++ b/tests/languages/de/UtilsDeTest.php | |||
@@ -0,0 +1,25 @@ | |||
1 | <?php | ||
2 | |||
3 | require_once 'tests/UtilsTest.php'; | ||
4 | |||
5 | |||
6 | class UtilsDeTest extends UtilsTest | ||
7 | { | ||
8 | /** | ||
9 | * Test date_format(). | ||
10 | */ | ||
11 | public function testDateFormat() | ||
12 | { | ||
13 | $date = DateTime::createFromFormat('Ymd_His', '20170101_101112'); | ||
14 | $this->assertRegExp('/1. Januar 2017 (um )?10:11:12 GMT\+0?3(:00)?/', format_date($date, true)); | ||
15 | } | ||
16 | |||
17 | /** | ||
18 | * Test date_format() using builtin PHP function strftime. | ||
19 | */ | ||
20 | public function testDateFormatDefault() | ||
21 | { | ||
22 | $date = DateTime::createFromFormat('Ymd_His', '20170101_101112'); | ||
23 | $this->assertEquals('So 01 Jan 2017 10:11:12 EAT', format_date($date, false)); | ||
24 | } | ||
25 | } | ||
diff --git a/tests/languages/en/UtilsEnTest.php b/tests/languages/en/UtilsEnTest.php new file mode 100644 index 00000000..60bcb653 --- /dev/null +++ b/tests/languages/en/UtilsEnTest.php | |||
@@ -0,0 +1,25 @@ | |||
1 | <?php | ||
2 | |||
3 | require_once 'tests/UtilsTest.php'; | ||
4 | |||
5 | |||
6 | class UtilsEnTest extends UtilsTest | ||
7 | { | ||
8 | /** | ||
9 | * Test date_format(). | ||
10 | */ | ||
11 | public function testDateFormat() | ||
12 | { | ||
13 | $date = DateTime::createFromFormat('Ymd_His', '20170101_101112'); | ||
14 | $this->assertRegExp('/January 1, 2017 (at )?10:11:12 AM GMT\+0?3(:00)?/', format_date($date, true)); | ||
15 | } | ||
16 | |||
17 | /** | ||
18 | * Test date_format() using builtin PHP function strftime. | ||
19 | */ | ||
20 | public function testDateFormatDefault() | ||
21 | { | ||
22 | $date = DateTime::createFromFormat('Ymd_His', '20170101_101112'); | ||
23 | $this->assertEquals('Sun 01 Jan 2017 10:11:12 AM EAT', format_date($date, false)); | ||
24 | } | ||
25 | } | ||
diff --git a/tests/languages/fr/UtilsFrTest.php b/tests/languages/fr/UtilsFrTest.php new file mode 100644 index 00000000..890308d3 --- /dev/null +++ b/tests/languages/fr/UtilsFrTest.php | |||
@@ -0,0 +1,25 @@ | |||
1 | <?php | ||
2 | |||
3 | require_once 'tests/UtilsTest.php'; | ||
4 | |||
5 | |||
6 | class UtilsFrTest extends UtilsTest | ||
7 | { | ||
8 | /** | ||
9 | * Test date_format(). | ||
10 | */ | ||
11 | public function testDateFormat() | ||
12 | { | ||
13 | $date = DateTime::createFromFormat('Ymd_His', '20170101_101112'); | ||
14 | $this->assertRegExp('/1 janvier 2017 (à )?10:11:12 UTC\+0?3(:00)?/', format_date($date)); | ||
15 | } | ||
16 | |||
17 | /** | ||
18 | * Test date_format() using builtin PHP function strftime. | ||
19 | */ | ||
20 | public function testDateFormatDefault() | ||
21 | { | ||
22 | $date = DateTime::createFromFormat('Ymd_His', '20170101_101112'); | ||
23 | $this->assertEquals('dim. 01 janv. 2017 10:11:12 EAT', format_date($date, false)); | ||
24 | } | ||
25 | } | ||