From: ArthurHoaro Date: Wed, 30 Sep 2020 09:12:17 +0000 (+0200) Subject: Merge pull request #1566 from nodiscc/makefile-composer-install X-Git-Tag: v0.12.0-beta-1~4 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=769a28833b68f4c629c5578348b31d51016fbf6f;hp=0f686afe11e56392e0beb3131a8380922600d408;p=github%2Fshaarli%2FShaarli.git Merge pull request #1566 from nodiscc/makefile-composer-install doc/Makefile: remove references to composer update --- diff --git a/.travis.yml b/.travis.yml index fb95235c..af04a022 100644 --- a/.travis.yml +++ b/.travis.yml @@ -43,7 +43,8 @@ cache: install: # install/update composer and php dependencies - - composer install --prefer-dist + - composer config --unset platform && composer config platform.php $TRAVIS_PHP_VERSION + - composer update before_script: - PATH=${PATH//:\.\/node_modules\/\.bin/} diff --git a/Makefile b/Makefile index d1663926..0ff6bd3f 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ BIN = vendor/bin -all: static_analysis_summary check_permissions test +all: check_permissions test ## # Docker test adapter diff --git a/application/front/controller/visitor/ShaarliVisitorController.php b/application/front/controller/visitor/ShaarliVisitorController.php index cd27455b..55c075a2 100644 --- a/application/front/controller/visitor/ShaarliVisitorController.php +++ b/application/front/controller/visitor/ShaarliVisitorController.php @@ -142,6 +142,13 @@ abstract class ShaarliVisitorController if (null !== $referer) { $currentUrl = parse_url($referer); + // If the referer is not related to Shaarli instance, redirect to default + if (isset($currentUrl['host']) + && strpos(index_url($this->container->environment), $currentUrl['host']) === false + ) { + return $response->withRedirect($defaultPath); + } + parse_str($currentUrl['query'] ?? '', $params); $path = $currentUrl['path'] ?? $defaultPath; } else { diff --git a/composer.json b/composer.json index 738d9f58..de7b1732 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "require-dev": { "roave/security-advisories": "dev-master", "phpunit/phpcov": "*", - "phpunit/phpunit": "^7.5", + "phpunit/phpunit": "^7.5 || ^8.0", "squizlabs/php_codesniffer": "3.*" }, "suggest": { diff --git a/doc/md/dev/Plugin-system.md b/doc/md/dev/Plugin-system.md index a87bd0cf..c29774de 100644 --- a/doc/md/dev/Plugin-system.md +++ b/doc/md/dev/Plugin-system.md @@ -139,6 +139,20 @@ Each file contain two keys: > Note: In PHP, `parse_ini_file()` seems to want strings to be between by quotes `"` in the ini file. +### Understanding relative paths + +Because Shaarli is a self-hosted tool, an instance can either be installed at the root directory, or under a subfolder. +This means that you can *never* use absolute paths (eg `/plugins/mything/file.png`). + +If a file needs to be included in server end, use simple relative path: +`PluginManager::$PLUGINS_PATH . '/mything/template.html'`. + +If it needs to be included in front end side (e.g. an image), +the relative path must be prefixed with special data `_BASE_PATH_`: +`($data['_BASE_PATH_'] ?? '') . '/' . PluginManager::$PLUGINS_PATH . '/mything/picture.png`. + +Note that special placeholders for CSS and JS files (respectively `css_files` and `js_files`) are already prefixed +with the base path in template files. ### It's not working! diff --git a/plugins/archiveorg/archiveorg.php b/plugins/archiveorg/archiveorg.php index f26e6129..922b5966 100644 --- a/plugins/archiveorg/archiveorg.php +++ b/plugins/archiveorg/archiveorg.php @@ -20,10 +20,12 @@ function hook_archiveorg_render_linklist($data) $path = ($data['_BASE_PATH_'] ?? '') . '/' . PluginManager::$PLUGINS_PATH; foreach ($data['links'] as &$value) { - if ($value['private'] && preg_match('/^\?[a-zA-Z0-9-_@]{6}($|&|#)/', $value['real_url'])) { + $isNote = startsWith($value['real_url'], '/shaare/'); + if ($value['private'] && $isNote) { continue; } - $archive = sprintf($archive_html, $value['url'], $path, t('View on archive.org')); + $url = $isNote ? rtrim(index_url($_SERVER), '/') . $value['real_url'] : $value['real_url']; + $archive = sprintf($archive_html, $url, $path, t('View on archive.org')); $value['link_plugin'][] = $archive; } diff --git a/plugins/isso/isso.php b/plugins/isso/isso.php index 16edd9a6..79e7380b 100644 --- a/plugins/isso/isso.php +++ b/plugins/isso/isso.php @@ -49,7 +49,7 @@ function hook_isso_render_linklist($data, $conf) $isso = sprintf($issoHtml, $issoUrl, $issoUrl, $link['id'], $link['id']); $data['plugin_end_zone'][] = $isso; } else { - $button = ''; + $button = ''; // For the default theme we use a FontAwesome icon which is better than an image if ($conf->get('resource.theme') === 'default') { $button .= ''; diff --git a/plugins/qrcode/qrcode.php b/plugins/qrcode/qrcode.php index 56ae47b3..95499e39 100644 --- a/plugins/qrcode/qrcode.php +++ b/plugins/qrcode/qrcode.php @@ -42,7 +42,7 @@ function hook_qrcode_render_linklist($data) function hook_qrcode_render_footer($data) { if ($data['_PAGE_'] == TemplatePage::LINKLIST) { - $data['js_files'][] = ($data['_BASE_PATH_'] ?? '') . '/' . PluginManager::$PLUGINS_PATH . '/qrcode/shaarli-qrcode.js'; + $data['js_files'][] = PluginManager::$PLUGINS_PATH . '/qrcode/shaarli-qrcode.js'; } return $data; @@ -58,7 +58,7 @@ function hook_qrcode_render_footer($data) function hook_qrcode_render_includes($data) { if ($data['_PAGE_'] == TemplatePage::LINKLIST) { - $data['css_files'][] = ($data['_BASE_PATH_'] ?? '') . '/' . PluginManager::$PLUGINS_PATH . '/qrcode/qrcode.css'; + $data['css_files'][] = PluginManager::$PLUGINS_PATH . '/qrcode/qrcode.css'; } return $data; diff --git a/tests/ApplicationUtilsTest.php b/tests/ApplicationUtilsTest.php index 15388970..421d2dd9 100644 --- a/tests/ApplicationUtilsTest.php +++ b/tests/ApplicationUtilsTest.php @@ -17,7 +17,7 @@ class ApplicationUtilsTest extends \PHPUnit\Framework\TestCase /** * Reset test data for each test */ - public function setUp() + protected function setUp(): void { FakeApplicationUtils::$VERSION_CODE = ''; if (file_exists(self::$testUpdateFile)) { @@ -28,7 +28,7 @@ class ApplicationUtilsTest extends \PHPUnit\Framework\TestCase /** * Remove test version file if it exists */ - public function tearDown() + protected function tearDown(): void { if (is_file('sandbox/version.php')) { unlink('sandbox/version.php'); @@ -145,10 +145,11 @@ class ApplicationUtilsTest extends \PHPUnit\Framework\TestCase /** * Test update checks - invalid Git branch * @expectedException Exception - * @expectedExceptionMessageRegExp /Invalid branch selected for updates/ */ public function testCheckUpdateInvalidGitBranch() { + $this->expectExceptionMessageRegExp('/Invalid branch selected for updates/'); + ApplicationUtils::checkUpdate('', 'null', 0, true, true, 'unstable'); } @@ -261,20 +262,22 @@ class ApplicationUtilsTest extends \PHPUnit\Framework\TestCase /** * Check a unsupported PHP version * @expectedException Exception - * @expectedExceptionMessageRegExp /Your PHP version is obsolete/ */ public function testCheckSupportedPHPVersion51() { + $this->expectExceptionMessageRegExp('/Your PHP version is obsolete/'); + $this->assertTrue(ApplicationUtils::checkPHPVersion('5.3', '5.1.0')); } /** * Check another unsupported PHP version * @expectedException Exception - * @expectedExceptionMessageRegExp /Your PHP version is obsolete/ */ public function testCheckSupportedPHPVersion52() { + $this->expectExceptionMessageRegExp('/Your PHP version is obsolete/'); + $this->assertTrue(ApplicationUtils::checkPHPVersion('5.3', '5.2')); } diff --git a/tests/FileUtilsTest.php b/tests/FileUtilsTest.php index 57719175..6e8f44f2 100644 --- a/tests/FileUtilsTest.php +++ b/tests/FileUtilsTest.php @@ -19,7 +19,7 @@ class FileUtilsTest extends \PHPUnit\Framework\TestCase /** * Delete test file after every test. */ - public function tearDown() + protected function tearDown(): void { @unlink(self::$file); } @@ -49,12 +49,12 @@ class FileUtilsTest extends \PHPUnit\Framework\TestCase /** * File not writable: raise an exception. - * - * @expectedException Shaarli\Exceptions\IOException - * @expectedExceptionMessage Error accessing "sandbox/flat.db" */ public function testWriteWithoutPermission() { + $this->expectException(\Shaarli\Exceptions\IOException::class); + $this->expectExceptionMessage('Error accessing "sandbox/flat.db"'); + touch(self::$file); chmod(self::$file, 0440); FileUtils::writeFlatDB(self::$file, null); @@ -62,23 +62,23 @@ class FileUtilsTest extends \PHPUnit\Framework\TestCase /** * Folder non existent: raise an exception. - * - * @expectedException Shaarli\Exceptions\IOException - * @expectedExceptionMessage Error accessing "nopefolder" */ public function testWriteFolderDoesNotExist() { + $this->expectException(\Shaarli\Exceptions\IOException::class); + $this->expectExceptionMessage('Error accessing "nopefolder"'); + FileUtils::writeFlatDB('nopefolder/file', null); } /** * Folder non writable: raise an exception. - * - * @expectedException Shaarli\Exceptions\IOException - * @expectedExceptionMessage Error accessing "sandbox" */ public function testWriteFolderPermission() { + $this->expectException(\Shaarli\Exceptions\IOException::class); + $this->expectExceptionMessage('Error accessing "sandbox"'); + chmod(dirname(self::$file), 0555); try { FileUtils::writeFlatDB(self::$file, null); diff --git a/tests/HistoryTest.php b/tests/HistoryTest.php index 7189c3a9..fb633e79 100644 --- a/tests/HistoryTest.php +++ b/tests/HistoryTest.php @@ -16,7 +16,7 @@ class HistoryTest extends \PHPUnit\Framework\TestCase /** * Delete history file. */ - public function setUp() + protected function setUp(): void { if (file_exists(self::$historyFilePath)) { unlink(self::$historyFilePath); @@ -44,12 +44,12 @@ class HistoryTest extends \PHPUnit\Framework\TestCase /** * Not writable history file: raise an exception. - * - * @expectedException Exception - * @expectedExceptionMessage History file isn't readable or writable */ public function testConstructNotWritable() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('History file isn\'t readable or writable'); + touch(self::$historyFilePath); chmod(self::$historyFilePath, 0440); $history = new History(self::$historyFilePath); @@ -58,12 +58,12 @@ class HistoryTest extends \PHPUnit\Framework\TestCase /** * Not parsable history file: raise an exception. - * - * @expectedException Exception - * @expectedExceptionMessageRegExp /Could not parse history file/ */ public function testConstructNotParsable() { + $this->expectException(\Exception::class); + $this->expectExceptionMessageRegExp('/Could not parse history file/'); + file_put_contents(self::$historyFilePath, 'not parsable'); $history = new History(self::$historyFilePath); // gzinflate generates a warning diff --git a/tests/LanguagesTest.php b/tests/LanguagesTest.php index de83f291..914179c8 100644 --- a/tests/LanguagesTest.php +++ b/tests/LanguagesTest.php @@ -22,7 +22,7 @@ class LanguagesTest extends \PHPUnit\Framework\TestCase /** * */ - public function setUp() + protected function setUp(): void { $this->conf = new ConfigManager(self::$configFile); } diff --git a/tests/ThumbnailerTest.php b/tests/ThumbnailerTest.php index c01849f7..5b6d6a4d 100644 --- a/tests/ThumbnailerTest.php +++ b/tests/ThumbnailerTest.php @@ -30,7 +30,7 @@ class ThumbnailerTest extends TestCase */ protected $conf; - public function setUp() + protected function setUp(): void { $this->conf = new ConfigManager('tests/utils/config/configJson'); $this->conf->set('thumbnails.mode', Thumbnailer::MODE_ALL); @@ -43,7 +43,7 @@ class ThumbnailerTest extends TestCase WTConfigManager::addFile('tests/utils/config/wt.json'); } - public function tearDown() + protected function tearDown(): void { $this->rrmdirContent('sandbox/'); } diff --git a/tests/TimeZoneTest.php b/tests/TimeZoneTest.php index 02bf060f..d3d9aeeb 100644 --- a/tests/TimeZoneTest.php +++ b/tests/TimeZoneTest.php @@ -15,7 +15,7 @@ class TimeZoneTest extends PHPUnit\Framework\TestCase */ protected $installedTimezones; - public function setUp() + protected function setUp(): void { $this->installedTimezones = [ 'Antarctica/Syowa', diff --git a/tests/UtilsTest.php b/tests/UtilsTest.php index 26d2a6b8..93b77539 100644 --- a/tests/UtilsTest.php +++ b/tests/UtilsTest.php @@ -26,7 +26,7 @@ class UtilsTest extends PHPUnit\Framework\TestCase /** * Assign reference data */ - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { self::$defaultTimeZone = date_default_timezone_get(); // Timezone without DST for test consistency @@ -36,7 +36,7 @@ class UtilsTest extends PHPUnit\Framework\TestCase /** * Reset the timezone */ - public static function tearDownAfterClass() + public static function tearDownAfterClass(): void { date_default_timezone_set(self::$defaultTimeZone); } @@ -44,7 +44,7 @@ class UtilsTest extends PHPUnit\Framework\TestCase /** * Resets test data before each test */ - protected function setUp() + protected function setUp(): void { if (file_exists(self::$testLogFile)) { unlink(self::$testLogFile); diff --git a/tests/api/ApiMiddlewareTest.php b/tests/api/ApiMiddlewareTest.php index df2fb33a..b157e4a7 100644 --- a/tests/api/ApiMiddlewareTest.php +++ b/tests/api/ApiMiddlewareTest.php @@ -43,7 +43,7 @@ class ApiMiddlewareTest extends \PHPUnit\Framework\TestCase /** * Before every test, instantiate a new Api with its config, plugins and bookmarks. */ - public function setUp() + protected function setUp(): void { $this->conf = new ConfigManager('tests/utils/config/configJson'); $this->conf->set('api.secret', 'NapoleonWasALizard'); @@ -61,7 +61,7 @@ class ApiMiddlewareTest extends \PHPUnit\Framework\TestCase /** * After every test, remove the test datastore. */ - public function tearDown() + protected function tearDown(): void { @unlink(self::$testDatastore); } diff --git a/tests/api/ApiUtilsTest.php b/tests/api/ApiUtilsTest.php index 7efec9bb..96787014 100644 --- a/tests/api/ApiUtilsTest.php +++ b/tests/api/ApiUtilsTest.php @@ -13,7 +13,7 @@ class ApiUtilsTest extends \PHPUnit\Framework\TestCase /** * Force the timezone for ISO datetimes. */ - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { date_default_timezone_set('UTC'); } @@ -66,143 +66,143 @@ class ApiUtilsTest extends \PHPUnit\Framework\TestCase /** * Test validateJwtToken() with a malformed JWT token. - * - * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException - * @expectedExceptionMessage Malformed JWT token */ public function testValidateJwtTokenMalformed() { + $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class); + $this->expectExceptionMessage('Malformed JWT token'); + $token = 'ABC.DEF'; ApiUtils::validateJwtToken($token, 'foo'); } /** * Test validateJwtToken() with an empty JWT token. - * - * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException - * @expectedExceptionMessage Malformed JWT token */ public function testValidateJwtTokenMalformedEmpty() { + $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class); + $this->expectExceptionMessage('Malformed JWT token'); + $token = false; ApiUtils::validateJwtToken($token, 'foo'); } /** * Test validateJwtToken() with a JWT token without header. - * - * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException - * @expectedExceptionMessage Malformed JWT token */ public function testValidateJwtTokenMalformedEmptyHeader() { + $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class); + $this->expectExceptionMessage('Malformed JWT token'); + $token = '.payload.signature'; ApiUtils::validateJwtToken($token, 'foo'); } /** * Test validateJwtToken() with a JWT token without payload - * - * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException - * @expectedExceptionMessage Malformed JWT token */ public function testValidateJwtTokenMalformedEmptyPayload() { + $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class); + $this->expectExceptionMessage('Malformed JWT token'); + $token = 'header..signature'; ApiUtils::validateJwtToken($token, 'foo'); } /** * Test validateJwtToken() with a JWT token with an empty signature. - * - * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException - * @expectedExceptionMessage Invalid JWT signature */ public function testValidateJwtTokenInvalidSignatureEmpty() { + $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class); + $this->expectExceptionMessage('Invalid JWT signature'); + $token = 'header.payload.'; ApiUtils::validateJwtToken($token, 'foo'); } /** * Test validateJwtToken() with a JWT token with an invalid signature. - * - * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException - * @expectedExceptionMessage Invalid JWT signature */ public function testValidateJwtTokenInvalidSignature() { + $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class); + $this->expectExceptionMessage('Invalid JWT signature'); + $token = 'header.payload.nope'; ApiUtils::validateJwtToken($token, 'foo'); } /** * Test validateJwtToken() with a JWT token with a signature generated with the wrong API secret. - * - * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException - * @expectedExceptionMessage Invalid JWT signature */ public function testValidateJwtTokenInvalidSignatureSecret() { + $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class); + $this->expectExceptionMessage('Invalid JWT signature'); + ApiUtils::validateJwtToken(self::generateValidJwtToken('foo'), 'bar'); } /** * Test validateJwtToken() with a JWT token with a an invalid header (not JSON). - * - * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException - * @expectedExceptionMessage Invalid JWT header */ public function testValidateJwtTokenInvalidHeader() { + $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class); + $this->expectExceptionMessage('Invalid JWT header'); + $token = $this->generateCustomJwtToken('notJSON', '{"JSON":1}', 'secret'); ApiUtils::validateJwtToken($token, 'secret'); } /** * Test validateJwtToken() with a JWT token with a an invalid payload (not JSON). - * - * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException - * @expectedExceptionMessage Invalid JWT payload */ public function testValidateJwtTokenInvalidPayload() { + $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class); + $this->expectExceptionMessage('Invalid JWT payload'); + $token = $this->generateCustomJwtToken('{"JSON":1}', 'notJSON', 'secret'); ApiUtils::validateJwtToken($token, 'secret'); } /** * Test validateJwtToken() with a JWT token without issued time. - * - * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException - * @expectedExceptionMessage Invalid JWT issued time */ public function testValidateJwtTokenInvalidTimeEmpty() { + $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class); + $this->expectExceptionMessage('Invalid JWT issued time'); + $token = $this->generateCustomJwtToken('{"JSON":1}', '{"JSON":1}', 'secret'); ApiUtils::validateJwtToken($token, 'secret'); } /** * Test validateJwtToken() with an expired JWT token. - * - * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException - * @expectedExceptionMessage Invalid JWT issued time */ public function testValidateJwtTokenInvalidTimeExpired() { + $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class); + $this->expectExceptionMessage('Invalid JWT issued time'); + $token = $this->generateCustomJwtToken('{"JSON":1}', '{"iat":' . (time() - 600) . '}', 'secret'); ApiUtils::validateJwtToken($token, 'secret'); } /** * Test validateJwtToken() with a JWT token issued in the future. - * - * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException - * @expectedExceptionMessage Invalid JWT issued time */ public function testValidateJwtTokenInvalidTimeFuture() { + $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class); + $this->expectExceptionMessage('Invalid JWT issued time'); + $token = $this->generateCustomJwtToken('{"JSON":1}', '{"iat":' . (time() + 60) . '}', 'secret'); ApiUtils::validateJwtToken($token, 'secret'); } diff --git a/tests/api/controllers/history/HistoryTest.php b/tests/api/controllers/history/HistoryTest.php index f4d3b646..40f26b12 100644 --- a/tests/api/controllers/history/HistoryTest.php +++ b/tests/api/controllers/history/HistoryTest.php @@ -41,7 +41,7 @@ class HistoryTest extends \PHPUnit\Framework\TestCase /** * Before every test, instantiate a new Api with its config, plugins and bookmarks. */ - public function setUp() + protected function setUp(): void { $this->conf = new ConfigManager('tests/utils/config/configJson'); $this->refHistory = new \ReferenceHistory(); @@ -57,7 +57,7 @@ class HistoryTest extends \PHPUnit\Framework\TestCase /** * After every test, remove the test datastore. */ - public function tearDown() + protected function tearDown(): void { @unlink(self::$testHistory); } diff --git a/tests/api/controllers/info/InfoTest.php b/tests/api/controllers/info/InfoTest.php index b5c938e1..cc50d2e3 100644 --- a/tests/api/controllers/info/InfoTest.php +++ b/tests/api/controllers/info/InfoTest.php @@ -47,7 +47,7 @@ class InfoTest extends TestCase /** * Before every test, instantiate a new Api with its config, plugins and bookmarks. */ - public function setUp() + protected function setUp(): void { $this->conf = new ConfigManager('tests/utils/config/configJson'); $this->conf->set('resource.datastore', self::$testDatastore); @@ -67,7 +67,7 @@ class InfoTest extends TestCase /** * After every test, remove the test datastore. */ - public function tearDown() + protected function tearDown(): void { @unlink(self::$testDatastore); } diff --git a/tests/api/controllers/links/DeleteLinkTest.php b/tests/api/controllers/links/DeleteLinkTest.php index 6c2b3698..bd8403cf 100644 --- a/tests/api/controllers/links/DeleteLinkTest.php +++ b/tests/api/controllers/links/DeleteLinkTest.php @@ -56,7 +56,7 @@ class DeleteLinkTest extends \PHPUnit\Framework\TestCase /** * Before each test, instantiate a new Api with its config, plugins and bookmarks. */ - public function setUp() + protected function setUp(): void { $this->conf = new ConfigManager('tests/utils/config/configJson'); $this->conf->set('resource.datastore', self::$testDatastore); @@ -78,7 +78,7 @@ class DeleteLinkTest extends \PHPUnit\Framework\TestCase /** * After each test, remove the test datastore. */ - public function tearDown() + protected function tearDown(): void { @unlink(self::$testDatastore); @unlink(self::$testHistory); @@ -113,11 +113,11 @@ class DeleteLinkTest extends \PHPUnit\Framework\TestCase /** * Test DELETE link endpoint: reach not existing ID. - * - * @expectedException \Shaarli\Api\Exceptions\ApiLinkNotFoundException */ public function testDeleteLink404() { + $this->expectException(\Shaarli\Api\Exceptions\ApiLinkNotFoundException::class); + $id = -1; $this->assertFalse($this->bookmarkService->exists($id)); $env = Environment::mock([ diff --git a/tests/api/controllers/links/GetLinkIdTest.php b/tests/api/controllers/links/GetLinkIdTest.php index 8bb81dc8..3a3aaa7b 100644 --- a/tests/api/controllers/links/GetLinkIdTest.php +++ b/tests/api/controllers/links/GetLinkIdTest.php @@ -55,7 +55,7 @@ class GetLinkIdTest extends \PHPUnit\Framework\TestCase /** * Before each test, instantiate a new Api with its config, plugins and bookmarks. */ - public function setUp() + protected function setUp(): void { $this->conf = new ConfigManager('tests/utils/config/configJson'); $this->conf->set('resource.datastore', self::$testDatastore); @@ -74,7 +74,7 @@ class GetLinkIdTest extends \PHPUnit\Framework\TestCase /** * After each test, remove the test datastore. */ - public function tearDown() + protected function tearDown(): void { @unlink(self::$testDatastore); } @@ -120,12 +120,12 @@ class GetLinkIdTest extends \PHPUnit\Framework\TestCase /** * Test basic getLink service: get non existent link => ApiLinkNotFoundException. - * - * @expectedException Shaarli\Api\Exceptions\ApiLinkNotFoundException - * @expectedExceptionMessage Link not found */ public function testGetLink404() { + $this->expectException(\Shaarli\Api\Exceptions\ApiLinkNotFoundException::class); + $this->expectExceptionMessage('Link not found'); + $env = Environment::mock([ 'REQUEST_METHOD' => 'GET', ]); diff --git a/tests/api/controllers/links/GetLinksTest.php b/tests/api/controllers/links/GetLinksTest.php index d02e6fad..01c40c2f 100644 --- a/tests/api/controllers/links/GetLinksTest.php +++ b/tests/api/controllers/links/GetLinksTest.php @@ -55,7 +55,7 @@ class GetLinksTest extends \PHPUnit\Framework\TestCase /** * Before every test, instantiate a new Api with its config, plugins and bookmarks. */ - public function setUp() + protected function setUp(): void { $this->conf = new ConfigManager('tests/utils/config/configJson'); $this->conf->set('resource.datastore', self::$testDatastore); @@ -74,7 +74,7 @@ class GetLinksTest extends \PHPUnit\Framework\TestCase /** * After every test, remove the test datastore. */ - public function tearDown() + protected function tearDown(): void { @unlink(self::$testDatastore); } diff --git a/tests/api/controllers/links/PostLinkTest.php b/tests/api/controllers/links/PostLinkTest.php index 4e791a04..b1c9008b 100644 --- a/tests/api/controllers/links/PostLinkTest.php +++ b/tests/api/controllers/links/PostLinkTest.php @@ -70,7 +70,7 @@ class PostLinkTest extends TestCase /** * Before every test, instantiate a new Api with its config, plugins and bookmarks. */ - public function setUp() + protected function setUp(): void { $this->conf = new ConfigManager('tests/utils/config/configJson'); $this->conf->set('resource.datastore', self::$testDatastore); @@ -107,7 +107,7 @@ class PostLinkTest extends TestCase /** * After every test, remove the test datastore. */ - public function tearDown() + protected function tearDown(): void { @unlink(self::$testDatastore); @unlink(self::$testHistory); diff --git a/tests/api/controllers/links/PutLinkTest.php b/tests/api/controllers/links/PutLinkTest.php index 302cac0f..3d62a1b1 100644 --- a/tests/api/controllers/links/PutLinkTest.php +++ b/tests/api/controllers/links/PutLinkTest.php @@ -62,7 +62,7 @@ class PutLinkTest extends \PHPUnit\Framework\TestCase /** * Before every test, instantiate a new Api with its config, plugins and bookmarks. */ - public function setUp() + protected function setUp(): void { $this->conf = new ConfigManager('tests/utils/config/configJson'); $this->conf->set('resource.datastore', self::$testDatastore); @@ -91,7 +91,7 @@ class PutLinkTest extends \PHPUnit\Framework\TestCase /** * After every test, remove the test datastore. */ - public function tearDown() + protected function tearDown(): void { @unlink(self::$testDatastore); @unlink(self::$testHistory); @@ -218,12 +218,12 @@ class PutLinkTest extends \PHPUnit\Framework\TestCase /** * Test link update on non existent link => ApiLinkNotFoundException. - * - * @expectedException Shaarli\Api\Exceptions\ApiLinkNotFoundException - * @expectedExceptionMessage Link not found */ public function testGetLink404() { + $this->expectException(\Shaarli\Api\Exceptions\ApiLinkNotFoundException::class); + $this->expectExceptionMessage('Link not found'); + $env = Environment::mock([ 'REQUEST_METHOD' => 'PUT', ]); diff --git a/tests/api/controllers/tags/DeleteTagTest.php b/tests/api/controllers/tags/DeleteTagTest.php index c6748872..0d991b85 100644 --- a/tests/api/controllers/tags/DeleteTagTest.php +++ b/tests/api/controllers/tags/DeleteTagTest.php @@ -57,7 +57,7 @@ class DeleteTagTest extends \PHPUnit\Framework\TestCase /** * Before each test, instantiate a new Api with its config, plugins and bookmarks. */ - public function setUp() + protected function setUp(): void { $this->conf = new ConfigManager('tests/utils/config/configJson'); $this->conf->set('resource.datastore', self::$testDatastore); @@ -79,7 +79,7 @@ class DeleteTagTest extends \PHPUnit\Framework\TestCase /** * After each test, remove the test datastore. */ - public function tearDown() + protected function tearDown(): void { @unlink(self::$testDatastore); @unlink(self::$testHistory); @@ -150,12 +150,12 @@ class DeleteTagTest extends \PHPUnit\Framework\TestCase /** * Test DELETE tag endpoint: reach not existing tag. - * - * @expectedException Shaarli\Api\Exceptions\ApiTagNotFoundException - * @expectedExceptionMessage Tag not found */ public function testDeleteLink404() { + $this->expectException(\Shaarli\Api\Exceptions\ApiTagNotFoundException::class); + $this->expectExceptionMessage('Tag not found'); + $tagName = 'nopenope'; $tags = $this->bookmarkService->bookmarksCountPerTag(); $this->assertFalse(isset($tags[$tagName])); diff --git a/tests/api/controllers/tags/GetTagNameTest.php b/tests/api/controllers/tags/GetTagNameTest.php index b9a81f9b..a2fb89ab 100644 --- a/tests/api/controllers/tags/GetTagNameTest.php +++ b/tests/api/controllers/tags/GetTagNameTest.php @@ -53,7 +53,7 @@ class GetTagNameTest extends \PHPUnit\Framework\TestCase /** * Before each test, instantiate a new Api with its config, plugins and bookmarks. */ - public function setUp() + protected function setUp(): void { $this->conf = new ConfigManager('tests/utils/config/configJson'); $this->conf->set('resource.datastore', self::$testDatastore); @@ -72,7 +72,7 @@ class GetTagNameTest extends \PHPUnit\Framework\TestCase /** * After each test, remove the test datastore. */ - public function tearDown() + protected function tearDown(): void { @unlink(self::$testDatastore); } @@ -117,12 +117,12 @@ class GetTagNameTest extends \PHPUnit\Framework\TestCase /** * Test basic getTag service: get non existent tag => ApiTagNotFoundException. - * - * @expectedException Shaarli\Api\Exceptions\ApiTagNotFoundException - * @expectedExceptionMessage Tag not found */ public function testGetTag404() { + $this->expectException(\Shaarli\Api\Exceptions\ApiTagNotFoundException::class); + $this->expectExceptionMessage('Tag not found'); + $env = Environment::mock([ 'REQUEST_METHOD' => 'GET', ]); diff --git a/tests/api/controllers/tags/GetTagsTest.php b/tests/api/controllers/tags/GetTagsTest.php index 53a3326d..ab666f20 100644 --- a/tests/api/controllers/tags/GetTagsTest.php +++ b/tests/api/controllers/tags/GetTagsTest.php @@ -57,7 +57,7 @@ class GetTagsTest extends \PHPUnit\Framework\TestCase /** * Before every test, instantiate a new Api with its config, plugins and bookmarks. */ - public function setUp() + protected function setUp(): void { $this->conf = new ConfigManager('tests/utils/config/configJson'); $this->conf->set('resource.datastore', self::$testDatastore); @@ -78,7 +78,7 @@ class GetTagsTest extends \PHPUnit\Framework\TestCase /** * After every test, remove the test datastore. */ - public function tearDown() + protected function tearDown(): void { @unlink(self::$testDatastore); } diff --git a/tests/api/controllers/tags/PutTagTest.php b/tests/api/controllers/tags/PutTagTest.php index 2a3cc15a..0845dce1 100644 --- a/tests/api/controllers/tags/PutTagTest.php +++ b/tests/api/controllers/tags/PutTagTest.php @@ -62,7 +62,7 @@ class PutTagTest extends \PHPUnit\Framework\TestCase /** * Before every test, instantiate a new Api with its config, plugins and bookmarks. */ - public function setUp() + protected function setUp(): void { $this->conf = new ConfigManager('tests/utils/config/configJson'); $this->conf->set('resource.datastore', self::$testDatastore); @@ -84,7 +84,7 @@ class PutTagTest extends \PHPUnit\Framework\TestCase /** * After every test, remove the test datastore. */ - public function tearDown() + protected function tearDown(): void { @unlink(self::$testDatastore); @unlink(self::$testHistory); @@ -159,12 +159,12 @@ class PutTagTest extends \PHPUnit\Framework\TestCase /** * Test tag update with an empty new tag name => ApiBadParametersException - * - * @expectedException Shaarli\Api\Exceptions\ApiBadParametersException - * @expectedExceptionMessage New tag name is required in the request body */ public function testPutTagEmpty() { + $this->expectException(\Shaarli\Api\Exceptions\ApiBadParametersException::class); + $this->expectExceptionMessage('New tag name is required in the request body'); + $tagName = 'gnu'; $newName = ''; @@ -194,12 +194,12 @@ class PutTagTest extends \PHPUnit\Framework\TestCase /** * Test tag update on non existent tag => ApiTagNotFoundException. - * - * @expectedException Shaarli\Api\Exceptions\ApiTagNotFoundException - * @expectedExceptionMessage Tag not found */ public function testPutTag404() { + $this->expectException(\Shaarli\Api\Exceptions\ApiTagNotFoundException::class); + $this->expectExceptionMessage('Tag not found'); + $env = Environment::mock([ 'REQUEST_METHOD' => 'PUT', ]); diff --git a/tests/bookmark/BookmarkArrayTest.php b/tests/bookmark/BookmarkArrayTest.php index 0f8f04c5..bad3af8d 100644 --- a/tests/bookmark/BookmarkArrayTest.php +++ b/tests/bookmark/BookmarkArrayTest.php @@ -47,22 +47,22 @@ class BookmarkArrayTest extends TestCase /** * Test adding a bad entry: wrong type - * - * @expectedException Shaarli\Bookmark\Exception\InvalidBookmarkException */ public function testArrayAccessAddBadEntryInstance() { + $this->expectException(\Shaarli\Bookmark\Exception\InvalidBookmarkException::class); + $array = new BookmarkArray(); $array[] = 'nope'; } /** * Test adding a bad entry: no id - * - * @expectedException Shaarli\Bookmark\Exception\InvalidBookmarkException */ public function testArrayAccessAddBadEntryNoId() { + $this->expectException(\Shaarli\Bookmark\Exception\InvalidBookmarkException::class); + $array = new BookmarkArray(); $bookmark = new Bookmark(); $array[] = $bookmark; @@ -70,11 +70,11 @@ class BookmarkArrayTest extends TestCase /** * Test adding a bad entry: no url - * - * @expectedException Shaarli\Bookmark\Exception\InvalidBookmarkException */ public function testArrayAccessAddBadEntryNoUrl() { + $this->expectException(\Shaarli\Bookmark\Exception\InvalidBookmarkException::class); + $array = new BookmarkArray(); $bookmark = (new Bookmark())->setId(11); $array[] = $bookmark; @@ -82,11 +82,11 @@ class BookmarkArrayTest extends TestCase /** * Test adding a bad entry: invalid offset - * - * @expectedException Shaarli\Bookmark\Exception\InvalidBookmarkException */ public function testArrayAccessAddBadEntryOffset() { + $this->expectException(\Shaarli\Bookmark\Exception\InvalidBookmarkException::class); + $array = new BookmarkArray(); $bookmark = (new Bookmark())->setId(11); $bookmark->validate(); @@ -95,11 +95,11 @@ class BookmarkArrayTest extends TestCase /** * Test adding a bad entry: invalid ID type - * - * @expectedException Shaarli\Bookmark\Exception\InvalidBookmarkException */ public function testArrayAccessAddBadEntryIdType() { + $this->expectException(\Shaarli\Bookmark\Exception\InvalidBookmarkException::class); + $array = new BookmarkArray(); $bookmark = (new Bookmark())->setId('nope'); $bookmark->validate(); @@ -108,11 +108,11 @@ class BookmarkArrayTest extends TestCase /** * Test adding a bad entry: ID/offset not consistent - * - * @expectedException Shaarli\Bookmark\Exception\InvalidBookmarkException */ public function testArrayAccessAddBadEntryIdOffset() { + $this->expectException(\Shaarli\Bookmark\Exception\InvalidBookmarkException::class); + $array = new BookmarkArray(); $bookmark = (new Bookmark())->setId(11); $bookmark->validate(); diff --git a/tests/bookmark/BookmarkFileServiceTest.php b/tests/bookmark/BookmarkFileServiceTest.php index a4ec1013..9cff0fb3 100644 --- a/tests/bookmark/BookmarkFileServiceTest.php +++ b/tests/bookmark/BookmarkFileServiceTest.php @@ -66,7 +66,7 @@ class BookmarkFileServiceTest extends TestCase * * Resets test data for each test */ - protected function setUp() + protected function setUp(): void { if (file_exists(self::$testDatastore)) { unlink(self::$testDatastore); @@ -134,11 +134,11 @@ class BookmarkFileServiceTest extends TestCase /** * Test get() method for an undefined bookmark - * - * @expectedException Shaarli\Bookmark\Exception\BookmarkNotFoundException */ public function testGetUndefined() { + $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class); + $this->privateLinkDB->get(666); } @@ -230,13 +230,13 @@ class BookmarkFileServiceTest extends TestCase /** * Test add() method for a bookmark without any field set and without writing the data store - * - * @expectedExceptionMessage Shaarli\Bookmark\Exception\BookmarkNotFoundException */ public function testAddMinimalNoWrite() { + $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class); + $bookmark = new Bookmark(); - $this->privateLinkDB->add($bookmark); + $this->privateLinkDB->add($bookmark, false); $bookmark = $this->privateLinkDB->get(43); $this->assertEquals(43, $bookmark->getId()); @@ -249,34 +249,34 @@ class BookmarkFileServiceTest extends TestCase /** * Test add() method while logged out - * - * @expectedException \Exception - * @expectedExceptionMessage You're not authorized to alter the datastore */ public function testAddLoggedOut() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('You\'re not authorized to alter the datastore'); + $this->publicLinkDB->add(new Bookmark()); } /** * Test add() method with an entry which is not a bookmark instance - * - * @expectedException \Exception - * @expectedExceptionMessage Provided data is invalid */ public function testAddNotABookmark() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Provided data is invalid'); + $this->privateLinkDB->add(['title' => 'hi!']); } /** * Test add() method with a Bookmark already containing an ID - * - * @expectedException \Exception - * @expectedExceptionMessage This bookmarks already exists */ public function testAddWithId() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('This bookmarks already exists'); + $bookmark = new Bookmark(); $bookmark->setId(43); $this->privateLinkDB->add($bookmark); @@ -397,44 +397,44 @@ class BookmarkFileServiceTest extends TestCase /** * Test set() method while logged out - * - * @expectedException \Exception - * @expectedExceptionMessage You're not authorized to alter the datastore */ public function testSetLoggedOut() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('You\'re not authorized to alter the datastore'); + $this->publicLinkDB->set(new Bookmark()); } /** * Test set() method with an entry which is not a bookmark instance - * - * @expectedException \Exception - * @expectedExceptionMessage Provided data is invalid */ public function testSetNotABookmark() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Provided data is invalid'); + $this->privateLinkDB->set(['title' => 'hi!']); } /** * Test set() method with a Bookmark without an ID defined. - * - * @expectedException Shaarli\Bookmark\Exception\BookmarkNotFoundException */ public function testSetWithoutId() { + $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class); + $bookmark = new Bookmark(); $this->privateLinkDB->set($bookmark); } /** * Test set() method with a Bookmark with an unknow ID - * - * @expectedException Shaarli\Bookmark\Exception\BookmarkNotFoundException */ public function testSetWithUnknownId() { + $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class); + $bookmark = new Bookmark(); $bookmark->setId(666); $this->privateLinkDB->set($bookmark); @@ -481,23 +481,23 @@ class BookmarkFileServiceTest extends TestCase /** * Test addOrSet() method while logged out - * - * @expectedException \Exception - * @expectedExceptionMessage You're not authorized to alter the datastore */ public function testAddOrSetLoggedOut() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('You\'re not authorized to alter the datastore'); + $this->publicLinkDB->addOrSet(new Bookmark()); } /** * Test addOrSet() method with an entry which is not a bookmark instance - * - * @expectedException \Exception - * @expectedExceptionMessage Provided data is invalid */ public function testAddOrSetNotABookmark() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Provided data is invalid'); + $this->privateLinkDB->addOrSet(['title' => 'hi!']); } @@ -524,11 +524,11 @@ class BookmarkFileServiceTest extends TestCase /** * Test remove() method with an existing Bookmark - * - * @expectedException Shaarli\Bookmark\Exception\BookmarkNotFoundException */ public function testRemoveExisting() { + $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class); + $bookmark = $this->privateLinkDB->get(42); $this->privateLinkDB->remove($bookmark); @@ -548,34 +548,34 @@ class BookmarkFileServiceTest extends TestCase /** * Test remove() method while logged out - * - * @expectedException \Exception - * @expectedExceptionMessage You're not authorized to alter the datastore */ public function testRemoveLoggedOut() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('You\'re not authorized to alter the datastore'); + $bookmark = $this->privateLinkDB->get(42); $this->publicLinkDB->remove($bookmark); } /** * Test remove() method with an entry which is not a bookmark instance - * - * @expectedException \Exception - * @expectedExceptionMessage Provided data is invalid */ public function testRemoveNotABookmark() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Provided data is invalid'); + $this->privateLinkDB->remove(['title' => 'hi!']); } /** * Test remove() method with a Bookmark with an unknown ID - * - * @expectedException Shaarli\Bookmark\Exception\BookmarkNotFoundException */ public function testRemoveWithUnknownId() { + $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class); + $bookmark = new Bookmark(); $bookmark->setId(666); $this->privateLinkDB->remove($bookmark); @@ -635,15 +635,15 @@ class BookmarkFileServiceTest extends TestCase * to make sure that nothing have been broken in the migration process. * They mostly cover search/filters. Some of them might be redundant with the previous ones. */ - /** * Attempt to instantiate a LinkDB whereas the datastore is not writable * * @expectedException Shaarli\Bookmark\Exception\NotWritableDataStoreException - * @expectedExceptionMessageRegExp #Couldn't load data from the data store file "null".*# */ public function testConstructDatastoreNotWriteable() { + $this->expectExceptionMessageRegExp('#Couldn\'t load data from the data store file "null".*#'); + $conf = new ConfigManager('tests/utils/config/configJson'); $conf->set('resource.datastore', 'null/store.db'); new BookmarkFileService($conf, $this->history, true); diff --git a/tests/bookmark/BookmarkFilterTest.php b/tests/bookmark/BookmarkFilterTest.php index 91e139c2..752631a5 100644 --- a/tests/bookmark/BookmarkFilterTest.php +++ b/tests/bookmark/BookmarkFilterTest.php @@ -213,20 +213,22 @@ class BookmarkFilterTest extends TestCase /** * Use an invalid date format * @expectedException Exception - * @expectedExceptionMessageRegExp /Invalid date format/ */ public function testFilterInvalidDayWithChars() { + $this->expectExceptionMessageRegExp('/Invalid date format/'); + self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, 'Rainy day, dream away'); } /** * Use an invalid date format * @expectedException Exception - * @expectedExceptionMessageRegExp /Invalid date format/ */ public function testFilterInvalidDayDigits() { + $this->expectExceptionMessageRegExp('/Invalid date format/'); + self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, '20'); } @@ -250,11 +252,11 @@ class BookmarkFilterTest extends TestCase /** * No link for this hash - * - * @expectedException \Shaarli\Bookmark\Exception\BookmarkNotFoundException */ public function testFilterUnknownSmallHash() { + $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class); + self::$linkFilter->filter(BookmarkFilter::$FILTER_HASH, 'Iblaah'); } diff --git a/tests/config/ConfigJsonTest.php b/tests/config/ConfigJsonTest.php index 33160eb0..f884b0c6 100644 --- a/tests/config/ConfigJsonTest.php +++ b/tests/config/ConfigJsonTest.php @@ -11,7 +11,7 @@ class ConfigJsonTest extends \PHPUnit\Framework\TestCase */ protected $configIO; - public function setUp() + protected function setUp(): void { $this->configIO = new ConfigJson(); } @@ -38,12 +38,12 @@ class ConfigJsonTest extends \PHPUnit\Framework\TestCase /** * Read a non existent config file -> empty array. - * - * @expectedException \Exception - * @expectedExceptionMessageRegExp /An error occurred while parsing JSON configuration file \([\w\/\.]+\): error code #4/ */ public function testReadInvalidJson() { + $this->expectException(\Exception::class); + $this->expectExceptionMessageRegExp(' /An error occurred while parsing JSON configuration file \\([\\w\\/\\.]+\\): error code #4/'); + $this->configIO->read('tests/utils/config/configInvalid.json.php'); } @@ -110,22 +110,22 @@ class ConfigJsonTest extends \PHPUnit\Framework\TestCase /** * Write to invalid path. - * - * @expectedException \Shaarli\Exceptions\IOException */ public function testWriteInvalidArray() { + $this->expectException(\Shaarli\Exceptions\IOException::class); + $conf = array('conf' => 'value'); @$this->configIO->write(array(), $conf); } /** * Write to invalid path. - * - * @expectedException \Shaarli\Exceptions\IOException */ public function testWriteInvalidBlank() { + $this->expectException(\Shaarli\Exceptions\IOException::class); + $conf = array('conf' => 'value'); @$this->configIO->write('', $conf); } diff --git a/tests/config/ConfigManagerTest.php b/tests/config/ConfigManagerTest.php index 33830bc9..802e6524 100644 --- a/tests/config/ConfigManagerTest.php +++ b/tests/config/ConfigManagerTest.php @@ -14,7 +14,7 @@ class ConfigManagerTest extends \PHPUnit\Framework\TestCase */ protected $conf; - public function setUp() + protected function setUp(): void { $this->conf = new ConfigManager('tests/utils/config/configJson'); } @@ -95,44 +95,44 @@ class ConfigManagerTest extends \PHPUnit\Framework\TestCase /** * Set with an empty key. - * - * @expectedException \Exception - * @expectedExceptionMessageRegExp #^Invalid setting key parameter. String expected, got.*# */ public function testSetEmptyKey() { + $this->expectException(\Exception::class); + $this->expectExceptionMessageRegExp('#^Invalid setting key parameter. String expected, got.*#'); + $this->conf->set('', 'stuff'); } /** * Set with an array key. - * - * @expectedException \Exception - * @expectedExceptionMessageRegExp #^Invalid setting key parameter. String expected, got.*# */ public function testSetArrayKey() { + $this->expectException(\Exception::class); + $this->expectExceptionMessageRegExp('#^Invalid setting key parameter. String expected, got.*#'); + $this->conf->set(array('foo' => 'bar'), 'stuff'); } /** * Remove with an empty key. - * - * @expectedException \Exception - * @expectedExceptionMessageRegExp #^Invalid setting key parameter. String expected, got.*# */ public function testRmoveEmptyKey() { + $this->expectException(\Exception::class); + $this->expectExceptionMessageRegExp('#^Invalid setting key parameter. String expected, got.*#'); + $this->conf->remove(''); } /** * Try to write the config without mandatory parameter (e.g. 'login'). - * - * @expectedException Shaarli\Config\Exception\MissingFieldConfigException */ public function testWriteMissingParameter() { + $this->expectException(\Shaarli\Config\Exception\MissingFieldConfigException::class); + $this->conf->setConfigFile('tests/utils/config/configTmp'); $this->assertFalse(file_exists($this->conf->getConfigFileExt())); $this->conf->reload(); diff --git a/tests/config/ConfigPhpTest.php b/tests/config/ConfigPhpTest.php index fb91b51b..a9aa80f5 100644 --- a/tests/config/ConfigPhpTest.php +++ b/tests/config/ConfigPhpTest.php @@ -15,7 +15,7 @@ class ConfigPhpTest extends \PHPUnit\Framework\TestCase */ protected $configIO; - public function setUp() + protected function setUp(): void { $this->configIO = new ConfigPhp(); } diff --git a/tests/config/ConfigPluginTest.php b/tests/config/ConfigPluginTest.php index b2cc0045..3a45f623 100644 --- a/tests/config/ConfigPluginTest.php +++ b/tests/config/ConfigPluginTest.php @@ -46,11 +46,11 @@ class ConfigPluginTest extends \PHPUnit\Framework\TestCase /** * Test save_plugin_config with invalid data. - * - * @expectedException Shaarli\Config\Exception\PluginConfigOrderException */ public function testSavePluginConfigInvalid() { + $this->expectException(\Shaarli\Config\Exception\PluginConfigOrderException::class); + $data = array( 'plugin2' => 0, 'plugin3' => 0, diff --git a/tests/feed/CachedPageTest.php b/tests/feed/CachedPageTest.php index 2e716432..25d640d3 100644 --- a/tests/feed/CachedPageTest.php +++ b/tests/feed/CachedPageTest.php @@ -17,7 +17,7 @@ class CachedPageTest extends \PHPUnit\Framework\TestCase /** * Create the cache directory if needed */ - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { if (!is_dir(self::$testCacheDir)) { mkdir(self::$testCacheDir); @@ -28,7 +28,7 @@ class CachedPageTest extends \PHPUnit\Framework\TestCase /** * Reset the page cache */ - public function setUp() + protected function setUp(): void { if (file_exists(self::$filename)) { unlink(self::$filename); diff --git a/tests/formatter/BookmarkDefaultFormatterTest.php b/tests/formatter/BookmarkDefaultFormatterTest.php index cf48b00b..9ea86c14 100644 --- a/tests/formatter/BookmarkDefaultFormatterTest.php +++ b/tests/formatter/BookmarkDefaultFormatterTest.php @@ -25,7 +25,7 @@ class BookmarkDefaultFormatterTest extends TestCase /** * Initialize formatter instance. */ - public function setUp() + protected function setUp(): void { copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php'); $this->conf = new ConfigManager(self::$testConf); diff --git a/tests/formatter/BookmarkMarkdownFormatterTest.php b/tests/formatter/BookmarkMarkdownFormatterTest.php index 3e72d1ee..a7729416 100644 --- a/tests/formatter/BookmarkMarkdownFormatterTest.php +++ b/tests/formatter/BookmarkMarkdownFormatterTest.php @@ -25,7 +25,7 @@ class BookmarkMarkdownFormatterTest extends TestCase /** * Initialize formatter instance. */ - public function setUp() + protected function setUp(): void { copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php'); $this->conf = new ConfigManager(self::$testConf); diff --git a/tests/formatter/BookmarkRawFormatterTest.php b/tests/formatter/BookmarkRawFormatterTest.php index 4491b035..76cf1172 100644 --- a/tests/formatter/BookmarkRawFormatterTest.php +++ b/tests/formatter/BookmarkRawFormatterTest.php @@ -25,7 +25,7 @@ class BookmarkRawFormatterTest extends TestCase /** * Initialize formatter instance. */ - public function setUp() + protected function setUp(): void { copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php'); $this->conf = new ConfigManager(self::$testConf); diff --git a/tests/formatter/FormatterFactoryTest.php b/tests/formatter/FormatterFactoryTest.php index 5adf3ffd..6aab6a61 100644 --- a/tests/formatter/FormatterFactoryTest.php +++ b/tests/formatter/FormatterFactoryTest.php @@ -24,7 +24,7 @@ class FormatterFactoryTest extends TestCase /** * Initialize FormatterFactory instance */ - public function setUp() + protected function setUp(): void { copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php'); $this->conf = new ConfigManager(self::$testConf); diff --git a/tests/front/controller/admin/ManageShaareControllerTest/SaveBookmarkTest.php b/tests/front/controller/admin/ManageShaareControllerTest/SaveBookmarkTest.php index dabcd60d..58eaaa9b 100644 --- a/tests/front/controller/admin/ManageShaareControllerTest/SaveBookmarkTest.php +++ b/tests/front/controller/admin/ManageShaareControllerTest/SaveBookmarkTest.php @@ -43,7 +43,7 @@ class SaveBookmarkTest extends TestCase 'lf_description' => 'Provided description.', 'lf_tags' => 'abc def', 'lf_private' => '1', - 'returnurl' => 'http://shaarli.tld/subfolder/admin/add-shaare' + 'returnurl' => 'http://shaarli/subfolder/admin/add-shaare' ]; $request = $this->createMock(Request::class); @@ -124,7 +124,7 @@ class SaveBookmarkTest extends TestCase 'lf_description' => 'Provided description.', 'lf_tags' => 'abc def', 'lf_private' => '1', - 'returnurl' => 'http://shaarli.tld/subfolder/?page=2' + 'returnurl' => 'http://shaarli/subfolder/?page=2' ]; $request = $this->createMock(Request::class); diff --git a/tests/front/controller/admin/SessionFilterControllerTest.php b/tests/front/controller/admin/SessionFilterControllerTest.php index d306c6e9..c4253167 100644 --- a/tests/front/controller/admin/SessionFilterControllerTest.php +++ b/tests/front/controller/admin/SessionFilterControllerTest.php @@ -31,7 +31,7 @@ class SessionFilterControllerTest extends TestCase { $arg = ['visibility' => 'private']; - $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/subfolder/controller/?searchtag=abc']; + $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller/?searchtag=abc'; $this->container->loginManager->method('isLoggedIn')->willReturn(true); $this->container->sessionManager @@ -57,7 +57,7 @@ class SessionFilterControllerTest extends TestCase { $arg = ['visibility' => 'private']; - $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/subfolder/controller/?searchtag=abc']; + $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller/?searchtag=abc'; $this->container->loginManager->method('isLoggedIn')->willReturn(true); $this->container->sessionManager @@ -121,7 +121,7 @@ class SessionFilterControllerTest extends TestCase { $arg = ['visibility' => 'test']; - $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/subfolder/controller/?searchtag=abc']; + $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller/?searchtag=abc'; $this->container->loginManager->method('isLoggedIn')->willReturn(true); $this->container->sessionManager @@ -151,7 +151,7 @@ class SessionFilterControllerTest extends TestCase { $arg = ['visibility' => 'test']; - $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/subfolder/controller/?searchtag=abc']; + $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller/?searchtag=abc'; $this->container->loginManager = $this->createMock(LoginManager::class); $this->container->loginManager->method('isLoggedIn')->willReturn(false); diff --git a/tests/front/controller/visitor/PublicSessionFilterControllerTest.php b/tests/front/controller/visitor/PublicSessionFilterControllerTest.php index 06352750..b45fbe53 100644 --- a/tests/front/controller/visitor/PublicSessionFilterControllerTest.php +++ b/tests/front/controller/visitor/PublicSessionFilterControllerTest.php @@ -28,7 +28,7 @@ class PublicSessionFilterControllerTest extends TestCase */ public function testLinksPerPage(): void { - $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/subfolder/controller/?searchtag=abc']; + $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller/?searchtag=abc'; $request = $this->createMock(Request::class); $request->method('getParam')->with('nb')->willReturn('8'); @@ -74,7 +74,7 @@ class PublicSessionFilterControllerTest extends TestCase */ public function testUntaggedOnly(): void { - $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/subfolder/controller/?searchtag=abc']; + $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller/?searchtag=abc'; $request = $this->createMock(Request::class); $response = new Response(); @@ -97,7 +97,7 @@ class PublicSessionFilterControllerTest extends TestCase */ public function testUntaggedOnlyToggleOff(): void { - $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/subfolder/controller/?searchtag=abc']; + $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller/?searchtag=abc'; $request = $this->createMock(Request::class); $response = new Response(); diff --git a/tests/front/controller/visitor/ShaarliVisitorControllerTest.php b/tests/front/controller/visitor/ShaarliVisitorControllerTest.php index 316ce49c..00188c02 100644 --- a/tests/front/controller/visitor/ShaarliVisitorControllerTest.php +++ b/tests/front/controller/visitor/ShaarliVisitorControllerTest.php @@ -110,7 +110,7 @@ class ShaarliVisitorControllerTest extends TestCase */ public function testRedirectFromRefererDefault(): void { - $this->container->environment['HTTP_REFERER'] = 'http://shaarli.tld/subfolder/controller?query=param&other=2'; + $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller?query=param&other=2'; $response = new Response(); @@ -125,7 +125,7 @@ class ShaarliVisitorControllerTest extends TestCase */ public function testRedirectFromRefererWithUnmatchedLoopTerm(): void { - $this->container->environment['HTTP_REFERER'] = 'http://shaarli.tld/subfolder/controller?query=param&other=2'; + $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller?query=param&other=2'; $response = new Response(); @@ -140,7 +140,7 @@ class ShaarliVisitorControllerTest extends TestCase */ public function testRedirectFromRefererWithMatchingLoopTermInPath(): void { - $this->container->environment['HTTP_REFERER'] = 'http://shaarli.tld/subfolder/controller?query=param&other=2'; + $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller?query=param&other=2'; $response = new Response(); @@ -155,7 +155,7 @@ class ShaarliVisitorControllerTest extends TestCase */ public function testRedirectFromRefererWithMatchingLoopTermInQueryParam(): void { - $this->container->environment['HTTP_REFERER'] = 'http://shaarli.tld/subfolder/controller?query=param&other=2'; + $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller?query=param&other=2'; $response = new Response(); @@ -171,7 +171,7 @@ class ShaarliVisitorControllerTest extends TestCase */ public function testRedirectFromRefererWithMatchingLoopTermInQueryValue(): void { - $this->container->environment['HTTP_REFERER'] = 'http://shaarli.tld/subfolder/controller?query=param&other=2'; + $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller?query=param&other=2'; $response = new Response(); @@ -187,7 +187,7 @@ class ShaarliVisitorControllerTest extends TestCase */ public function testRedirectFromRefererWithLoopTermInDomain(): void { - $this->container->environment['HTTP_REFERER'] = 'http://shaarli.tld/subfolder/controller?query=param&other=2'; + $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller?query=param&other=2'; $response = new Response(); @@ -203,7 +203,7 @@ class ShaarliVisitorControllerTest extends TestCase */ public function testRedirectFromRefererWithMatchingClearedParam(): void { - $this->container->environment['HTTP_REFERER'] = 'http://shaarli.tld/subfolder/controller?query=param&other=2'; + $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller?query=param&other=2'; $response = new Response(); @@ -212,4 +212,35 @@ class ShaarliVisitorControllerTest extends TestCase static::assertSame(302, $result->getStatusCode()); static::assertSame(['/subfolder/controller?other=2'], $result->getHeader('location')); } + + /** + * Test redirectFromReferer() - From another domain -> we ignore the given referrer. + */ + public function testRedirectExternalReferer(): void + { + $this->container->environment['HTTP_REFERER'] = 'http://other.domain.tld/controller?query=param&other=2'; + + $response = new Response(); + + $result = $this->controller->redirectFromReferer($this->request, $response, ['query'], ['query']); + + static::assertSame(302, $result->getStatusCode()); + static::assertSame(['/subfolder/'], $result->getHeader('location')); + } + + /** + * Test redirectFromReferer() - From another domain -> we ignore the given referrer. + */ + public function testRedirectExternalRefererExplicitDomainName(): void + { + $this->container->environment['SERVER_NAME'] = 'my.shaarli.tld'; + $this->container->environment['HTTP_REFERER'] = 'http://your.shaarli.tld/controller?query=param&other=2'; + + $response = new Response(); + + $result = $this->controller->redirectFromReferer($this->request, $response, ['query'], ['query']); + + static::assertSame(302, $result->getStatusCode()); + static::assertSame(['/subfolder/'], $result->getHeader('location')); + } } diff --git a/tests/languages/fr/LanguagesFrTest.php b/tests/languages/fr/LanguagesFrTest.php index b8b7ca3a..e412b5bc 100644 --- a/tests/languages/fr/LanguagesFrTest.php +++ b/tests/languages/fr/LanguagesFrTest.php @@ -27,7 +27,7 @@ class LanguagesFrTest extends \PHPUnit\Framework\TestCase /** * Init: force French */ - public function setUp() + protected function setUp(): void { $this->conf = new ConfigManager(self::$configFile); $this->conf->set('translation.language', 'fr'); @@ -36,7 +36,7 @@ class LanguagesFrTest extends \PHPUnit\Framework\TestCase /** * Reset the locale since gettext seems to mess with it, making it too long */ - public static function tearDownAfterClass() + public static function tearDownAfterClass(): void { if (! empty(getenv('UT_LOCALE'))) { setlocale(LC_ALL, getenv('UT_LOCALE')); diff --git a/tests/legacy/LegacyLinkDBTest.php b/tests/legacy/LegacyLinkDBTest.php index 0884ad03..819bc272 100644 --- a/tests/legacy/LegacyLinkDBTest.php +++ b/tests/legacy/LegacyLinkDBTest.php @@ -52,7 +52,7 @@ class LegacyLinkDBTest extends \PHPUnit\Framework\TestCase * * Resets test data for each test */ - protected function setUp() + protected function setUp(): void { if (file_exists(self::$testDatastore)) { unlink(self::$testDatastore); @@ -101,10 +101,11 @@ class LegacyLinkDBTest extends \PHPUnit\Framework\TestCase * Attempt to instantiate a LinkDB whereas the datastore is not writable * * @expectedException Shaarli\Exceptions\IOException - * @expectedExceptionMessageRegExp /Error accessing "null"/ */ public function testConstructDatastoreNotWriteable() { + $this->expectExceptionMessageRegExp('/Error accessing "null"/'); + new LegacyLinkDB('null/store.db', false, false); } @@ -420,22 +421,22 @@ class LegacyLinkDBTest extends \PHPUnit\Framework\TestCase /** * Test filterHash() with an invalid smallhash. - * - * @expectedException \Shaarli\Bookmark\Exception\BookmarkNotFoundException */ public function testFilterHashInValid1() { + $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class); + $request = 'blabla'; self::$publicLinkDB->filterHash($request); } /** * Test filterHash() with an empty smallhash. - * - * @expectedException \Shaarli\Bookmark\Exception\BookmarkNotFoundException */ public function testFilterHashInValid() { + $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class); + self::$publicLinkDB->filterHash(''); } diff --git a/tests/legacy/LegacyLinkFilterTest.php b/tests/legacy/LegacyLinkFilterTest.php index ba9ec529..9db921a9 100644 --- a/tests/legacy/LegacyLinkFilterTest.php +++ b/tests/legacy/LegacyLinkFilterTest.php @@ -34,7 +34,7 @@ class LegacyLinkFilterTest extends \PHPUnit\Framework\TestCase /** * Instantiate linkFilter with ReferenceLinkDB data. */ - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { self::$refDB = new ReferenceLinkDB(true); self::$refDB->write(self::$testDatastore); @@ -198,20 +198,22 @@ class LegacyLinkFilterTest extends \PHPUnit\Framework\TestCase /** * Use an invalid date format * @expectedException Exception - * @expectedExceptionMessageRegExp /Invalid date format/ */ public function testFilterInvalidDayWithChars() { + $this->expectExceptionMessageRegExp('/Invalid date format/'); + self::$linkFilter->filter(LegacyLinkFilter::$FILTER_DAY, 'Rainy day, dream away'); } /** * Use an invalid date format * @expectedException Exception - * @expectedExceptionMessageRegExp /Invalid date format/ */ public function testFilterInvalidDayDigits() { + $this->expectExceptionMessageRegExp('/Invalid date format/'); + self::$linkFilter->filter(LegacyLinkFilter::$FILTER_DAY, '20'); } @@ -235,11 +237,11 @@ class LegacyLinkFilterTest extends \PHPUnit\Framework\TestCase /** * No link for this hash - * - * @expectedException \Shaarli\Bookmark\Exception\BookmarkNotFoundException */ public function testFilterUnknownSmallHash() { + $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class); + self::$linkFilter->filter(LegacyLinkFilter::$FILTER_HASH, 'Iblaah'); } diff --git a/tests/legacy/LegacyUpdaterTest.php b/tests/legacy/LegacyUpdaterTest.php index 7c429811..acfac530 100644 --- a/tests/legacy/LegacyUpdaterTest.php +++ b/tests/legacy/LegacyUpdaterTest.php @@ -40,7 +40,7 @@ class LegacyUpdaterTest extends \PHPUnit\Framework\TestCase /** * Executed before each test. */ - public function setUp() + protected function setUp(): void { copy('tests/utils/config/configJson.json.php', self::$configFile .'.json.php'); $this->conf = new ConfigManager(self::$configFile); @@ -82,10 +82,11 @@ class LegacyUpdaterTest extends \PHPUnit\Framework\TestCase * Test errors in UpdaterUtils::write_updates_file(): empty updates file. * * @expectedException Exception - * @expectedExceptionMessageRegExp /Updates file path is not set(.*)/ */ public function testWriteEmptyUpdatesFile() { + $this->expectExceptionMessageRegExp('/Updates file path is not set(.*)/'); + UpdaterUtils::write_updates_file('', array('test')); } @@ -93,10 +94,11 @@ class LegacyUpdaterTest extends \PHPUnit\Framework\TestCase * Test errors in UpdaterUtils::write_updates_file(): not writable updates file. * * @expectedException Exception - * @expectedExceptionMessageRegExp /Unable to write(.*)/ */ public function testWriteUpdatesFileNotWritable() { + $this->expectExceptionMessageRegExp('/Unable to write(.*)/'); + $updatesFile = $this->conf->get('resource.data_dir') . '/updates.txt'; touch($updatesFile); chmod($updatesFile, 0444); @@ -161,11 +163,11 @@ class LegacyUpdaterTest extends \PHPUnit\Framework\TestCase /** * Test Update failed. - * - * @expectedException \Exception */ public function testUpdateFailed() { + $this->expectException(\Exception::class); + $updates = array( 'updateMethodDummy1', 'updateMethodDummy2', @@ -754,7 +756,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; if (isset($_SESSION['warnings'])) { unset($_SESSION['warnings']); } - + $updater = new LegacyUpdater([], [], $this->conf, true, $_SESSION); $this->assertTrue($updater->updateMethodWebThumbnailer()); $this->assertFalse($this->conf->exists('thumbnail')); diff --git a/tests/netscape/BookmarkExportTest.php b/tests/netscape/BookmarkExportTest.php index 509da51d..a6eacae4 100644 --- a/tests/netscape/BookmarkExportTest.php +++ b/tests/netscape/BookmarkExportTest.php @@ -54,7 +54,7 @@ class BookmarkExportTest extends TestCase /** * Instantiate reference data */ - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { static::$conf = new ConfigManager('tests/utils/config/configJson'); static::$conf->set('resource.datastore', static::$testDatastore); @@ -78,10 +78,11 @@ class BookmarkExportTest extends TestCase /** * Attempt to export an invalid link selection * @expectedException Exception - * @expectedExceptionMessageRegExp /Invalid export selection/ */ public function testFilterAndFormatInvalid() { + $this->expectExceptionMessageRegExp('/Invalid export selection/'); + $this->netscapeBookmarkUtils->filterAndFormat( self::$formatter, 'derp', diff --git a/tests/netscape/BookmarkImportTest.php b/tests/netscape/BookmarkImportTest.php index f678e26b..89ae4aa7 100644 --- a/tests/netscape/BookmarkImportTest.php +++ b/tests/netscape/BookmarkImportTest.php @@ -75,7 +75,7 @@ class BookmarkImportTest extends TestCase */ protected static $defaultTimeZone; - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { self::$defaultTimeZone = date_default_timezone_get(); // Timezone without DST for test consistency @@ -85,7 +85,7 @@ class BookmarkImportTest extends TestCase /** * Resets test data before each test */ - protected function setUp() + protected function setUp(): void { if (file_exists(self::$testDatastore)) { unlink(self::$testDatastore); @@ -104,12 +104,12 @@ class BookmarkImportTest extends TestCase /** * Delete history file. */ - public function tearDown() + protected function tearDown(): void { @unlink(self::$historyFilePath); } - public static function tearDownAfterClass() + public static function tearDownAfterClass(): void { date_default_timezone_set(self::$defaultTimeZone); } diff --git a/tests/plugins/PluginAddlinkTest.php b/tests/plugins/PluginAddlinkTest.php index aa5c6988..1f60d289 100644 --- a/tests/plugins/PluginAddlinkTest.php +++ b/tests/plugins/PluginAddlinkTest.php @@ -14,7 +14,7 @@ class PluginAddlinkTest extends \PHPUnit\Framework\TestCase /** * Reset plugin path. */ - public function setUp() + protected function setUp(): void { PluginManager::$PLUGINS_PATH = 'plugins'; } diff --git a/tests/plugins/PluginArchiveorgTest.php b/tests/plugins/PluginArchiveorgTest.php index b9a67adb..9c19752c 100644 --- a/tests/plugins/PluginArchiveorgTest.php +++ b/tests/plugins/PluginArchiveorgTest.php @@ -1,10 +1,12 @@ savedScriptName = $_SERVER['SCRIPT_NAME'] ?? null; + $_SERVER['SCRIPT_NAME'] = '/index.php'; + } + + public function tearDown(): void + { + unset($_SERVER['SERVER_PORT']); + unset($_SERVER['SERVER_NAME']); + $_SERVER['SCRIPT_NAME'] = $this->savedScriptName; } /** * Test render_linklist hook on external bookmarks. */ - public function testArchiveorgLinklistOnExternalLinks() + public function testArchiveorgLinklistOnExternalLinks(): void { $str = 'http://randomstr.com/test'; @@ -56,16 +73,16 @@ class PluginArchiveorgTest extends \PHPUnit\Framework\TestCase /** * Test render_linklist hook on internal bookmarks. */ - public function testArchiveorgLinklistOnInternalLinks() + public function testArchiveorgLinklistOnInternalLinks(): void { - $internalLink1 = 'http://shaarli.shaarli/?qvMAqg'; - $internalLinkRealURL1 = '?qvMAqg'; + $internalLink1 = 'http://shaarli.shaarli/shaare/qvMAqg'; + $internalLinkRealURL1 = '/shaare/qvMAqg'; - $internalLink2 = 'http://shaarli.shaarli/?2_7zww'; - $internalLinkRealURL2 = '?2_7zww'; + $internalLink2 = 'http://shaarli.shaarli/shaare/2_7zww'; + $internalLinkRealURL2 = '/shaare/2_7zww'; - $internalLink3 = 'http://shaarli.shaarli/?z7u-_Q'; - $internalLinkRealURL3 = '?z7u-_Q'; + $internalLink3 = 'http://shaarli.shaarli/shaare/z7u-_Q'; + $internalLinkRealURL3 = '/shaare/z7u-_Q'; $data = array( 'title' => $internalLink1, diff --git a/tests/plugins/PluginDefaultColorsTest.php b/tests/plugins/PluginDefaultColorsTest.php index 9835dfa3..240bb4b2 100644 --- a/tests/plugins/PluginDefaultColorsTest.php +++ b/tests/plugins/PluginDefaultColorsTest.php @@ -19,7 +19,7 @@ class PluginDefaultColorsTest extends TestCase /** * Reset plugin path */ - public function setUp() + protected function setUp(): void { PluginManager::$PLUGINS_PATH = 'sandbox'; mkdir(PluginManager::$PLUGINS_PATH . '/default_colors/'); @@ -32,7 +32,7 @@ class PluginDefaultColorsTest extends TestCase /** * Remove sandbox files and folder */ - public function tearDown() + protected function tearDown(): void { if (file_exists('sandbox/default_colors/default_colors.css.template')) { unlink('sandbox/default_colors/default_colors.css.template'); diff --git a/tests/plugins/PluginIssoTest.php b/tests/plugins/PluginIssoTest.php index 99477205..2bbb93d2 100644 --- a/tests/plugins/PluginIssoTest.php +++ b/tests/plugins/PluginIssoTest.php @@ -2,6 +2,7 @@ namespace Shaarli\Plugin\Isso; use DateTime; +use PHPUnit\Framework\TestCase; use Shaarli\Bookmark\Bookmark; use Shaarli\Config\ConfigManager; use Shaarli\Plugin\PluginManager; @@ -13,12 +14,12 @@ require_once 'plugins/isso/isso.php'; * * Test the Isso plugin (comment system). */ -class PluginIssoTest extends \PHPUnit\Framework\TestCase +class PluginIssoTest extends TestCase { /** * Reset plugin path */ - public function setUp() + public function setUp(): void { PluginManager::$PLUGINS_PATH = 'plugins'; } @@ -26,7 +27,7 @@ class PluginIssoTest extends \PHPUnit\Framework\TestCase /** * Test Isso init without errors. */ - public function testIssoInitNoError() + public function testIssoInitNoError(): void { $conf = new ConfigManager(''); $conf->set('plugins.ISSO_SERVER', 'value'); @@ -37,7 +38,7 @@ class PluginIssoTest extends \PHPUnit\Framework\TestCase /** * Test Isso init with errors. */ - public function testIssoInitError() + public function testIssoInitError(): void { $conf = new ConfigManager(''); $errors = isso_init($conf); @@ -47,7 +48,7 @@ class PluginIssoTest extends \PHPUnit\Framework\TestCase /** * Test render_linklist hook with valid settings to display the comment form. */ - public function testIssoDisplayed() + public function testIssoDisplayed(): void { $conf = new ConfigManager(''); $conf->set('plugins.ISSO_SERVER', 'value'); @@ -87,7 +88,7 @@ class PluginIssoTest extends \PHPUnit\Framework\TestCase /** * Test isso plugin when multiple bookmarks are displayed (shouldn't be displayed). */ - public function testIssoMultipleLinks() + public function testIssoMultipleLinks(): void { $conf = new ConfigManager(''); $conf->set('plugins.ISSO_SERVER', 'value'); @@ -115,14 +116,14 @@ class PluginIssoTest extends \PHPUnit\Framework\TestCase $processed = hook_isso_render_linklist($data, $conf); // link_plugin should be added for the icon - $this->assertContains('', $processed['links'][0]['link_plugin'][0]); - $this->assertContains('', $processed['links'][1]['link_plugin'][0]); + $this->assertContains('', $processed['links'][0]['link_plugin'][0]); + $this->assertContains('', $processed['links'][1]['link_plugin'][0]); } /** * Test isso plugin when using search (shouldn't be displayed). */ - public function testIssoNotDisplayedWhenSearch() + public function testIssoNotDisplayedWhenSearch(): void { $conf = new ConfigManager(''); $conf->set('plugins.ISSO_SERVER', 'value'); @@ -145,13 +146,13 @@ class PluginIssoTest extends \PHPUnit\Framework\TestCase $processed = hook_isso_render_linklist($data, $conf); // link_plugin should be added for the icon - $this->assertContains('', $processed['links'][0]['link_plugin'][0]); + $this->assertContains('', $processed['links'][0]['link_plugin'][0]); } /** * Test isso plugin without server configuration (shouldn't be displayed). */ - public function testIssoWithoutConf() + public function testIssoWithoutConf(): void { $data = 'abc'; $conf = new ConfigManager(''); diff --git a/tests/plugins/PluginPlayvideosTest.php b/tests/plugins/PluginPlayvideosTest.php index b7b6ce53..de1a1aec 100644 --- a/tests/plugins/PluginPlayvideosTest.php +++ b/tests/plugins/PluginPlayvideosTest.php @@ -19,7 +19,7 @@ class PluginPlayvideosTest extends \PHPUnit\Framework\TestCase /** * Reset plugin path */ - public function setUp() + protected function setUp(): void { PluginManager::$PLUGINS_PATH = 'plugins'; } diff --git a/tests/plugins/PluginPubsubhubbubTest.php b/tests/plugins/PluginPubsubhubbubTest.php index e66f484e..d30c3703 100644 --- a/tests/plugins/PluginPubsubhubbubTest.php +++ b/tests/plugins/PluginPubsubhubbubTest.php @@ -21,7 +21,7 @@ class PluginPubsubhubbubTest extends \PHPUnit\Framework\TestCase /** * Reset plugin path */ - public function setUp() + protected function setUp(): void { PluginManager::$PLUGINS_PATH = 'plugins'; } diff --git a/tests/plugins/PluginQrcodeTest.php b/tests/plugins/PluginQrcodeTest.php index c9f8c733..bc6be0eb 100644 --- a/tests/plugins/PluginQrcodeTest.php +++ b/tests/plugins/PluginQrcodeTest.php @@ -19,7 +19,7 @@ class PluginQrcodeTest extends \PHPUnit\Framework\TestCase /** * Reset plugin path */ - public function setUp() + protected function setUp(): void { PluginManager::$PLUGINS_PATH = 'plugins'; } diff --git a/tests/plugins/PluginWallabagTest.php b/tests/plugins/PluginWallabagTest.php index 79751921..372929ea 100644 --- a/tests/plugins/PluginWallabagTest.php +++ b/tests/plugins/PluginWallabagTest.php @@ -15,7 +15,7 @@ class PluginWallabagTest extends \PHPUnit\Framework\TestCase /** * Reset plugin path */ - public function setUp() + protected function setUp(): void { PluginManager::$PLUGINS_PATH = 'plugins'; } diff --git a/tests/plugins/WallabagInstanceTest.php b/tests/plugins/WallabagInstanceTest.php index a3cd9076..4cb0d4cc 100644 --- a/tests/plugins/WallabagInstanceTest.php +++ b/tests/plugins/WallabagInstanceTest.php @@ -14,7 +14,7 @@ class WallabagInstanceTest extends \PHPUnit\Framework\TestCase /** * Reset plugin path */ - public function setUp() + protected function setUp(): void { $this->instance = 'http://some.url'; } diff --git a/tests/render/PageCacheManagerTest.php b/tests/render/PageCacheManagerTest.php index c258f45f..4aa7e179 100644 --- a/tests/render/PageCacheManagerTest.php +++ b/tests/render/PageCacheManagerTest.php @@ -29,7 +29,7 @@ class PageCacheManagerTest extends TestCase /** * Populate the cache with dummy files */ - public function setUp() + protected function setUp(): void { $this->cacheManager = new PageCacheManager(static::$testCacheDir, true); @@ -48,7 +48,7 @@ class PageCacheManagerTest extends TestCase /** * Remove dummycache folder after each tests. */ - public function tearDown() + protected function tearDown(): void { array_map('unlink', glob(self::$testCacheDir . '/*')); rmdir(self::$testCacheDir); diff --git a/tests/security/BanManagerTest.php b/tests/security/BanManagerTest.php index bba7c8ad..2fef82f5 100644 --- a/tests/security/BanManagerTest.php +++ b/tests/security/BanManagerTest.php @@ -32,7 +32,7 @@ class BanManagerTest extends TestCase /** * Prepare or reset test resources */ - public function setUp() + protected function setUp(): void { if (file_exists($this->banFile)) { unlink($this->banFile); diff --git a/tests/security/LoginManagerTest.php b/tests/security/LoginManagerTest.php index f242be09..cc9aa647 100644 --- a/tests/security/LoginManagerTest.php +++ b/tests/security/LoginManagerTest.php @@ -63,7 +63,7 @@ class LoginManagerTest extends TestCase /** * Prepare or reset test resources */ - public function setUp() + protected function setUp(): void { if (file_exists($this->banFile)) { unlink($this->banFile); diff --git a/tests/security/SessionManagerTest.php b/tests/security/SessionManagerTest.php index 11a59f9c..27e3b1a9 100644 --- a/tests/security/SessionManagerTest.php +++ b/tests/security/SessionManagerTest.php @@ -24,7 +24,7 @@ class SessionManagerTest extends TestCase /** * Assign reference data */ - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { self::$sidHashes = \ReferenceSessionIdHashes::getHashes(); } @@ -32,7 +32,7 @@ class SessionManagerTest extends TestCase /** * Initialize or reset test resources */ - public function setUp() + protected function setUp(): void { $this->conf = new \FakeConfigManager([ 'credentials.login' => 'johndoe', diff --git a/tests/updater/UpdaterTest.php b/tests/updater/UpdaterTest.php index a7dd70bf..5cfcd5db 100644 --- a/tests/updater/UpdaterTest.php +++ b/tests/updater/UpdaterTest.php @@ -42,7 +42,7 @@ class UpdaterTest extends TestCase /** * Executed before each test. */ - public function setUp() + protected function setUp(): void { $this->refDB = new \ReferenceLinkDB(); $this->refDB->write(self::$testDatastore); @@ -89,10 +89,11 @@ class UpdaterTest extends TestCase * Test errors in UpdaterUtils::write_updates_file(): empty updates file. * * @expectedException Exception - * @expectedExceptionMessageRegExp /Updates file path is not set(.*)/ */ public function testWriteEmptyUpdatesFile() { + $this->expectExceptionMessageRegExp('/Updates file path is not set(.*)/'); + UpdaterUtils::write_updates_file('', array('test')); } @@ -100,10 +101,11 @@ class UpdaterTest extends TestCase * Test errors in UpdaterUtils::write_updates_file(): not writable updates file. * * @expectedException Exception - * @expectedExceptionMessageRegExp /Unable to write(.*)/ */ public function testWriteUpdatesFileNotWritable() { + $this->expectExceptionMessageRegExp('/Unable to write(.*)/'); + $updatesFile = $this->conf->get('resource.data_dir') . '/updates.txt'; touch($updatesFile); chmod($updatesFile, 0444); @@ -168,11 +170,11 @@ class UpdaterTest extends TestCase /** * Test Update failed. - * - * @expectedException \Exception */ public function testUpdateFailed() { + $this->expectException(\Exception::class); + $updates = array( 'updateMethodDummy1', 'updateMethodDummy2', diff --git a/tpl/vintage/editlink.html b/tpl/vintage/editlink.html index c3671b1f..eb8807b5 100644 --- a/tpl/vintage/editlink.html +++ b/tpl/vintage/editlink.html @@ -11,7 +11,6 @@
- {if="isset($link.id)"} {/if} diff --git a/tpl/vintage/linklist.paging.html b/tpl/vintage/linklist.paging.html index b9396df6..79daf16c 100644 --- a/tpl/vintage/linklist.paging.html +++ b/tpl/vintage/linklist.paging.html @@ -32,6 +32,6 @@
{if="$previous_page_url"} ◄Older {/if} -
page {$page_current} / {$page_max}
+ {if="$page_max>1"}
page {$page_current} / {$page_max}
{/if} {if="$next_page_url"} Newer► {/if}