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 <virtualtam@flibidi.net>
This commit is contained in:
parent
5b0ebbc5de
commit
d1e2f8e52c
10 changed files with 288 additions and 102 deletions
|
@ -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']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
);
|
||||
}
|
||||
|
|
83
tests/TimeZoneTest.php
Normal file
83
tests/TimeZoneTest.php
Normal file
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
/**
|
||||
* TimeZone's tests
|
||||
*/
|
||||
|
||||
require_once 'application/TimeZone.php';
|
||||
|
||||
/**
|
||||
* Unitary tests for timezone utilities
|
||||
*/
|
||||
class TimeZoneTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Generate a timezone selection form
|
||||
*/
|
||||
public function testGenerateTimeZoneForm()
|
||||
{
|
||||
$generated = generateTimeZoneForm();
|
||||
|
||||
// HTML form
|
||||
$this->assertStringStartsWith('Continent:<select', $generated[0]);
|
||||
$this->assertContains('selected="selected"', $generated[0]);
|
||||
$this->assertStringEndsWith('</select><br />', $generated[0]);
|
||||
|
||||
// Javascript handler
|
||||
$this->assertStringStartsWith('<script>', $generated[1]);
|
||||
$this->assertContains(
|
||||
'<option value=\"Bermuda\">Bermuda<\/option>',
|
||||
$generated[1]
|
||||
);
|
||||
$this->assertStringEndsWith('</script>', $generated[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a timezone selection form, with a preselected timezone
|
||||
*/
|
||||
public function testGenerateTimeZoneFormPreselected()
|
||||
{
|
||||
$generated = generateTimeZoneForm('Antarctica/Syowa');
|
||||
|
||||
// HTML form
|
||||
$this->assertStringStartsWith('Continent:<select', $generated[0]);
|
||||
$this->assertContains(
|
||||
'value="Antarctica" selected="selected"',
|
||||
$generated[0]
|
||||
);
|
||||
$this->assertContains(
|
||||
'value="Syowa" selected="selected"',
|
||||
$generated[0]
|
||||
);
|
||||
$this->assertStringEndsWith('</select><br />', $generated[0]);
|
||||
|
||||
|
||||
// Javascript handler
|
||||
$this->assertStringStartsWith('<script>', $generated[1]);
|
||||
$this->assertContains(
|
||||
'<option value=\"Bermuda\">Bermuda<\/option>',
|
||||
$generated[1]
|
||||
);
|
||||
$this->assertStringEndsWith('</script>', $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'));
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue