From: VirtualTam Date: Fri, 31 Jul 2015 14:08:32 +0000 (+0200) Subject: Merge pull request #276 from virtualtam/tools/phpcs X-Git-Tag: v0.5.1~8 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=96db105e4c0833324f7168edb5673278de8ccd54;hp=3e25f245f95bdaeb9db2e6e0540189d5378ad05d;p=github%2Fshaarli%2FShaarli.git Merge pull request #276 from virtualtam/tools/phpcs Add a generic rule to run PHPCS against different coding standards --- diff --git a/.travis.yml b/.travis.yml index bcaf682c..80db6506 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,13 @@ +sudo: false language: php php: - 5.6 - 5.5 - 5.4 + - 5.3 install: - composer self-update - composer install script: + - make clean - make test diff --git a/Makefile b/Makefile index 5104e302..d69fac46 100644 --- a/Makefile +++ b/Makefile @@ -106,7 +106,7 @@ mess_detector_summary: mess_title # See phpunit.xml for configuration # https://phpunit.de/manual/current/en/appendixes.configuration.html ## -test: clean +test: @echo "-------" @echo "PHPUNIT" @echo "-------" @@ -118,13 +118,13 @@ test: clean ### remove all unversioned files clean: - @git clean -df + @git clean -df ### update the local copy of the documentation doc: clean - @rm -rf doc - @git clone https://github.com/shaarli/Shaarli.wiki.git doc - @rm -rf doc/.git + @rm -rf doc + @git clone https://github.com/shaarli/Shaarli.wiki.git doc + @rm -rf doc/.git ### Convert local markdown documentation to HTML htmldoc: diff --git a/README.md b/README.md old mode 100644 new mode 100755 index 15d4379a..5743ec4b --- a/README.md +++ b/README.md @@ -55,9 +55,11 @@ Password: `demo` * [Bugs/Feature requests/Discussion](https://github.com/shaarli/Shaarli/issues/) -## Installing +## Requirements + +Check the [Server requirements](https://github.com/shaarli/Shaarli/wiki/Server-requirements) wiki page. -Shaarli requires php 5.4. `php-gd` is optional and provides thumbnail resizing. +## Installing * Download the latest stable release from https://github.com/shaarli/Shaarli/releases * Unpack the archive in a directory on your web server diff --git a/application/Config.php b/application/Config.php index 0b01b524..ec799d7f 100755 --- a/application/Config.php +++ b/application/Config.php @@ -19,10 +19,10 @@ function writeConfig($config, $isLoggedIn) { // These fields are required in configuration. - $MANDATORY_FIELDS = [ + $MANDATORY_FIELDS = array( 'login', 'hash', 'salt', 'timezone', 'title', 'titleLink', 'redirector', 'disablesessionprotection', 'privateLinkByDefault' - ]; + ); if (!isset($config['config']['CONFIG_FILE'])) { throw new MissingFieldConfigException('CONFIG_FILE'); @@ -126,4 +126,4 @@ class UnauthorizedConfigException extends Exception { $this->message = 'You are not authorized to alter config.'; } -} \ No newline at end of file +} diff --git a/application/TimeZone.php b/application/TimeZone.php new file mode 100644 index 00000000..ccbef918 --- /dev/null +++ b/application/TimeZone.php @@ -0,0 +1,110 @@ +'.$city.''; + } + } + + $continents_html = ''; + $continents = array_keys($continents); + + foreach ($continents as $continent) { + $continents_html .= ''; - } - } - $continents_html = ''; - $continents = array_keys($continents); - foreach($continents as $continent) - $continents_html.=''; - $cities_html = $cities[$pcontinent]; - $timezone_form = "Continent: "; - $timezone_form .= "    City:
"; - $timezone_js = "" ; - return array($timezone_form,$timezone_js); - } - return array('',''); -} - -// Tells if a timezone is valid or not. -// If not valid, returns false. -// If system does not support timezone list, returns false. -function isTZvalid($continent,$city) -{ - $tz = $continent.'/'.$city; - if (function_exists('timezone_identifiers_list')) // because of old PHP version (5.1) which can be found on free.fr - { - if (in_array($tz, timezone_identifiers_list())) // it's a valid timezone? - return true; - } - return false; -} if (!function_exists('json_encode')) { function json_encode($data) { switch ($type = gettype($data)) { diff --git a/shaarli_version.php b/shaarli_version.php index d2254870..a2045a7b 100644 --- a/shaarli_version.php +++ b/shaarli_version.php @@ -1 +1 @@ - + 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'); + } } +?> diff --git a/tpl/picwall.html b/tpl/picwall.html index 9a2a4715..f59685cf 100644 --- a/tpl/picwall.html +++ b/tpl/picwall.html @@ -17,7 +17,9 @@ {include="page.footer"} - \ No newline at end of file +