From 1255a42cfed9ce419962c6cf29181a66c7e22bb8 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sat, 7 Jan 2017 14:28:58 +0100 Subject: Improve autoLocale() detection - Creates arrays_combination function to cover all cases - add the underscore separator in the regex - add `utf8` encoding in addition to `UTF-8` --- tests/UtilsTest.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'tests') diff --git a/tests/UtilsTest.php b/tests/UtilsTest.php index c885f552..b8f608b9 100644 --- a/tests/UtilsTest.php +++ b/tests/UtilsTest.php @@ -282,4 +282,24 @@ class UtilsTest extends PHPUnit_Framework_TestCase $this->assertEquals('', normalize_spaces('')); $this->assertEquals(null, normalize_spaces(null)); } + + /** + * Test arrays_combine + */ + public function testArraysCombination() + { + $arr = [['ab', 'cd'], ['ef', 'gh'], ['ij', 'kl'], ['m']]; + $expected = [ + 'abefijm', + 'cdefijm', + 'abghijm', + 'cdghijm', + 'abefklm', + 'cdefklm', + 'abghklm', + 'cdghklm', + ]; + $this->assertEquals($expected, arrays_combination($arr)); + } + } -- cgit v1.2.3 From 52b503105d389d1796698114573ff618b2ad34a2 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sat, 7 Jan 2017 14:30:42 +0100 Subject: 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) --- tests/UtilsTest.php | 46 +++++++++++++++++++++++++++++--------- tests/languages/bootstrap.php | 7 ++++++ tests/languages/de/UtilsDeTest.php | 25 +++++++++++++++++++++ tests/languages/en/UtilsEnTest.php | 25 +++++++++++++++++++++ tests/languages/fr/UtilsFrTest.php | 25 +++++++++++++++++++++ 5 files changed, 117 insertions(+), 11 deletions(-) create mode 100644 tests/languages/bootstrap.php create mode 100644 tests/languages/de/UtilsDeTest.php create mode 100644 tests/languages/en/UtilsEnTest.php create mode 100644 tests/languages/fr/UtilsFrTest.php (limited to 'tests') 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 // Expected log date format protected static $dateFormat = 'Y/m/d H:i:s'; - + + /** + * @var string Save the current timezone. + */ + protected static $defaultTimeZone; + /** * Assign reference data @@ -31,6 +36,17 @@ class UtilsTest extends PHPUnit_Framework_TestCase public static function setUpBeforeClass() { self::$sidHashes = ReferenceSessionIdHashes::getHashes(); + self::$defaultTimeZone = date_default_timezone_get(); + // Timezone without DST for test consistency + date_default_timezone_set('Africa/Nairobi'); + } + + /** + * Reset the timezone + */ + public static function tearDownAfterClass() + { + date_default_timezone_set(self::$defaultTimeZone); } /** @@ -286,20 +302,28 @@ class UtilsTest extends PHPUnit_Framework_TestCase /** * Test arrays_combine */ - public function testArraysCombination() + public function testCartesianProductGenerator() { $arr = [['ab', 'cd'], ['ef', 'gh'], ['ij', 'kl'], ['m']]; $expected = [ - 'abefijm', - 'cdefijm', - 'abghijm', - 'cdghijm', - 'abefklm', - 'cdefklm', - 'abghklm', - 'cdghklm', + ['ab', 'ef', 'ij', 'm'], + ['ab', 'ef', 'kl', 'm'], + ['ab', 'gh', 'ij', 'm'], + ['ab', 'gh', 'kl', 'm'], + ['cd', 'ef', 'ij', 'm'], + ['cd', 'ef', 'kl', 'm'], + ['cd', 'gh', 'ij', 'm'], + ['cd', 'gh', 'kl', 'm'], ]; - $this->assertEquals($expected, arrays_combination($arr)); + $this->assertEquals($expected, iterator_to_array(cartesian_product_generator($arr))); } + /** + * Test date_format() with invalid parameter. + */ + public function testDateFormatInvalid() + { + $this->assertFalse(format_date([])); + $this->assertFalse(format_date(null)); + } } 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 @@ +assertRegExp('/1. Januar 2017 (um )?10:11:12 GMT\+0?3(:00)?/', format_date($date, true)); + } + + /** + * Test date_format() using builtin PHP function strftime. + */ + public function testDateFormatDefault() + { + $date = DateTime::createFromFormat('Ymd_His', '20170101_101112'); + $this->assertEquals('So 01 Jan 2017 10:11:12 EAT', format_date($date, false)); + } +} 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 @@ +assertRegExp('/January 1, 2017 (at )?10:11:12 AM GMT\+0?3(:00)?/', format_date($date, true)); + } + + /** + * Test date_format() using builtin PHP function strftime. + */ + public function testDateFormatDefault() + { + $date = DateTime::createFromFormat('Ymd_His', '20170101_101112'); + $this->assertEquals('Sun 01 Jan 2017 10:11:12 AM EAT', format_date($date, false)); + } +} 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 @@ +assertRegExp('/1 janvier 2017 (à )?10:11:12 UTC\+0?3(:00)?/', format_date($date)); + } + + /** + * Test date_format() using builtin PHP function strftime. + */ + public function testDateFormatDefault() + { + $date = DateTime::createFromFormat('Ymd_His', '20170101_101112'); + $this->assertEquals('dim. 01 janv. 2017 10:11:12 EAT', format_date($date, false)); + } +} -- cgit v1.2.3