From d1e2f8e52c931f84c11d4f54f32959710d528182 Mon Sep 17 00:00:00 2001 From: VirtualTam Date: Sat, 11 Jul 2015 01:29:12 +0200 Subject: PHP: ensure 5.3 compatibility, refactor timezone utilities Relates to #250 Modifications - supported version - bump required version from 5.1.0 to 5.3.x - update README - add PHP 5.3 to Travis environments - rewrite array declarations: explicitely use array() instead of [] - move checkPHPVersion to application/Utils.php - move timezone functions to application/TimeZone.php - cleanup code - improve test coverage Signed-off-by: VirtualTam --- tests/ConfigTest.php | 10 +++--- tests/LinkDBTest.php | 12 ++++---- tests/TimeZoneTest.php | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/UtilsTest.php | 34 ++++++++++++++++++++- 4 files changed, 127 insertions(+), 12 deletions(-) create mode 100644 tests/TimeZoneTest.php (limited to 'tests') diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 4279c57e..a239d8b7 100755 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -18,7 +18,7 @@ class ConfigTest extends PHPUnit_Framework_TestCase */ public function setUp() { - self::$_configFields = [ + self::$_configFields = array( 'login' => 'login', 'hash' => 'hash', 'salt' => 'salt', @@ -28,13 +28,13 @@ class ConfigTest extends PHPUnit_Framework_TestCase 'redirector' => '', 'disablesessionprotection' => false, 'privateLinkByDefault' => false, - 'config' => [ + 'config' => array( 'CONFIG_FILE' => 'tests/config.php', 'DATADIR' => 'tests', 'config1' => 'config1data', 'config2' => 'config2data', - ] - ]; + ) + ); } /** @@ -174,4 +174,4 @@ class ConfigTest extends PHPUnit_Framework_TestCase include self::$_configFields['config']['CONFIG_FILE']; $this->assertEquals(self::$_configFields['login'], $GLOBALS['login']); } -} \ No newline at end of file +} diff --git a/tests/LinkDBTest.php b/tests/LinkDBTest.php index d34ea4f5..504c8190 100644 --- a/tests/LinkDBTest.php +++ b/tests/LinkDBTest.php @@ -228,12 +228,12 @@ class LinkDBTest extends PHPUnit_Framework_TestCase public function testDays() { $this->assertEquals( - ['20121206', '20130614', '20150310'], + array('20121206', '20130614', '20150310'), self::$publicLinkDB->days() ); $this->assertEquals( - ['20121206', '20130614', '20141125', '20150310'], + array('20121206', '20130614', '20141125', '20150310'), self::$privateLinkDB->days() ); } @@ -269,7 +269,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase public function testAllTags() { $this->assertEquals( - [ + array( 'web' => 3, 'cartoon' => 2, 'gnu' => 2, @@ -279,12 +279,12 @@ class LinkDBTest extends PHPUnit_Framework_TestCase 'software' => 1, 'stallman' => 1, 'free' => 1 - ], + ), self::$publicLinkDB->allTags() ); $this->assertEquals( - [ + array( 'web' => 4, 'cartoon' => 3, 'gnu' => 2, @@ -298,7 +298,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase 'w3c' => 1, 'css' => 1, 'Mercurial' => 1 - ], + ), self::$privateLinkDB->allTags() ); } diff --git a/tests/TimeZoneTest.php b/tests/TimeZoneTest.php new file mode 100644 index 00000000..f3de3913 --- /dev/null +++ b/tests/TimeZoneTest.php @@ -0,0 +1,83 @@ +assertStringStartsWith('Continent:assertContains('selected="selected"', $generated[0]); + $this->assertStringEndsWith('
', $generated[0]); + + // Javascript handler + $this->assertStringStartsWith('', $generated[1]); + } + + /** + * Generate a timezone selection form, with a preselected timezone + */ + public function testGenerateTimeZoneFormPreselected() + { + $generated = generateTimeZoneForm('Antarctica/Syowa'); + + // HTML form + $this->assertStringStartsWith('Continent:assertContains( + 'value="Antarctica" selected="selected"', + $generated[0] + ); + $this->assertContains( + 'value="Syowa" selected="selected"', + $generated[0] + ); + $this->assertStringEndsWith('
', $generated[0]); + + + // Javascript handler + $this->assertStringStartsWith('', $generated[1]); + } + + /** + * Check valid timezones + */ + public function testValidTimeZone() + { + $this->assertTrue(isTimeZoneValid('America', 'Argentina/Ushuaia')); + $this->assertTrue(isTimeZoneValid('Europe', 'Oslo')); + $this->assertTrue(isTimeZoneValid('UTC', 'UTC')); + } + + /** + * Check invalid timezones + */ + public function testInvalidTimeZone() + { + $this->assertFalse(isTimeZoneValid('CEST', 'CEST')); + $this->assertFalse(isTimeZoneValid('Europe', 'Atlantis')); + $this->assertFalse(isTimeZoneValid('Middle_Earth', 'Moria')); + } +} +?> diff --git a/tests/UtilsTest.php b/tests/UtilsTest.php index 8355c7f8..28e15f5a 100644 --- a/tests/UtilsTest.php +++ b/tests/UtilsTest.php @@ -109,7 +109,7 @@ class UtilsTest extends PHPUnit_Framework_TestCase */ public function testGenerateLocationLoop() { $ref = 'http://localhost/?test'; - $this->assertEquals('?', generateLocation($ref, 'localhost', ['test'])); + $this->assertEquals('?', generateLocation($ref, 'localhost', array('test'))); } /** @@ -119,4 +119,36 @@ class UtilsTest extends PHPUnit_Framework_TestCase $ref = 'http://somewebsite.com/?test'; $this->assertEquals('?', generateLocation($ref, 'localhost')); } + + /** + * Check supported PHP versions + */ + public function testCheckSupportedPHPVersion() + { + $minVersion = '5.3'; + checkPHPVersion($minVersion, '5.4.32'); + checkPHPVersion($minVersion, '5.5'); + checkPHPVersion($minVersion, '5.6.10'); + } + + /** + * Check a unsupported PHP version + * @expectedException Exception + * @expectedExceptionMessageRegExp /Your PHP version is obsolete/ + */ + public function testCheckSupportedPHPVersion51() + { + checkPHPVersion('5.3', '5.1.0'); + } + + /** + * Check another unsupported PHP version + * @expectedException Exception + * @expectedExceptionMessageRegExp /Your PHP version is obsolete/ + */ + public function testCheckSupportedPHPVersion52() + { + checkPHPVersion('5.3', '5.2'); + } } +?> -- cgit v1.2.3