aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ApplicationUtilsTest.php21
-rw-r--r--tests/FileUtilsTest.php22
-rw-r--r--tests/HistoryTest.php17
-rw-r--r--tests/LanguagesTest.php4
-rw-r--r--tests/PluginManagerTest.php51
-rw-r--r--tests/TestCase.php77
-rw-r--r--tests/ThumbnailerTest.php5
-rw-r--r--tests/TimeZoneTest.php4
-rw-r--r--tests/UtilsTest.php8
-rw-r--r--tests/api/ApiMiddlewareTest.php65
-rw-r--r--tests/api/ApiUtilsTest.php76
-rw-r--r--tests/api/controllers/history/HistoryTest.php6
-rw-r--r--tests/api/controllers/info/InfoTest.php6
-rw-r--r--tests/api/controllers/links/DeleteLinkTest.php10
-rw-r--r--tests/api/controllers/links/GetLinkIdTest.php12
-rw-r--r--tests/api/controllers/links/GetLinksTest.php6
-rw-r--r--tests/api/controllers/links/PostLinkTest.php6
-rw-r--r--tests/api/controllers/links/PutLinkTest.php12
-rw-r--r--tests/api/controllers/tags/DeleteTagTest.php12
-rw-r--r--tests/api/controllers/tags/GetTagNameTest.php12
-rw-r--r--tests/api/controllers/tags/GetTagsTest.php6
-rw-r--r--tests/api/controllers/tags/PutTagTest.php18
-rw-r--r--tests/bookmark/BookmarkArrayTest.php29
-rw-r--r--tests/bookmark/BookmarkFileServiceTest.php141
-rw-r--r--tests/bookmark/BookmarkFilterTest.php30
-rw-r--r--tests/bookmark/BookmarkInitializerTest.php72
-rw-r--r--tests/bookmark/BookmarkTest.php12
-rw-r--r--tests/bookmark/LinkUtilsTest.php35
-rw-r--r--tests/bootstrap.php1
-rw-r--r--tests/config/ConfigJsonTest.php25
-rw-r--r--tests/config/ConfigManagerTest.php26
-rw-r--r--tests/config/ConfigPhpTest.php4
-rw-r--r--tests/config/ConfigPluginTest.php6
-rw-r--r--tests/container/ContainerBuilderTest.php4
-rw-r--r--tests/feed/CachedPageTest.php6
-rw-r--r--tests/feed/FeedBuilderTest.php41
-rw-r--r--tests/formatter/BookmarkDefaultFormatterTest.php4
-rw-r--r--tests/formatter/BookmarkMarkdownExtraFormatterTest.php162
-rw-r--r--tests/formatter/BookmarkMarkdownFormatterTest.php4
-rw-r--r--tests/formatter/BookmarkRawFormatterTest.php4
-rw-r--r--tests/formatter/FormatterFactoryTest.php4
-rw-r--r--tests/front/ShaarliAdminMiddlewareTest.php2
-rw-r--r--tests/front/ShaarliMiddlewareTest.php2
-rw-r--r--tests/front/controller/admin/ConfigureControllerTest.php6
-rw-r--r--tests/front/controller/admin/ExportControllerTest.php4
-rw-r--r--tests/front/controller/admin/ImportControllerTest.php2
-rw-r--r--tests/front/controller/admin/LogoutControllerTest.php3
-rw-r--r--tests/front/controller/admin/ManageShaareControllerTest/AddShaareTest.php2
-rw-r--r--tests/front/controller/admin/ManageShaareControllerTest/ChangeVisibilityBookmarkTest.php2
-rw-r--r--tests/front/controller/admin/ManageShaareControllerTest/DeleteBookmarkTest.php2
-rw-r--r--tests/front/controller/admin/ManageShaareControllerTest/DisplayCreateFormTest.php12
-rw-r--r--tests/front/controller/admin/ManageShaareControllerTest/DisplayEditFormTest.php2
-rw-r--r--tests/front/controller/admin/ManageShaareControllerTest/PinBookmarkTest.php2
-rw-r--r--tests/front/controller/admin/ManageShaareControllerTest/SaveBookmarkTest.php68
-rw-r--r--tests/front/controller/admin/ManageTagControllerTest.php2
-rw-r--r--tests/front/controller/admin/PasswordControllerTest.php2
-rw-r--r--tests/front/controller/admin/PluginsControllerTest.php7
-rw-r--r--tests/front/controller/admin/SessionFilterControllerTest.php10
-rw-r--r--tests/front/controller/admin/ShaarliAdminControllerTest.php2
-rw-r--r--tests/front/controller/admin/ThumbnailsControllerTest.php2
-rw-r--r--tests/front/controller/admin/TokenControllerTest.php2
-rw-r--r--tests/front/controller/admin/ToolsControllerTest.php8
-rw-r--r--tests/front/controller/visitor/BookmarkListControllerTest.php2
-rw-r--r--tests/front/controller/visitor/DailyControllerTest.php60
-rw-r--r--tests/front/controller/visitor/ErrorControllerTest.php2
-rw-r--r--tests/front/controller/visitor/ErrorNotFoundControllerTest.php81
-rw-r--r--tests/front/controller/visitor/FeedControllerTest.php38
-rw-r--r--tests/front/controller/visitor/FrontControllerMockHelper.php7
-rw-r--r--tests/front/controller/visitor/InstallControllerTest.php37
-rw-r--r--tests/front/controller/visitor/LoginControllerTest.php2
-rw-r--r--tests/front/controller/visitor/OpenSearchControllerTest.php4
-rw-r--r--tests/front/controller/visitor/PictureWallControllerTest.php18
-rw-r--r--tests/front/controller/visitor/PublicSessionFilterControllerTest.php8
-rw-r--r--tests/front/controller/visitor/ShaarliVisitorControllerTest.php47
-rw-r--r--tests/front/controller/visitor/TagCloudControllerTest.php74
-rw-r--r--tests/front/controller/visitor/TagControllerTest.php2
-rw-r--r--tests/http/HttpUtils/ClientIpIdTest.php2
-rw-r--r--tests/http/HttpUtils/GetHttpUrlTest.php2
-rw-r--r--tests/http/HttpUtils/GetIpAdressFromProxyTest.php2
-rw-r--r--tests/http/HttpUtils/IndexUrlTest.php36
-rw-r--r--tests/http/HttpUtils/IndexUrlTestWithConstant.php51
-rw-r--r--tests/http/HttpUtils/IsHttpsTest.php2
-rw-r--r--tests/http/HttpUtils/PageUrlTest.php2
-rw-r--r--tests/http/HttpUtils/ServerUrlTest.php2
-rw-r--r--tests/http/UrlTest.php2
-rw-r--r--tests/http/UrlUtils/CleanupUrlTest.php2
-rw-r--r--tests/http/UrlUtils/GetUrlSchemeTest.php2
-rw-r--r--tests/http/UrlUtils/UnparseUrlTest.php2
-rw-r--r--tests/http/UrlUtils/WhitelistProtocolsTest.php2
-rw-r--r--tests/languages/fr/LanguagesFrTest.php6
-rw-r--r--tests/legacy/LegacyControllerTest.php10
-rw-r--r--tests/legacy/LegacyLinkDBTest.php28
-rw-r--r--tests/legacy/LegacyLinkFilterTest.php18
-rw-r--r--tests/legacy/LegacyRouterTest.php512
-rw-r--r--tests/legacy/LegacyUpdaterTest.php24
-rw-r--r--tests/netscape/BookmarkExportTest.php9
-rw-r--r--tests/netscape/BookmarkImportTest.php10
-rw-r--r--tests/plugins/PluginAddlinkTest.php4
-rw-r--r--tests/plugins/PluginArchiveorgTest.php37
-rw-r--r--tests/plugins/PluginDefaultColorsTest.php25
-rw-r--r--tests/plugins/PluginIssoTest.php23
-rw-r--r--tests/plugins/PluginPlayvideosTest.php4
-rw-r--r--tests/plugins/PluginPubsubhubbubTest.php4
-rw-r--r--tests/plugins/PluginQrcodeTest.php4
-rw-r--r--tests/plugins/PluginWallabagTest.php4
-rw-r--r--tests/plugins/WallabagInstanceTest.php4
-rw-r--r--tests/plugins/test/test.php3
-rw-r--r--tests/render/PageCacheManagerTest.php6
-rw-r--r--tests/render/ThemeUtilsTest.php2
-rw-r--r--tests/security/BanManagerTest.php4
-rw-r--r--tests/security/LoginManagerTest.php4
-rw-r--r--tests/security/SessionManagerTest.php19
-rw-r--r--tests/updater/DummyUpdater.php8
-rw-r--r--tests/updater/UpdaterTest.php20
114 files changed, 1332 insertions, 1161 deletions
diff --git a/tests/ApplicationUtilsTest.php b/tests/ApplicationUtilsTest.php
index 15388970..a232b351 100644
--- a/tests/ApplicationUtilsTest.php
+++ b/tests/ApplicationUtilsTest.php
@@ -8,7 +8,7 @@ require_once 'tests/utils/FakeApplicationUtils.php';
8/** 8/**
9 * Unitary tests for Shaarli utilities 9 * Unitary tests for Shaarli utilities
10 */ 10 */
11class ApplicationUtilsTest extends \PHPUnit\Framework\TestCase 11class ApplicationUtilsTest extends \Shaarli\TestCase
12{ 12{
13 protected static $testUpdateFile = 'sandbox/update.txt'; 13 protected static $testUpdateFile = 'sandbox/update.txt';
14 protected static $testVersion = '0.5.0'; 14 protected static $testVersion = '0.5.0';
@@ -17,7 +17,7 @@ class ApplicationUtilsTest extends \PHPUnit\Framework\TestCase
17 /** 17 /**
18 * Reset test data for each test 18 * Reset test data for each test
19 */ 19 */
20 public function setUp() 20 protected function setUp(): void
21 { 21 {
22 FakeApplicationUtils::$VERSION_CODE = ''; 22 FakeApplicationUtils::$VERSION_CODE = '';
23 if (file_exists(self::$testUpdateFile)) { 23 if (file_exists(self::$testUpdateFile)) {
@@ -28,7 +28,7 @@ class ApplicationUtilsTest extends \PHPUnit\Framework\TestCase
28 /** 28 /**
29 * Remove test version file if it exists 29 * Remove test version file if it exists
30 */ 30 */
31 public function tearDown() 31 protected function tearDown(): void
32 { 32 {
33 if (is_file('sandbox/version.php')) { 33 if (is_file('sandbox/version.php')) {
34 unlink('sandbox/version.php'); 34 unlink('sandbox/version.php');
@@ -144,11 +144,12 @@ class ApplicationUtilsTest extends \PHPUnit\Framework\TestCase
144 144
145 /** 145 /**
146 * Test update checks - invalid Git branch 146 * Test update checks - invalid Git branch
147 * @expectedException Exception
148 * @expectedExceptionMessageRegExp /Invalid branch selected for updates/
149 */ 147 */
150 public function testCheckUpdateInvalidGitBranch() 148 public function testCheckUpdateInvalidGitBranch()
151 { 149 {
150 $this->expectException(\Exception::class);
151 $this->expectExceptionMessageRegExp('/Invalid branch selected for updates/');
152
152 ApplicationUtils::checkUpdate('', 'null', 0, true, true, 'unstable'); 153 ApplicationUtils::checkUpdate('', 'null', 0, true, true, 'unstable');
153 } 154 }
154 155
@@ -260,21 +261,23 @@ class ApplicationUtilsTest extends \PHPUnit\Framework\TestCase
260 261
261 /** 262 /**
262 * Check a unsupported PHP version 263 * Check a unsupported PHP version
263 * @expectedException Exception
264 * @expectedExceptionMessageRegExp /Your PHP version is obsolete/
265 */ 264 */
266 public function testCheckSupportedPHPVersion51() 265 public function testCheckSupportedPHPVersion51()
267 { 266 {
267 $this->expectException(\Exception::class);
268 $this->expectExceptionMessageRegExp('/Your PHP version is obsolete/');
269
268 $this->assertTrue(ApplicationUtils::checkPHPVersion('5.3', '5.1.0')); 270 $this->assertTrue(ApplicationUtils::checkPHPVersion('5.3', '5.1.0'));
269 } 271 }
270 272
271 /** 273 /**
272 * Check another unsupported PHP version 274 * Check another unsupported PHP version
273 * @expectedException Exception
274 * @expectedExceptionMessageRegExp /Your PHP version is obsolete/
275 */ 275 */
276 public function testCheckSupportedPHPVersion52() 276 public function testCheckSupportedPHPVersion52()
277 { 277 {
278 $this->expectException(\Exception::class);
279 $this->expectExceptionMessageRegExp('/Your PHP version is obsolete/');
280
278 $this->assertTrue(ApplicationUtils::checkPHPVersion('5.3', '5.2')); 281 $this->assertTrue(ApplicationUtils::checkPHPVersion('5.3', '5.2'));
279 } 282 }
280 283
diff --git a/tests/FileUtilsTest.php b/tests/FileUtilsTest.php
index 57719175..9163bdf1 100644
--- a/tests/FileUtilsTest.php
+++ b/tests/FileUtilsTest.php
@@ -9,7 +9,7 @@ use Exception;
9 * 9 *
10 * Test file utility class. 10 * Test file utility class.
11 */ 11 */
12class FileUtilsTest extends \PHPUnit\Framework\TestCase 12class FileUtilsTest extends \Shaarli\TestCase
13{ 13{
14 /** 14 /**
15 * @var string Test file path. 15 * @var string Test file path.
@@ -19,7 +19,7 @@ class FileUtilsTest extends \PHPUnit\Framework\TestCase
19 /** 19 /**
20 * Delete test file after every test. 20 * Delete test file after every test.
21 */ 21 */
22 public function tearDown() 22 protected function tearDown(): void
23 { 23 {
24 @unlink(self::$file); 24 @unlink(self::$file);
25 } 25 }
@@ -49,12 +49,12 @@ class FileUtilsTest extends \PHPUnit\Framework\TestCase
49 49
50 /** 50 /**
51 * File not writable: raise an exception. 51 * File not writable: raise an exception.
52 *
53 * @expectedException Shaarli\Exceptions\IOException
54 * @expectedExceptionMessage Error accessing "sandbox/flat.db"
55 */ 52 */
56 public function testWriteWithoutPermission() 53 public function testWriteWithoutPermission()
57 { 54 {
55 $this->expectException(\Shaarli\Exceptions\IOException::class);
56 $this->expectExceptionMessage('Error accessing "sandbox/flat.db"');
57
58 touch(self::$file); 58 touch(self::$file);
59 chmod(self::$file, 0440); 59 chmod(self::$file, 0440);
60 FileUtils::writeFlatDB(self::$file, null); 60 FileUtils::writeFlatDB(self::$file, null);
@@ -62,23 +62,23 @@ class FileUtilsTest extends \PHPUnit\Framework\TestCase
62 62
63 /** 63 /**
64 * Folder non existent: raise an exception. 64 * Folder non existent: raise an exception.
65 *
66 * @expectedException Shaarli\Exceptions\IOException
67 * @expectedExceptionMessage Error accessing "nopefolder"
68 */ 65 */
69 public function testWriteFolderDoesNotExist() 66 public function testWriteFolderDoesNotExist()
70 { 67 {
68 $this->expectException(\Shaarli\Exceptions\IOException::class);
69 $this->expectExceptionMessage('Error accessing "nopefolder"');
70
71 FileUtils::writeFlatDB('nopefolder/file', null); 71 FileUtils::writeFlatDB('nopefolder/file', null);
72 } 72 }
73 73
74 /** 74 /**
75 * Folder non writable: raise an exception. 75 * Folder non writable: raise an exception.
76 *
77 * @expectedException Shaarli\Exceptions\IOException
78 * @expectedExceptionMessage Error accessing "sandbox"
79 */ 76 */
80 public function testWriteFolderPermission() 77 public function testWriteFolderPermission()
81 { 78 {
79 $this->expectException(\Shaarli\Exceptions\IOException::class);
80 $this->expectExceptionMessage('Error accessing "sandbox"');
81
82 chmod(dirname(self::$file), 0555); 82 chmod(dirname(self::$file), 0555);
83 try { 83 try {
84 FileUtils::writeFlatDB(self::$file, null); 84 FileUtils::writeFlatDB(self::$file, null);
diff --git a/tests/HistoryTest.php b/tests/HistoryTest.php
index 7189c3a9..6dc0e5b7 100644
--- a/tests/HistoryTest.php
+++ b/tests/HistoryTest.php
@@ -3,10 +3,9 @@
3namespace Shaarli; 3namespace Shaarli;
4 4
5use DateTime; 5use DateTime;
6use Exception;
7use Shaarli\Bookmark\Bookmark; 6use Shaarli\Bookmark\Bookmark;
8 7
9class HistoryTest extends \PHPUnit\Framework\TestCase 8class HistoryTest extends \Shaarli\TestCase
10{ 9{
11 /** 10 /**
12 * @var string History file path 11 * @var string History file path
@@ -16,7 +15,7 @@ class HistoryTest extends \PHPUnit\Framework\TestCase
16 /** 15 /**
17 * Delete history file. 16 * Delete history file.
18 */ 17 */
19 public function setUp() 18 protected function setUp(): void
20 { 19 {
21 if (file_exists(self::$historyFilePath)) { 20 if (file_exists(self::$historyFilePath)) {
22 unlink(self::$historyFilePath); 21 unlink(self::$historyFilePath);
@@ -44,12 +43,12 @@ class HistoryTest extends \PHPUnit\Framework\TestCase
44 43
45 /** 44 /**
46 * Not writable history file: raise an exception. 45 * Not writable history file: raise an exception.
47 *
48 * @expectedException Exception
49 * @expectedExceptionMessage History file isn't readable or writable
50 */ 46 */
51 public function testConstructNotWritable() 47 public function testConstructNotWritable()
52 { 48 {
49 $this->expectException(\Exception::class);
50 $this->expectExceptionMessage('History file isn\'t readable or writable');
51
53 touch(self::$historyFilePath); 52 touch(self::$historyFilePath);
54 chmod(self::$historyFilePath, 0440); 53 chmod(self::$historyFilePath, 0440);
55 $history = new History(self::$historyFilePath); 54 $history = new History(self::$historyFilePath);
@@ -58,12 +57,12 @@ class HistoryTest extends \PHPUnit\Framework\TestCase
58 57
59 /** 58 /**
60 * Not parsable history file: raise an exception. 59 * Not parsable history file: raise an exception.
61 *
62 * @expectedException Exception
63 * @expectedExceptionMessageRegExp /Could not parse history file/
64 */ 60 */
65 public function testConstructNotParsable() 61 public function testConstructNotParsable()
66 { 62 {
63 $this->expectException(\Exception::class);
64 $this->expectExceptionMessageRegExp('/Could not parse history file/');
65
67 file_put_contents(self::$historyFilePath, 'not parsable'); 66 file_put_contents(self::$historyFilePath, 'not parsable');
68 $history = new History(self::$historyFilePath); 67 $history = new History(self::$historyFilePath);
69 // gzinflate generates a warning 68 // gzinflate generates a warning
diff --git a/tests/LanguagesTest.php b/tests/LanguagesTest.php
index de83f291..ce24c160 100644
--- a/tests/LanguagesTest.php
+++ b/tests/LanguagesTest.php
@@ -7,7 +7,7 @@ use Shaarli\Config\ConfigManager;
7/** 7/**
8 * Class LanguagesTest. 8 * Class LanguagesTest.
9 */ 9 */
10class LanguagesTest extends \PHPUnit\Framework\TestCase 10class LanguagesTest extends \Shaarli\TestCase
11{ 11{
12 /** 12 /**
13 * @var string Config file path (without extension). 13 * @var string Config file path (without extension).
@@ -22,7 +22,7 @@ class LanguagesTest extends \PHPUnit\Framework\TestCase
22 /** 22 /**
23 * 23 *
24 */ 24 */
25 public function setUp() 25 protected function setUp(): void
26 { 26 {
27 $this->conf = new ConfigManager(self::$configFile); 27 $this->conf = new ConfigManager(self::$configFile);
28 } 28 }
diff --git a/tests/PluginManagerTest.php b/tests/PluginManagerTest.php
index a5d5dbe9..efef5e87 100644
--- a/tests/PluginManagerTest.php
+++ b/tests/PluginManagerTest.php
@@ -1,4 +1,5 @@
1<?php 1<?php
2
2namespace Shaarli\Plugin; 3namespace Shaarli\Plugin;
3 4
4use Shaarli\Config\ConfigManager; 5use Shaarli\Config\ConfigManager;
@@ -6,7 +7,7 @@ use Shaarli\Config\ConfigManager;
6/** 7/**
7 * Unit tests for Plugins 8 * Unit tests for Plugins
8 */ 9 */
9class PluginManagerTest extends \PHPUnit\Framework\TestCase 10class PluginManagerTest extends \Shaarli\TestCase
10{ 11{
11 /** 12 /**
12 * Path to tests plugin. 13 * Path to tests plugin.
@@ -41,17 +42,31 @@ class PluginManagerTest extends \PHPUnit\Framework\TestCase
41 42
42 $this->assertTrue(function_exists('hook_test_random')); 43 $this->assertTrue(function_exists('hook_test_random'));
43 44
44 $data = array(0 => 'woot'); 45 $data = [0 => 'woot'];
45 $this->pluginManager->executeHooks('random', $data); 46 $this->pluginManager->executeHooks('random', $data);
46 $this->assertEquals('woot', $data[1]);
47 47
48 $data = array(0 => 'woot'); 48 static::assertCount(2, $data);
49 static::assertSame('woot', $data[1]);
50
51 $data = [0 => 'woot'];
49 $this->pluginManager->executeHooks('random', $data, array('target' => 'test')); 52 $this->pluginManager->executeHooks('random', $data, array('target' => 'test'));
50 $this->assertEquals('page test', $data[1]);
51 53
52 $data = array(0 => 'woot'); 54 static::assertCount(2, $data);
55 static::assertSame('page test', $data[1]);
56
57 $data = [0 => 'woot'];
53 $this->pluginManager->executeHooks('random', $data, array('loggedin' => true)); 58 $this->pluginManager->executeHooks('random', $data, array('loggedin' => true));
54 $this->assertEquals('loggedin', $data[1]); 59
60 static::assertCount(2, $data);
61 static::assertEquals('loggedin', $data[1]);
62
63 $data = [0 => 'woot'];
64 $this->pluginManager->executeHooks('random', $data, array('loggedin' => null));
65
66 static::assertCount(3, $data);
67 static::assertEquals('loggedin', $data[1]);
68 static::assertArrayHasKey(2, $data);
69 static::assertNull($data[2]);
55 } 70 }
56 71
57 /** 72 /**
@@ -67,8 +82,8 @@ class PluginManagerTest extends \PHPUnit\Framework\TestCase
67 $data = []; 82 $data = [];
68 $this->pluginManager->executeHooks('error', $data); 83 $this->pluginManager->executeHooks('error', $data);
69 84
70 $this->assertSame( 85 $this->assertRegExp(
71 'test [plugin incompatibility]: Class \'Unknown\' not found', 86 '/test \[plugin incompatibility\]: Class [\'"]Unknown[\'"] not found/',
72 $this->pluginManager->getErrors()[0] 87 $this->pluginManager->getErrors()[0]
73 ); 88 );
74 } 89 }
@@ -78,8 +93,8 @@ class PluginManagerTest extends \PHPUnit\Framework\TestCase
78 */ 93 */
79 public function testPluginNotFound(): void 94 public function testPluginNotFound(): void
80 { 95 {
81 $this->pluginManager->load(array()); 96 $this->pluginManager->load([]);
82 $this->pluginManager->load(array('nope', 'renope')); 97 $this->pluginManager->load(['nope', 'renope']);
83 $this->addToAssertionCount(1); 98 $this->addToAssertionCount(1);
84 } 99 }
85 100
@@ -89,18 +104,18 @@ class PluginManagerTest extends \PHPUnit\Framework\TestCase
89 public function testGetPluginsMeta(): void 104 public function testGetPluginsMeta(): void
90 { 105 {
91 PluginManager::$PLUGINS_PATH = self::$pluginPath; 106 PluginManager::$PLUGINS_PATH = self::$pluginPath;
92 $this->pluginManager->load(array(self::$pluginName)); 107 $this->pluginManager->load([self::$pluginName]);
93 108
94 $expectedParameters = array( 109 $expectedParameters = [
95 'pop' => array( 110 'pop' => [
96 'value' => '', 111 'value' => '',
97 'desc' => 'pop description', 112 'desc' => 'pop description',
98 ), 113 ],
99 'hip' => array( 114 'hip' => [
100 'value' => '', 115 'value' => '',
101 'desc' => '', 116 'desc' => '',
102 ), 117 ],
103 ); 118 ];
104 $meta = $this->pluginManager->getPluginsMeta(); 119 $meta = $this->pluginManager->getPluginsMeta();
105 $this->assertEquals('test plugin', $meta[self::$pluginName]['description']); 120 $this->assertEquals('test plugin', $meta[self::$pluginName]['description']);
106 $this->assertEquals($expectedParameters, $meta[self::$pluginName]['parameters']); 121 $this->assertEquals($expectedParameters, $meta[self::$pluginName]['parameters']);
diff --git a/tests/TestCase.php b/tests/TestCase.php
new file mode 100644
index 00000000..781e7aa3
--- /dev/null
+++ b/tests/TestCase.php
@@ -0,0 +1,77 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Shaarli;
6
7/**
8 * Helper class extending \PHPUnit\Framework\TestCase.
9 * Used to make Shaarli UT run on multiple versions of PHPUnit.
10 */
11class TestCase extends \PHPUnit\Framework\TestCase
12{
13 /**
14 * expectExceptionMessageRegExp has been removed and replaced by expectExceptionMessageMatches in PHPUnit 9.
15 */
16 public function expectExceptionMessageRegExp(string $regularExpression): void
17 {
18 if (method_exists($this, 'expectExceptionMessageMatches')) {
19 $this->expectExceptionMessageMatches($regularExpression);
20 } else {
21 parent::expectExceptionMessageRegExp($regularExpression);
22 }
23 }
24
25 /**
26 * assertContains is now used for iterable, strings should use assertStringContainsString
27 */
28 public function assertContainsPolyfill($expected, $actual, string $message = ''): void
29 {
30 if (is_string($actual) && method_exists($this, 'assertStringContainsString')) {
31 static::assertStringContainsString($expected, $actual, $message);
32 } else {
33 static::assertContains($expected, $actual, $message);
34 }
35 }
36
37 /**
38 * assertNotContains is now used for iterable, strings should use assertStringNotContainsString
39 */
40 public function assertNotContainsPolyfill($expected, $actual, string $message = ''): void
41 {
42 if (is_string($actual) && method_exists($this, 'assertStringNotContainsString')) {
43 static::assertStringNotContainsString($expected, $actual, $message);
44 } else {
45 static::assertNotContains($expected, $actual, $message);
46 }
47 }
48
49 /**
50 * assertFileNotExists has been renamed in assertFileDoesNotExist
51 */
52 public static function assertFileNotExists(string $filename, string $message = ''): void
53 {
54 if (method_exists(TestCase::class, 'assertFileDoesNotExist')) {
55 static::assertFileDoesNotExist($filename, $message);
56 } else {
57 parent::assertFileNotExists($filename, $message);
58 }
59 }
60
61 /**
62 * assertRegExp has been renamed in assertMatchesRegularExpression
63 */
64 public static function assertRegExp(string $pattern, string $string, string $message = ''): void
65 {
66 if (method_exists(TestCase::class, 'assertMatchesRegularExpression')) {
67 static::assertMatchesRegularExpression($pattern, $string, $message);
68 } else {
69 parent::assertRegExp($pattern, $string, $message);
70 }
71 }
72
73 public function isInTestsContext(): bool
74 {
75 return true;
76 }
77}
diff --git a/tests/ThumbnailerTest.php b/tests/ThumbnailerTest.php
index c01849f7..70519aca 100644
--- a/tests/ThumbnailerTest.php
+++ b/tests/ThumbnailerTest.php
@@ -2,7 +2,6 @@
2 2
3namespace Shaarli; 3namespace Shaarli;
4 4
5use PHPUnit\Framework\TestCase;
6use Shaarli\Config\ConfigManager; 5use Shaarli\Config\ConfigManager;
7use WebThumbnailer\Application\ConfigManager as WTConfigManager; 6use WebThumbnailer\Application\ConfigManager as WTConfigManager;
8 7
@@ -30,7 +29,7 @@ class ThumbnailerTest extends TestCase
30 */ 29 */
31 protected $conf; 30 protected $conf;
32 31
33 public function setUp() 32 protected function setUp(): void
34 { 33 {
35 $this->conf = new ConfigManager('tests/utils/config/configJson'); 34 $this->conf = new ConfigManager('tests/utils/config/configJson');
36 $this->conf->set('thumbnails.mode', Thumbnailer::MODE_ALL); 35 $this->conf->set('thumbnails.mode', Thumbnailer::MODE_ALL);
@@ -43,7 +42,7 @@ class ThumbnailerTest extends TestCase
43 WTConfigManager::addFile('tests/utils/config/wt.json'); 42 WTConfigManager::addFile('tests/utils/config/wt.json');
44 } 43 }
45 44
46 public function tearDown() 45 protected function tearDown(): void
47 { 46 {
48 $this->rrmdirContent('sandbox/'); 47 $this->rrmdirContent('sandbox/');
49 } 48 }
diff --git a/tests/TimeZoneTest.php b/tests/TimeZoneTest.php
index 02bf060f..77862855 100644
--- a/tests/TimeZoneTest.php
+++ b/tests/TimeZoneTest.php
@@ -8,14 +8,14 @@ require_once 'application/TimeZone.php';
8/** 8/**
9 * Unitary tests for timezone utilities 9 * Unitary tests for timezone utilities
10 */ 10 */
11class TimeZoneTest extends PHPUnit\Framework\TestCase 11class TimeZoneTest extends \Shaarli\TestCase
12{ 12{
13 /** 13 /**
14 * @var array of timezones 14 * @var array of timezones
15 */ 15 */
16 protected $installedTimezones; 16 protected $installedTimezones;
17 17
18 public function setUp() 18 protected function setUp(): void
19 { 19 {
20 $this->installedTimezones = [ 20 $this->installedTimezones = [
21 'Antarctica/Syowa', 21 'Antarctica/Syowa',
diff --git a/tests/UtilsTest.php b/tests/UtilsTest.php
index 26d2a6b8..6e787d7f 100644
--- a/tests/UtilsTest.php
+++ b/tests/UtilsTest.php
@@ -10,7 +10,7 @@ require_once 'application/Languages.php';
10/** 10/**
11 * Unitary tests for Shaarli utilities 11 * Unitary tests for Shaarli utilities
12 */ 12 */
13class UtilsTest extends PHPUnit\Framework\TestCase 13class UtilsTest extends \Shaarli\TestCase
14{ 14{
15 // Log file 15 // Log file
16 protected static $testLogFile = 'tests.log'; 16 protected static $testLogFile = 'tests.log';
@@ -26,7 +26,7 @@ class UtilsTest extends PHPUnit\Framework\TestCase
26 /** 26 /**
27 * Assign reference data 27 * Assign reference data
28 */ 28 */
29 public static function setUpBeforeClass() 29 public static function setUpBeforeClass(): void
30 { 30 {
31 self::$defaultTimeZone = date_default_timezone_get(); 31 self::$defaultTimeZone = date_default_timezone_get();
32 // Timezone without DST for test consistency 32 // Timezone without DST for test consistency
@@ -36,7 +36,7 @@ class UtilsTest extends PHPUnit\Framework\TestCase
36 /** 36 /**
37 * Reset the timezone 37 * Reset the timezone
38 */ 38 */
39 public static function tearDownAfterClass() 39 public static function tearDownAfterClass(): void
40 { 40 {
41 date_default_timezone_set(self::$defaultTimeZone); 41 date_default_timezone_set(self::$defaultTimeZone);
42 } 42 }
@@ -44,7 +44,7 @@ class UtilsTest extends PHPUnit\Framework\TestCase
44 /** 44 /**
45 * Resets test data before each test 45 * Resets test data before each test
46 */ 46 */
47 protected function setUp() 47 protected function setUp(): void
48 { 48 {
49 if (file_exists(self::$testLogFile)) { 49 if (file_exists(self::$testLogFile)) {
50 unlink(self::$testLogFile); 50 unlink(self::$testLogFile);
diff --git a/tests/api/ApiMiddlewareTest.php b/tests/api/ApiMiddlewareTest.php
index df2fb33a..86700840 100644
--- a/tests/api/ApiMiddlewareTest.php
+++ b/tests/api/ApiMiddlewareTest.php
@@ -18,7 +18,7 @@ use Slim\Http\Response;
18 * 18 *
19 * @package Api 19 * @package Api
20 */ 20 */
21class ApiMiddlewareTest extends \PHPUnit\Framework\TestCase 21class ApiMiddlewareTest extends \Shaarli\TestCase
22{ 22{
23 /** 23 /**
24 * @var string datastore to test write operations 24 * @var string datastore to test write operations
@@ -26,7 +26,7 @@ class ApiMiddlewareTest extends \PHPUnit\Framework\TestCase
26 protected static $testDatastore = 'sandbox/datastore.php'; 26 protected static $testDatastore = 'sandbox/datastore.php';
27 27
28 /** 28 /**
29 * @var \ConfigManager instance 29 * @var ConfigManager instance
30 */ 30 */
31 protected $conf; 31 protected $conf;
32 32
@@ -43,7 +43,7 @@ class ApiMiddlewareTest extends \PHPUnit\Framework\TestCase
43 /** 43 /**
44 * Before every test, instantiate a new Api with its config, plugins and bookmarks. 44 * Before every test, instantiate a new Api with its config, plugins and bookmarks.
45 */ 45 */
46 public function setUp() 46 protected function setUp(): void
47 { 47 {
48 $this->conf = new ConfigManager('tests/utils/config/configJson'); 48 $this->conf = new ConfigManager('tests/utils/config/configJson');
49 $this->conf->set('api.secret', 'NapoleonWasALizard'); 49 $this->conf->set('api.secret', 'NapoleonWasALizard');
@@ -61,12 +61,59 @@ class ApiMiddlewareTest extends \PHPUnit\Framework\TestCase
61 /** 61 /**
62 * After every test, remove the test datastore. 62 * After every test, remove the test datastore.
63 */ 63 */
64 public function tearDown() 64 protected function tearDown(): void
65 { 65 {
66 @unlink(self::$testDatastore); 66 @unlink(self::$testDatastore);
67 } 67 }
68 68
69 /** 69 /**
70 * Invoke the middleware with a valid token
71 */
72 public function testInvokeMiddlewareWithValidToken(): void
73 {
74 $next = function (Request $request, Response $response): Response {
75 return $response;
76 };
77 $mw = new ApiMiddleware($this->container);
78 $env = Environment::mock([
79 'REQUEST_METHOD' => 'GET',
80 'REQUEST_URI' => '/echo',
81 'HTTP_AUTHORIZATION'=> 'Bearer ' . ApiUtilsTest::generateValidJwtToken('NapoleonWasALizard'),
82 ]);
83 $request = Request::createFromEnvironment($env);
84 $response = new Response();
85 /** @var Response $response */
86 $response = $mw($request, $response, $next);
87
88 $this->assertEquals(200, $response->getStatusCode());
89 }
90
91 /**
92 * Invoke the middleware with a valid token
93 * Using specific Apache CGI redirected authorization.
94 */
95 public function testInvokeMiddlewareWithValidTokenFromRedirectedHeader(): void
96 {
97 $next = function (Request $request, Response $response): Response {
98 return $response;
99 };
100
101 $token = 'Bearer ' . ApiUtilsTest::generateValidJwtToken('NapoleonWasALizard');
102 $this->container->environment['REDIRECT_HTTP_AUTHORIZATION'] = $token;
103 $mw = new ApiMiddleware($this->container);
104 $env = Environment::mock([
105 'REQUEST_METHOD' => 'GET',
106 'REQUEST_URI' => '/echo',
107 ]);
108 $request = Request::createFromEnvironment($env);
109 $response = new Response();
110 /** @var Response $response */
111 $response = $mw($request, $response, $next);
112
113 $this->assertEquals(200, $response->getStatusCode());
114 }
115
116 /**
70 * Invoke the middleware with the API disabled: 117 * Invoke the middleware with the API disabled:
71 * should return a 401 error Unauthorized. 118 * should return a 401 error Unauthorized.
72 */ 119 */
@@ -109,7 +156,7 @@ class ApiMiddlewareTest extends \PHPUnit\Framework\TestCase
109 $this->assertEquals(401, $response->getStatusCode()); 156 $this->assertEquals(401, $response->getStatusCode());
110 $body = json_decode((string) $response->getBody()); 157 $body = json_decode((string) $response->getBody());
111 $this->assertEquals('Not authorized: API is disabled', $body->message); 158 $this->assertEquals('Not authorized: API is disabled', $body->message);
112 $this->assertContains('ApiAuthorizationException', $body->stacktrace); 159 $this->assertContainsPolyfill('ApiAuthorizationException', $body->stacktrace);
113 } 160 }
114 161
115 /** 162 /**
@@ -132,7 +179,7 @@ class ApiMiddlewareTest extends \PHPUnit\Framework\TestCase
132 $this->assertEquals(401, $response->getStatusCode()); 179 $this->assertEquals(401, $response->getStatusCode());
133 $body = json_decode((string) $response->getBody()); 180 $body = json_decode((string) $response->getBody());
134 $this->assertEquals('Not authorized: JWT token not provided', $body->message); 181 $this->assertEquals('Not authorized: JWT token not provided', $body->message);
135 $this->assertContains('ApiAuthorizationException', $body->stacktrace); 182 $this->assertContainsPolyfill('ApiAuthorizationException', $body->stacktrace);
136 } 183 }
137 184
138 /** 185 /**
@@ -157,7 +204,7 @@ class ApiMiddlewareTest extends \PHPUnit\Framework\TestCase
157 $this->assertEquals(401, $response->getStatusCode()); 204 $this->assertEquals(401, $response->getStatusCode());
158 $body = json_decode((string) $response->getBody()); 205 $body = json_decode((string) $response->getBody());
159 $this->assertEquals('Not authorized: Token secret must be set in Shaarli\'s administration', $body->message); 206 $this->assertEquals('Not authorized: Token secret must be set in Shaarli\'s administration', $body->message);
160 $this->assertContains('ApiAuthorizationException', $body->stacktrace); 207 $this->assertContainsPolyfill('ApiAuthorizationException', $body->stacktrace);
161 } 208 }
162 209
163 /** 210 /**
@@ -180,7 +227,7 @@ class ApiMiddlewareTest extends \PHPUnit\Framework\TestCase
180 $this->assertEquals(401, $response->getStatusCode()); 227 $this->assertEquals(401, $response->getStatusCode());
181 $body = json_decode((string) $response->getBody()); 228 $body = json_decode((string) $response->getBody());
182 $this->assertEquals('Not authorized: Invalid JWT header', $body->message); 229 $this->assertEquals('Not authorized: Invalid JWT header', $body->message);
183 $this->assertContains('ApiAuthorizationException', $body->stacktrace); 230 $this->assertContainsPolyfill('ApiAuthorizationException', $body->stacktrace);
184 } 231 }
185 232
186 /** 233 /**
@@ -206,6 +253,6 @@ class ApiMiddlewareTest extends \PHPUnit\Framework\TestCase
206 $this->assertEquals(401, $response->getStatusCode()); 253 $this->assertEquals(401, $response->getStatusCode());
207 $body = json_decode((string) $response->getBody()); 254 $body = json_decode((string) $response->getBody());
208 $this->assertEquals('Not authorized: Malformed JWT token', $body->message); 255 $this->assertEquals('Not authorized: Malformed JWT token', $body->message);
209 $this->assertContains('ApiAuthorizationException', $body->stacktrace); 256 $this->assertContainsPolyfill('ApiAuthorizationException', $body->stacktrace);
210 } 257 }
211} 258}
diff --git a/tests/api/ApiUtilsTest.php b/tests/api/ApiUtilsTest.php
index 7efec9bb..7a143859 100644
--- a/tests/api/ApiUtilsTest.php
+++ b/tests/api/ApiUtilsTest.php
@@ -8,12 +8,12 @@ use Shaarli\Http\Base64Url;
8/** 8/**
9 * Class ApiUtilsTest 9 * Class ApiUtilsTest
10 */ 10 */
11class ApiUtilsTest extends \PHPUnit\Framework\TestCase 11class ApiUtilsTest extends \Shaarli\TestCase
12{ 12{
13 /** 13 /**
14 * Force the timezone for ISO datetimes. 14 * Force the timezone for ISO datetimes.
15 */ 15 */
16 public static function setUpBeforeClass() 16 public static function setUpBeforeClass(): void
17 { 17 {
18 date_default_timezone_set('UTC'); 18 date_default_timezone_set('UTC');
19 } 19 }
@@ -66,143 +66,143 @@ class ApiUtilsTest extends \PHPUnit\Framework\TestCase
66 66
67 /** 67 /**
68 * Test validateJwtToken() with a malformed JWT token. 68 * Test validateJwtToken() with a malformed JWT token.
69 *
70 * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException
71 * @expectedExceptionMessage Malformed JWT token
72 */ 69 */
73 public function testValidateJwtTokenMalformed() 70 public function testValidateJwtTokenMalformed()
74 { 71 {
72 $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class);
73 $this->expectExceptionMessage('Malformed JWT token');
74
75 $token = 'ABC.DEF'; 75 $token = 'ABC.DEF';
76 ApiUtils::validateJwtToken($token, 'foo'); 76 ApiUtils::validateJwtToken($token, 'foo');
77 } 77 }
78 78
79 /** 79 /**
80 * Test validateJwtToken() with an empty JWT token. 80 * Test validateJwtToken() with an empty JWT token.
81 *
82 * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException
83 * @expectedExceptionMessage Malformed JWT token
84 */ 81 */
85 public function testValidateJwtTokenMalformedEmpty() 82 public function testValidateJwtTokenMalformedEmpty()
86 { 83 {
84 $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class);
85 $this->expectExceptionMessage('Malformed JWT token');
86
87 $token = false; 87 $token = false;
88 ApiUtils::validateJwtToken($token, 'foo'); 88 ApiUtils::validateJwtToken($token, 'foo');
89 } 89 }
90 90
91 /** 91 /**
92 * Test validateJwtToken() with a JWT token without header. 92 * Test validateJwtToken() with a JWT token without header.
93 *
94 * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException
95 * @expectedExceptionMessage Malformed JWT token
96 */ 93 */
97 public function testValidateJwtTokenMalformedEmptyHeader() 94 public function testValidateJwtTokenMalformedEmptyHeader()
98 { 95 {
96 $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class);
97 $this->expectExceptionMessage('Malformed JWT token');
98
99 $token = '.payload.signature'; 99 $token = '.payload.signature';
100 ApiUtils::validateJwtToken($token, 'foo'); 100 ApiUtils::validateJwtToken($token, 'foo');
101 } 101 }
102 102
103 /** 103 /**
104 * Test validateJwtToken() with a JWT token without payload 104 * Test validateJwtToken() with a JWT token without payload
105 *
106 * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException
107 * @expectedExceptionMessage Malformed JWT token
108 */ 105 */
109 public function testValidateJwtTokenMalformedEmptyPayload() 106 public function testValidateJwtTokenMalformedEmptyPayload()
110 { 107 {
108 $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class);
109 $this->expectExceptionMessage('Malformed JWT token');
110
111 $token = 'header..signature'; 111 $token = 'header..signature';
112 ApiUtils::validateJwtToken($token, 'foo'); 112 ApiUtils::validateJwtToken($token, 'foo');
113 } 113 }
114 114
115 /** 115 /**
116 * Test validateJwtToken() with a JWT token with an empty signature. 116 * Test validateJwtToken() with a JWT token with an empty signature.
117 *
118 * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException
119 * @expectedExceptionMessage Invalid JWT signature
120 */ 117 */
121 public function testValidateJwtTokenInvalidSignatureEmpty() 118 public function testValidateJwtTokenInvalidSignatureEmpty()
122 { 119 {
120 $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class);
121 $this->expectExceptionMessage('Invalid JWT signature');
122
123 $token = 'header.payload.'; 123 $token = 'header.payload.';
124 ApiUtils::validateJwtToken($token, 'foo'); 124 ApiUtils::validateJwtToken($token, 'foo');
125 } 125 }
126 126
127 /** 127 /**
128 * Test validateJwtToken() with a JWT token with an invalid signature. 128 * Test validateJwtToken() with a JWT token with an invalid signature.
129 *
130 * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException
131 * @expectedExceptionMessage Invalid JWT signature
132 */ 129 */
133 public function testValidateJwtTokenInvalidSignature() 130 public function testValidateJwtTokenInvalidSignature()
134 { 131 {
132 $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class);
133 $this->expectExceptionMessage('Invalid JWT signature');
134
135 $token = 'header.payload.nope'; 135 $token = 'header.payload.nope';
136 ApiUtils::validateJwtToken($token, 'foo'); 136 ApiUtils::validateJwtToken($token, 'foo');
137 } 137 }
138 138
139 /** 139 /**
140 * Test validateJwtToken() with a JWT token with a signature generated with the wrong API secret. 140 * Test validateJwtToken() with a JWT token with a signature generated with the wrong API secret.
141 *
142 * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException
143 * @expectedExceptionMessage Invalid JWT signature
144 */ 141 */
145 public function testValidateJwtTokenInvalidSignatureSecret() 142 public function testValidateJwtTokenInvalidSignatureSecret()
146 { 143 {
144 $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class);
145 $this->expectExceptionMessage('Invalid JWT signature');
146
147 ApiUtils::validateJwtToken(self::generateValidJwtToken('foo'), 'bar'); 147 ApiUtils::validateJwtToken(self::generateValidJwtToken('foo'), 'bar');
148 } 148 }
149 149
150 /** 150 /**
151 * Test validateJwtToken() with a JWT token with a an invalid header (not JSON). 151 * Test validateJwtToken() with a JWT token with a an invalid header (not JSON).
152 *
153 * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException
154 * @expectedExceptionMessage Invalid JWT header
155 */ 152 */
156 public function testValidateJwtTokenInvalidHeader() 153 public function testValidateJwtTokenInvalidHeader()
157 { 154 {
155 $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class);
156 $this->expectExceptionMessage('Invalid JWT header');
157
158 $token = $this->generateCustomJwtToken('notJSON', '{"JSON":1}', 'secret'); 158 $token = $this->generateCustomJwtToken('notJSON', '{"JSON":1}', 'secret');
159 ApiUtils::validateJwtToken($token, 'secret'); 159 ApiUtils::validateJwtToken($token, 'secret');
160 } 160 }
161 161
162 /** 162 /**
163 * Test validateJwtToken() with a JWT token with a an invalid payload (not JSON). 163 * Test validateJwtToken() with a JWT token with a an invalid payload (not JSON).
164 *
165 * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException
166 * @expectedExceptionMessage Invalid JWT payload
167 */ 164 */
168 public function testValidateJwtTokenInvalidPayload() 165 public function testValidateJwtTokenInvalidPayload()
169 { 166 {
167 $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class);
168 $this->expectExceptionMessage('Invalid JWT payload');
169
170 $token = $this->generateCustomJwtToken('{"JSON":1}', 'notJSON', 'secret'); 170 $token = $this->generateCustomJwtToken('{"JSON":1}', 'notJSON', 'secret');
171 ApiUtils::validateJwtToken($token, 'secret'); 171 ApiUtils::validateJwtToken($token, 'secret');
172 } 172 }
173 173
174 /** 174 /**
175 * Test validateJwtToken() with a JWT token without issued time. 175 * Test validateJwtToken() with a JWT token without issued time.
176 *
177 * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException
178 * @expectedExceptionMessage Invalid JWT issued time
179 */ 176 */
180 public function testValidateJwtTokenInvalidTimeEmpty() 177 public function testValidateJwtTokenInvalidTimeEmpty()
181 { 178 {
179 $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class);
180 $this->expectExceptionMessage('Invalid JWT issued time');
181
182 $token = $this->generateCustomJwtToken('{"JSON":1}', '{"JSON":1}', 'secret'); 182 $token = $this->generateCustomJwtToken('{"JSON":1}', '{"JSON":1}', 'secret');
183 ApiUtils::validateJwtToken($token, 'secret'); 183 ApiUtils::validateJwtToken($token, 'secret');
184 } 184 }
185 185
186 /** 186 /**
187 * Test validateJwtToken() with an expired JWT token. 187 * Test validateJwtToken() with an expired JWT token.
188 *
189 * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException
190 * @expectedExceptionMessage Invalid JWT issued time
191 */ 188 */
192 public function testValidateJwtTokenInvalidTimeExpired() 189 public function testValidateJwtTokenInvalidTimeExpired()
193 { 190 {
191 $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class);
192 $this->expectExceptionMessage('Invalid JWT issued time');
193
194 $token = $this->generateCustomJwtToken('{"JSON":1}', '{"iat":' . (time() - 600) . '}', 'secret'); 194 $token = $this->generateCustomJwtToken('{"JSON":1}', '{"iat":' . (time() - 600) . '}', 'secret');
195 ApiUtils::validateJwtToken($token, 'secret'); 195 ApiUtils::validateJwtToken($token, 'secret');
196 } 196 }
197 197
198 /** 198 /**
199 * Test validateJwtToken() with a JWT token issued in the future. 199 * Test validateJwtToken() with a JWT token issued in the future.
200 *
201 * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException
202 * @expectedExceptionMessage Invalid JWT issued time
203 */ 200 */
204 public function testValidateJwtTokenInvalidTimeFuture() 201 public function testValidateJwtTokenInvalidTimeFuture()
205 { 202 {
203 $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class);
204 $this->expectExceptionMessage('Invalid JWT issued time');
205
206 $token = $this->generateCustomJwtToken('{"JSON":1}', '{"iat":' . (time() + 60) . '}', 'secret'); 206 $token = $this->generateCustomJwtToken('{"JSON":1}', '{"iat":' . (time() + 60) . '}', 'secret');
207 ApiUtils::validateJwtToken($token, 'secret'); 207 ApiUtils::validateJwtToken($token, 'secret');
208 } 208 }
diff --git a/tests/api/controllers/history/HistoryTest.php b/tests/api/controllers/history/HistoryTest.php
index f4d3b646..84f8716e 100644
--- a/tests/api/controllers/history/HistoryTest.php
+++ b/tests/api/controllers/history/HistoryTest.php
@@ -11,7 +11,7 @@ use Slim\Http\Response;
11 11
12require_once 'tests/utils/ReferenceHistory.php'; 12require_once 'tests/utils/ReferenceHistory.php';
13 13
14class HistoryTest extends \PHPUnit\Framework\TestCase 14class HistoryTest extends \Shaarli\TestCase
15{ 15{
16 /** 16 /**
17 * @var string datastore to test write operations 17 * @var string datastore to test write operations
@@ -41,7 +41,7 @@ class HistoryTest extends \PHPUnit\Framework\TestCase
41 /** 41 /**
42 * Before every test, instantiate a new Api with its config, plugins and bookmarks. 42 * Before every test, instantiate a new Api with its config, plugins and bookmarks.
43 */ 43 */
44 public function setUp() 44 protected function setUp(): void
45 { 45 {
46 $this->conf = new ConfigManager('tests/utils/config/configJson'); 46 $this->conf = new ConfigManager('tests/utils/config/configJson');
47 $this->refHistory = new \ReferenceHistory(); 47 $this->refHistory = new \ReferenceHistory();
@@ -57,7 +57,7 @@ class HistoryTest extends \PHPUnit\Framework\TestCase
57 /** 57 /**
58 * After every test, remove the test datastore. 58 * After every test, remove the test datastore.
59 */ 59 */
60 public function tearDown() 60 protected function tearDown(): void
61 { 61 {
62 @unlink(self::$testHistory); 62 @unlink(self::$testHistory);
63 } 63 }
diff --git a/tests/api/controllers/info/InfoTest.php b/tests/api/controllers/info/InfoTest.php
index b5c938e1..1598e1e8 100644
--- a/tests/api/controllers/info/InfoTest.php
+++ b/tests/api/controllers/info/InfoTest.php
@@ -1,10 +1,10 @@
1<?php 1<?php
2namespace Shaarli\Api\Controllers; 2namespace Shaarli\Api\Controllers;
3 3
4use PHPUnit\Framework\TestCase;
5use Shaarli\Bookmark\BookmarkFileService; 4use Shaarli\Bookmark\BookmarkFileService;
6use Shaarli\Config\ConfigManager; 5use Shaarli\Config\ConfigManager;
7use Shaarli\History; 6use Shaarli\History;
7use Shaarli\TestCase;
8use Slim\Container; 8use Slim\Container;
9use Slim\Http\Environment; 9use Slim\Http\Environment;
10use Slim\Http\Request; 10use Slim\Http\Request;
@@ -47,7 +47,7 @@ class InfoTest extends TestCase
47 /** 47 /**
48 * Before every test, instantiate a new Api with its config, plugins and bookmarks. 48 * Before every test, instantiate a new Api with its config, plugins and bookmarks.
49 */ 49 */
50 public function setUp() 50 protected function setUp(): void
51 { 51 {
52 $this->conf = new ConfigManager('tests/utils/config/configJson'); 52 $this->conf = new ConfigManager('tests/utils/config/configJson');
53 $this->conf->set('resource.datastore', self::$testDatastore); 53 $this->conf->set('resource.datastore', self::$testDatastore);
@@ -67,7 +67,7 @@ class InfoTest extends TestCase
67 /** 67 /**
68 * After every test, remove the test datastore. 68 * After every test, remove the test datastore.
69 */ 69 */
70 public function tearDown() 70 protected function tearDown(): void
71 { 71 {
72 @unlink(self::$testDatastore); 72 @unlink(self::$testDatastore);
73 } 73 }
diff --git a/tests/api/controllers/links/DeleteLinkTest.php b/tests/api/controllers/links/DeleteLinkTest.php
index 6c2b3698..cf9464f0 100644
--- a/tests/api/controllers/links/DeleteLinkTest.php
+++ b/tests/api/controllers/links/DeleteLinkTest.php
@@ -11,7 +11,7 @@ use Slim\Http\Environment;
11use Slim\Http\Request; 11use Slim\Http\Request;
12use Slim\Http\Response; 12use Slim\Http\Response;
13 13
14class DeleteLinkTest extends \PHPUnit\Framework\TestCase 14class DeleteLinkTest extends \Shaarli\TestCase
15{ 15{
16 /** 16 /**
17 * @var string datastore to test write operations 17 * @var string datastore to test write operations
@@ -56,7 +56,7 @@ class DeleteLinkTest extends \PHPUnit\Framework\TestCase
56 /** 56 /**
57 * Before each test, instantiate a new Api with its config, plugins and bookmarks. 57 * Before each test, instantiate a new Api with its config, plugins and bookmarks.
58 */ 58 */
59 public function setUp() 59 protected function setUp(): void
60 { 60 {
61 $this->conf = new ConfigManager('tests/utils/config/configJson'); 61 $this->conf = new ConfigManager('tests/utils/config/configJson');
62 $this->conf->set('resource.datastore', self::$testDatastore); 62 $this->conf->set('resource.datastore', self::$testDatastore);
@@ -78,7 +78,7 @@ class DeleteLinkTest extends \PHPUnit\Framework\TestCase
78 /** 78 /**
79 * After each test, remove the test datastore. 79 * After each test, remove the test datastore.
80 */ 80 */
81 public function tearDown() 81 protected function tearDown(): void
82 { 82 {
83 @unlink(self::$testDatastore); 83 @unlink(self::$testDatastore);
84 @unlink(self::$testHistory); 84 @unlink(self::$testHistory);
@@ -113,11 +113,11 @@ class DeleteLinkTest extends \PHPUnit\Framework\TestCase
113 113
114 /** 114 /**
115 * Test DELETE link endpoint: reach not existing ID. 115 * Test DELETE link endpoint: reach not existing ID.
116 *
117 * @expectedException \Shaarli\Api\Exceptions\ApiLinkNotFoundException
118 */ 116 */
119 public function testDeleteLink404() 117 public function testDeleteLink404()
120 { 118 {
119 $this->expectException(\Shaarli\Api\Exceptions\ApiLinkNotFoundException::class);
120
121 $id = -1; 121 $id = -1;
122 $this->assertFalse($this->bookmarkService->exists($id)); 122 $this->assertFalse($this->bookmarkService->exists($id));
123 $env = Environment::mock([ 123 $env = Environment::mock([
diff --git a/tests/api/controllers/links/GetLinkIdTest.php b/tests/api/controllers/links/GetLinkIdTest.php
index 8bb81dc8..99dc606f 100644
--- a/tests/api/controllers/links/GetLinkIdTest.php
+++ b/tests/api/controllers/links/GetLinkIdTest.php
@@ -20,7 +20,7 @@ use Slim\Http\Response;
20 * 20 *
21 * @package Shaarli\Api\Controllers 21 * @package Shaarli\Api\Controllers
22 */ 22 */
23class GetLinkIdTest extends \PHPUnit\Framework\TestCase 23class GetLinkIdTest extends \Shaarli\TestCase
24{ 24{
25 /** 25 /**
26 * @var string datastore to test write operations 26 * @var string datastore to test write operations
@@ -55,7 +55,7 @@ class GetLinkIdTest extends \PHPUnit\Framework\TestCase
55 /** 55 /**
56 * Before each test, instantiate a new Api with its config, plugins and bookmarks. 56 * Before each test, instantiate a new Api with its config, plugins and bookmarks.
57 */ 57 */
58 public function setUp() 58 protected function setUp(): void
59 { 59 {
60 $this->conf = new ConfigManager('tests/utils/config/configJson'); 60 $this->conf = new ConfigManager('tests/utils/config/configJson');
61 $this->conf->set('resource.datastore', self::$testDatastore); 61 $this->conf->set('resource.datastore', self::$testDatastore);
@@ -74,7 +74,7 @@ class GetLinkIdTest extends \PHPUnit\Framework\TestCase
74 /** 74 /**
75 * After each test, remove the test datastore. 75 * After each test, remove the test datastore.
76 */ 76 */
77 public function tearDown() 77 protected function tearDown(): void
78 { 78 {
79 @unlink(self::$testDatastore); 79 @unlink(self::$testDatastore);
80 } 80 }
@@ -120,12 +120,12 @@ class GetLinkIdTest extends \PHPUnit\Framework\TestCase
120 120
121 /** 121 /**
122 * Test basic getLink service: get non existent link => ApiLinkNotFoundException. 122 * Test basic getLink service: get non existent link => ApiLinkNotFoundException.
123 *
124 * @expectedException Shaarli\Api\Exceptions\ApiLinkNotFoundException
125 * @expectedExceptionMessage Link not found
126 */ 123 */
127 public function testGetLink404() 124 public function testGetLink404()
128 { 125 {
126 $this->expectException(\Shaarli\Api\Exceptions\ApiLinkNotFoundException::class);
127 $this->expectExceptionMessage('Link not found');
128
129 $env = Environment::mock([ 129 $env = Environment::mock([
130 'REQUEST_METHOD' => 'GET', 130 'REQUEST_METHOD' => 'GET',
131 ]); 131 ]);
diff --git a/tests/api/controllers/links/GetLinksTest.php b/tests/api/controllers/links/GetLinksTest.php
index d02e6fad..ca1bfc63 100644
--- a/tests/api/controllers/links/GetLinksTest.php
+++ b/tests/api/controllers/links/GetLinksTest.php
@@ -20,7 +20,7 @@ use Slim\Http\Response;
20 * 20 *
21 * @package Shaarli\Api\Controllers 21 * @package Shaarli\Api\Controllers
22 */ 22 */
23class GetLinksTest extends \PHPUnit\Framework\TestCase 23class GetLinksTest extends \Shaarli\TestCase
24{ 24{
25 /** 25 /**
26 * @var string datastore to test write operations 26 * @var string datastore to test write operations
@@ -55,7 +55,7 @@ class GetLinksTest extends \PHPUnit\Framework\TestCase
55 /** 55 /**
56 * Before every test, instantiate a new Api with its config, plugins and bookmarks. 56 * Before every test, instantiate a new Api with its config, plugins and bookmarks.
57 */ 57 */
58 public function setUp() 58 protected function setUp(): void
59 { 59 {
60 $this->conf = new ConfigManager('tests/utils/config/configJson'); 60 $this->conf = new ConfigManager('tests/utils/config/configJson');
61 $this->conf->set('resource.datastore', self::$testDatastore); 61 $this->conf->set('resource.datastore', self::$testDatastore);
@@ -74,7 +74,7 @@ class GetLinksTest extends \PHPUnit\Framework\TestCase
74 /** 74 /**
75 * After every test, remove the test datastore. 75 * After every test, remove the test datastore.
76 */ 76 */
77 public function tearDown() 77 protected function tearDown(): void
78 { 78 {
79 @unlink(self::$testDatastore); 79 @unlink(self::$testDatastore);
80 } 80 }
diff --git a/tests/api/controllers/links/PostLinkTest.php b/tests/api/controllers/links/PostLinkTest.php
index f969fe1c..20694571 100644
--- a/tests/api/controllers/links/PostLinkTest.php
+++ b/tests/api/controllers/links/PostLinkTest.php
@@ -2,11 +2,11 @@
2 2
3namespace Shaarli\Api\Controllers; 3namespace Shaarli\Api\Controllers;
4 4
5use PHPUnit\Framework\TestCase;
6use Shaarli\Bookmark\Bookmark; 5use Shaarli\Bookmark\Bookmark;
7use Shaarli\Bookmark\BookmarkFileService; 6use Shaarli\Bookmark\BookmarkFileService;
8use Shaarli\Config\ConfigManager; 7use Shaarli\Config\ConfigManager;
9use Shaarli\History; 8use Shaarli\History;
9use Shaarli\TestCase;
10use Slim\Container; 10use Slim\Container;
11use Slim\Http\Environment; 11use Slim\Http\Environment;
12use Slim\Http\Request; 12use Slim\Http\Request;
@@ -70,7 +70,7 @@ class PostLinkTest extends TestCase
70 /** 70 /**
71 * Before every test, instantiate a new Api with its config, plugins and bookmarks. 71 * Before every test, instantiate a new Api with its config, plugins and bookmarks.
72 */ 72 */
73 public function setUp() 73 protected function setUp(): void
74 { 74 {
75 $this->conf = new ConfigManager('tests/utils/config/configJson'); 75 $this->conf = new ConfigManager('tests/utils/config/configJson');
76 $this->conf->set('resource.datastore', self::$testDatastore); 76 $this->conf->set('resource.datastore', self::$testDatastore);
@@ -107,7 +107,7 @@ class PostLinkTest extends TestCase
107 /** 107 /**
108 * After every test, remove the test datastore. 108 * After every test, remove the test datastore.
109 */ 109 */
110 public function tearDown() 110 protected function tearDown(): void
111 { 111 {
112 @unlink(self::$testDatastore); 112 @unlink(self::$testDatastore);
113 @unlink(self::$testHistory); 113 @unlink(self::$testHistory);
diff --git a/tests/api/controllers/links/PutLinkTest.php b/tests/api/controllers/links/PutLinkTest.php
index 302cac0f..a2e87c59 100644
--- a/tests/api/controllers/links/PutLinkTest.php
+++ b/tests/api/controllers/links/PutLinkTest.php
@@ -12,7 +12,7 @@ use Slim\Http\Environment;
12use Slim\Http\Request; 12use Slim\Http\Request;
13use Slim\Http\Response; 13use Slim\Http\Response;
14 14
15class PutLinkTest extends \PHPUnit\Framework\TestCase 15class PutLinkTest extends \Shaarli\TestCase
16{ 16{
17 /** 17 /**
18 * @var string datastore to test write operations 18 * @var string datastore to test write operations
@@ -62,7 +62,7 @@ class PutLinkTest extends \PHPUnit\Framework\TestCase
62 /** 62 /**
63 * Before every test, instantiate a new Api with its config, plugins and bookmarks. 63 * Before every test, instantiate a new Api with its config, plugins and bookmarks.
64 */ 64 */
65 public function setUp() 65 protected function setUp(): void
66 { 66 {
67 $this->conf = new ConfigManager('tests/utils/config/configJson'); 67 $this->conf = new ConfigManager('tests/utils/config/configJson');
68 $this->conf->set('resource.datastore', self::$testDatastore); 68 $this->conf->set('resource.datastore', self::$testDatastore);
@@ -91,7 +91,7 @@ class PutLinkTest extends \PHPUnit\Framework\TestCase
91 /** 91 /**
92 * After every test, remove the test datastore. 92 * After every test, remove the test datastore.
93 */ 93 */
94 public function tearDown() 94 protected function tearDown(): void
95 { 95 {
96 @unlink(self::$testDatastore); 96 @unlink(self::$testDatastore);
97 @unlink(self::$testHistory); 97 @unlink(self::$testHistory);
@@ -218,12 +218,12 @@ class PutLinkTest extends \PHPUnit\Framework\TestCase
218 218
219 /** 219 /**
220 * Test link update on non existent link => ApiLinkNotFoundException. 220 * Test link update on non existent link => ApiLinkNotFoundException.
221 *
222 * @expectedException Shaarli\Api\Exceptions\ApiLinkNotFoundException
223 * @expectedExceptionMessage Link not found
224 */ 221 */
225 public function testGetLink404() 222 public function testGetLink404()
226 { 223 {
224 $this->expectException(\Shaarli\Api\Exceptions\ApiLinkNotFoundException::class);
225 $this->expectExceptionMessage('Link not found');
226
227 $env = Environment::mock([ 227 $env = Environment::mock([
228 'REQUEST_METHOD' => 'PUT', 228 'REQUEST_METHOD' => 'PUT',
229 ]); 229 ]);
diff --git a/tests/api/controllers/tags/DeleteTagTest.php b/tests/api/controllers/tags/DeleteTagTest.php
index c6748872..1326eb47 100644
--- a/tests/api/controllers/tags/DeleteTagTest.php
+++ b/tests/api/controllers/tags/DeleteTagTest.php
@@ -12,7 +12,7 @@ use Slim\Http\Environment;
12use Slim\Http\Request; 12use Slim\Http\Request;
13use Slim\Http\Response; 13use Slim\Http\Response;
14 14
15class DeleteTagTest extends \PHPUnit\Framework\TestCase 15class DeleteTagTest extends \Shaarli\TestCase
16{ 16{
17 /** 17 /**
18 * @var string datastore to test write operations 18 * @var string datastore to test write operations
@@ -57,7 +57,7 @@ class DeleteTagTest extends \PHPUnit\Framework\TestCase
57 /** 57 /**
58 * Before each test, instantiate a new Api with its config, plugins and bookmarks. 58 * Before each test, instantiate a new Api with its config, plugins and bookmarks.
59 */ 59 */
60 public function setUp() 60 protected function setUp(): void
61 { 61 {
62 $this->conf = new ConfigManager('tests/utils/config/configJson'); 62 $this->conf = new ConfigManager('tests/utils/config/configJson');
63 $this->conf->set('resource.datastore', self::$testDatastore); 63 $this->conf->set('resource.datastore', self::$testDatastore);
@@ -79,7 +79,7 @@ class DeleteTagTest extends \PHPUnit\Framework\TestCase
79 /** 79 /**
80 * After each test, remove the test datastore. 80 * After each test, remove the test datastore.
81 */ 81 */
82 public function tearDown() 82 protected function tearDown(): void
83 { 83 {
84 @unlink(self::$testDatastore); 84 @unlink(self::$testDatastore);
85 @unlink(self::$testHistory); 85 @unlink(self::$testHistory);
@@ -150,12 +150,12 @@ class DeleteTagTest extends \PHPUnit\Framework\TestCase
150 150
151 /** 151 /**
152 * Test DELETE tag endpoint: reach not existing tag. 152 * Test DELETE tag endpoint: reach not existing tag.
153 *
154 * @expectedException Shaarli\Api\Exceptions\ApiTagNotFoundException
155 * @expectedExceptionMessage Tag not found
156 */ 153 */
157 public function testDeleteLink404() 154 public function testDeleteLink404()
158 { 155 {
156 $this->expectException(\Shaarli\Api\Exceptions\ApiTagNotFoundException::class);
157 $this->expectExceptionMessage('Tag not found');
158
159 $tagName = 'nopenope'; 159 $tagName = 'nopenope';
160 $tags = $this->bookmarkService->bookmarksCountPerTag(); 160 $tags = $this->bookmarkService->bookmarksCountPerTag();
161 $this->assertFalse(isset($tags[$tagName])); 161 $this->assertFalse(isset($tags[$tagName]));
diff --git a/tests/api/controllers/tags/GetTagNameTest.php b/tests/api/controllers/tags/GetTagNameTest.php
index b9a81f9b..9c05954b 100644
--- a/tests/api/controllers/tags/GetTagNameTest.php
+++ b/tests/api/controllers/tags/GetTagNameTest.php
@@ -18,7 +18,7 @@ use Slim\Http\Response;
18 * 18 *
19 * @package Shaarli\Api\Controllers 19 * @package Shaarli\Api\Controllers
20 */ 20 */
21class GetTagNameTest extends \PHPUnit\Framework\TestCase 21class GetTagNameTest extends \Shaarli\TestCase
22{ 22{
23 /** 23 /**
24 * @var string datastore to test write operations 24 * @var string datastore to test write operations
@@ -53,7 +53,7 @@ class GetTagNameTest extends \PHPUnit\Framework\TestCase
53 /** 53 /**
54 * Before each test, instantiate a new Api with its config, plugins and bookmarks. 54 * Before each test, instantiate a new Api with its config, plugins and bookmarks.
55 */ 55 */
56 public function setUp() 56 protected function setUp(): void
57 { 57 {
58 $this->conf = new ConfigManager('tests/utils/config/configJson'); 58 $this->conf = new ConfigManager('tests/utils/config/configJson');
59 $this->conf->set('resource.datastore', self::$testDatastore); 59 $this->conf->set('resource.datastore', self::$testDatastore);
@@ -72,7 +72,7 @@ class GetTagNameTest extends \PHPUnit\Framework\TestCase
72 /** 72 /**
73 * After each test, remove the test datastore. 73 * After each test, remove the test datastore.
74 */ 74 */
75 public function tearDown() 75 protected function tearDown(): void
76 { 76 {
77 @unlink(self::$testDatastore); 77 @unlink(self::$testDatastore);
78 } 78 }
@@ -117,12 +117,12 @@ class GetTagNameTest extends \PHPUnit\Framework\TestCase
117 117
118 /** 118 /**
119 * Test basic getTag service: get non existent tag => ApiTagNotFoundException. 119 * Test basic getTag service: get non existent tag => ApiTagNotFoundException.
120 *
121 * @expectedException Shaarli\Api\Exceptions\ApiTagNotFoundException
122 * @expectedExceptionMessage Tag not found
123 */ 120 */
124 public function testGetTag404() 121 public function testGetTag404()
125 { 122 {
123 $this->expectException(\Shaarli\Api\Exceptions\ApiTagNotFoundException::class);
124 $this->expectExceptionMessage('Tag not found');
125
126 $env = Environment::mock([ 126 $env = Environment::mock([
127 'REQUEST_METHOD' => 'GET', 127 'REQUEST_METHOD' => 'GET',
128 ]); 128 ]);
diff --git a/tests/api/controllers/tags/GetTagsTest.php b/tests/api/controllers/tags/GetTagsTest.php
index 53a3326d..3459fdfa 100644
--- a/tests/api/controllers/tags/GetTagsTest.php
+++ b/tests/api/controllers/tags/GetTagsTest.php
@@ -17,7 +17,7 @@ use Slim\Http\Response;
17 * 17 *
18 * @package Shaarli\Api\Controllers 18 * @package Shaarli\Api\Controllers
19 */ 19 */
20class GetTagsTest extends \PHPUnit\Framework\TestCase 20class GetTagsTest extends \Shaarli\TestCase
21{ 21{
22 /** 22 /**
23 * @var string datastore to test write operations 23 * @var string datastore to test write operations
@@ -57,7 +57,7 @@ class GetTagsTest extends \PHPUnit\Framework\TestCase
57 /** 57 /**
58 * Before every test, instantiate a new Api with its config, plugins and bookmarks. 58 * Before every test, instantiate a new Api with its config, plugins and bookmarks.
59 */ 59 */
60 public function setUp() 60 protected function setUp(): void
61 { 61 {
62 $this->conf = new ConfigManager('tests/utils/config/configJson'); 62 $this->conf = new ConfigManager('tests/utils/config/configJson');
63 $this->conf->set('resource.datastore', self::$testDatastore); 63 $this->conf->set('resource.datastore', self::$testDatastore);
@@ -78,7 +78,7 @@ class GetTagsTest extends \PHPUnit\Framework\TestCase
78 /** 78 /**
79 * After every test, remove the test datastore. 79 * After every test, remove the test datastore.
80 */ 80 */
81 public function tearDown() 81 protected function tearDown(): void
82 { 82 {
83 @unlink(self::$testDatastore); 83 @unlink(self::$testDatastore);
84 } 84 }
diff --git a/tests/api/controllers/tags/PutTagTest.php b/tests/api/controllers/tags/PutTagTest.php
index 2a3cc15a..74edde78 100644
--- a/tests/api/controllers/tags/PutTagTest.php
+++ b/tests/api/controllers/tags/PutTagTest.php
@@ -12,7 +12,7 @@ use Slim\Http\Environment;
12use Slim\Http\Request; 12use Slim\Http\Request;
13use Slim\Http\Response; 13use Slim\Http\Response;
14 14
15class PutTagTest extends \PHPUnit\Framework\TestCase 15class PutTagTest extends \Shaarli\TestCase
16{ 16{
17 /** 17 /**
18 * @var string datastore to test write operations 18 * @var string datastore to test write operations
@@ -62,7 +62,7 @@ class PutTagTest extends \PHPUnit\Framework\TestCase
62 /** 62 /**
63 * Before every test, instantiate a new Api with its config, plugins and bookmarks. 63 * Before every test, instantiate a new Api with its config, plugins and bookmarks.
64 */ 64 */
65 public function setUp() 65 protected function setUp(): void
66 { 66 {
67 $this->conf = new ConfigManager('tests/utils/config/configJson'); 67 $this->conf = new ConfigManager('tests/utils/config/configJson');
68 $this->conf->set('resource.datastore', self::$testDatastore); 68 $this->conf->set('resource.datastore', self::$testDatastore);
@@ -84,7 +84,7 @@ class PutTagTest extends \PHPUnit\Framework\TestCase
84 /** 84 /**
85 * After every test, remove the test datastore. 85 * After every test, remove the test datastore.
86 */ 86 */
87 public function tearDown() 87 protected function tearDown(): void
88 { 88 {
89 @unlink(self::$testDatastore); 89 @unlink(self::$testDatastore);
90 @unlink(self::$testHistory); 90 @unlink(self::$testHistory);
@@ -159,12 +159,12 @@ class PutTagTest extends \PHPUnit\Framework\TestCase
159 159
160 /** 160 /**
161 * Test tag update with an empty new tag name => ApiBadParametersException 161 * Test tag update with an empty new tag name => ApiBadParametersException
162 *
163 * @expectedException Shaarli\Api\Exceptions\ApiBadParametersException
164 * @expectedExceptionMessage New tag name is required in the request body
165 */ 162 */
166 public function testPutTagEmpty() 163 public function testPutTagEmpty()
167 { 164 {
165 $this->expectException(\Shaarli\Api\Exceptions\ApiBadParametersException::class);
166 $this->expectExceptionMessage('New tag name is required in the request body');
167
168 $tagName = 'gnu'; 168 $tagName = 'gnu';
169 $newName = ''; 169 $newName = '';
170 170
@@ -194,12 +194,12 @@ class PutTagTest extends \PHPUnit\Framework\TestCase
194 194
195 /** 195 /**
196 * Test tag update on non existent tag => ApiTagNotFoundException. 196 * Test tag update on non existent tag => ApiTagNotFoundException.
197 *
198 * @expectedException Shaarli\Api\Exceptions\ApiTagNotFoundException
199 * @expectedExceptionMessage Tag not found
200 */ 197 */
201 public function testPutTag404() 198 public function testPutTag404()
202 { 199 {
200 $this->expectException(\Shaarli\Api\Exceptions\ApiTagNotFoundException::class);
201 $this->expectExceptionMessage('Tag not found');
202
203 $env = Environment::mock([ 203 $env = Environment::mock([
204 'REQUEST_METHOD' => 'PUT', 204 'REQUEST_METHOD' => 'PUT',
205 ]); 205 ]);
diff --git a/tests/bookmark/BookmarkArrayTest.php b/tests/bookmark/BookmarkArrayTest.php
index 0f8f04c5..ebed9bfc 100644
--- a/tests/bookmark/BookmarkArrayTest.php
+++ b/tests/bookmark/BookmarkArrayTest.php
@@ -2,10 +2,7 @@
2 2
3namespace Shaarli\Bookmark; 3namespace Shaarli\Bookmark;
4 4
5use PHPUnit\Framework\TestCase; 5use Shaarli\TestCase;
6use Shaarli\Bookmark\Exception\InvalidBookmarkException;
7use Shaarli\Config\ConfigManager;
8use Shaarli\History;
9 6
10/** 7/**
11 * Class BookmarkArrayTest 8 * Class BookmarkArrayTest
@@ -47,22 +44,22 @@ class BookmarkArrayTest extends TestCase
47 44
48 /** 45 /**
49 * Test adding a bad entry: wrong type 46 * Test adding a bad entry: wrong type
50 *
51 * @expectedException Shaarli\Bookmark\Exception\InvalidBookmarkException
52 */ 47 */
53 public function testArrayAccessAddBadEntryInstance() 48 public function testArrayAccessAddBadEntryInstance()
54 { 49 {
50 $this->expectException(\Shaarli\Bookmark\Exception\InvalidBookmarkException::class);
51
55 $array = new BookmarkArray(); 52 $array = new BookmarkArray();
56 $array[] = 'nope'; 53 $array[] = 'nope';
57 } 54 }
58 55
59 /** 56 /**
60 * Test adding a bad entry: no id 57 * Test adding a bad entry: no id
61 *
62 * @expectedException Shaarli\Bookmark\Exception\InvalidBookmarkException
63 */ 58 */
64 public function testArrayAccessAddBadEntryNoId() 59 public function testArrayAccessAddBadEntryNoId()
65 { 60 {
61 $this->expectException(\Shaarli\Bookmark\Exception\InvalidBookmarkException::class);
62
66 $array = new BookmarkArray(); 63 $array = new BookmarkArray();
67 $bookmark = new Bookmark(); 64 $bookmark = new Bookmark();
68 $array[] = $bookmark; 65 $array[] = $bookmark;
@@ -70,11 +67,11 @@ class BookmarkArrayTest extends TestCase
70 67
71 /** 68 /**
72 * Test adding a bad entry: no url 69 * Test adding a bad entry: no url
73 *
74 * @expectedException Shaarli\Bookmark\Exception\InvalidBookmarkException
75 */ 70 */
76 public function testArrayAccessAddBadEntryNoUrl() 71 public function testArrayAccessAddBadEntryNoUrl()
77 { 72 {
73 $this->expectException(\Shaarli\Bookmark\Exception\InvalidBookmarkException::class);
74
78 $array = new BookmarkArray(); 75 $array = new BookmarkArray();
79 $bookmark = (new Bookmark())->setId(11); 76 $bookmark = (new Bookmark())->setId(11);
80 $array[] = $bookmark; 77 $array[] = $bookmark;
@@ -82,11 +79,11 @@ class BookmarkArrayTest extends TestCase
82 79
83 /** 80 /**
84 * Test adding a bad entry: invalid offset 81 * Test adding a bad entry: invalid offset
85 *
86 * @expectedException Shaarli\Bookmark\Exception\InvalidBookmarkException
87 */ 82 */
88 public function testArrayAccessAddBadEntryOffset() 83 public function testArrayAccessAddBadEntryOffset()
89 { 84 {
85 $this->expectException(\Shaarli\Bookmark\Exception\InvalidBookmarkException::class);
86
90 $array = new BookmarkArray(); 87 $array = new BookmarkArray();
91 $bookmark = (new Bookmark())->setId(11); 88 $bookmark = (new Bookmark())->setId(11);
92 $bookmark->validate(); 89 $bookmark->validate();
@@ -95,11 +92,11 @@ class BookmarkArrayTest extends TestCase
95 92
96 /** 93 /**
97 * Test adding a bad entry: invalid ID type 94 * Test adding a bad entry: invalid ID type
98 *
99 * @expectedException Shaarli\Bookmark\Exception\InvalidBookmarkException
100 */ 95 */
101 public function testArrayAccessAddBadEntryIdType() 96 public function testArrayAccessAddBadEntryIdType()
102 { 97 {
98 $this->expectException(\Shaarli\Bookmark\Exception\InvalidBookmarkException::class);
99
103 $array = new BookmarkArray(); 100 $array = new BookmarkArray();
104 $bookmark = (new Bookmark())->setId('nope'); 101 $bookmark = (new Bookmark())->setId('nope');
105 $bookmark->validate(); 102 $bookmark->validate();
@@ -108,11 +105,11 @@ class BookmarkArrayTest extends TestCase
108 105
109 /** 106 /**
110 * Test adding a bad entry: ID/offset not consistent 107 * Test adding a bad entry: ID/offset not consistent
111 *
112 * @expectedException Shaarli\Bookmark\Exception\InvalidBookmarkException
113 */ 108 */
114 public function testArrayAccessAddBadEntryIdOffset() 109 public function testArrayAccessAddBadEntryIdOffset()
115 { 110 {
111 $this->expectException(\Shaarli\Bookmark\Exception\InvalidBookmarkException::class);
112
116 $array = new BookmarkArray(); 113 $array = new BookmarkArray();
117 $bookmark = (new Bookmark())->setId(11); 114 $bookmark = (new Bookmark())->setId(11);
118 $bookmark->validate(); 115 $bookmark->validate();
diff --git a/tests/bookmark/BookmarkFileServiceTest.php b/tests/bookmark/BookmarkFileServiceTest.php
index 7b1906d3..c399822b 100644
--- a/tests/bookmark/BookmarkFileServiceTest.php
+++ b/tests/bookmark/BookmarkFileServiceTest.php
@@ -6,7 +6,6 @@
6namespace Shaarli\Bookmark; 6namespace Shaarli\Bookmark;
7 7
8use DateTime; 8use DateTime;
9use PHPUnit\Framework\TestCase;
10use ReferenceLinkDB; 9use ReferenceLinkDB;
11use ReflectionClass; 10use ReflectionClass;
12use Shaarli; 11use Shaarli;
@@ -14,6 +13,7 @@ use Shaarli\Bookmark\Exception\BookmarkNotFoundException;
14use Shaarli\Config\ConfigManager; 13use Shaarli\Config\ConfigManager;
15use Shaarli\Formatter\BookmarkMarkdownFormatter; 14use Shaarli\Formatter\BookmarkMarkdownFormatter;
16use Shaarli\History; 15use Shaarli\History;
16use Shaarli\TestCase;
17 17
18/** 18/**
19 * Unitary tests for LegacyLinkDBTest 19 * Unitary tests for LegacyLinkDBTest
@@ -66,7 +66,7 @@ class BookmarkFileServiceTest extends TestCase
66 * 66 *
67 * Resets test data for each test 67 * Resets test data for each test
68 */ 68 */
69 protected function setUp() 69 protected function setUp(): void
70 { 70 {
71 if (file_exists(self::$testDatastore)) { 71 if (file_exists(self::$testDatastore)) {
72 unlink(self::$testDatastore); 72 unlink(self::$testDatastore);
@@ -134,11 +134,11 @@ class BookmarkFileServiceTest extends TestCase
134 134
135 /** 135 /**
136 * Test get() method for an undefined bookmark 136 * Test get() method for an undefined bookmark
137 *
138 * @expectedException Shaarli\Bookmark\Exception\BookmarkNotFoundException
139 */ 137 */
140 public function testGetUndefined() 138 public function testGetUndefined()
141 { 139 {
140 $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class);
141
142 $this->privateLinkDB->get(666); 142 $this->privateLinkDB->get(666);
143 } 143 }
144 144
@@ -230,13 +230,13 @@ class BookmarkFileServiceTest extends TestCase
230 230
231 /** 231 /**
232 * Test add() method for a bookmark without any field set and without writing the data store 232 * Test add() method for a bookmark without any field set and without writing the data store
233 *
234 * @expectedExceptionMessage Shaarli\Bookmark\Exception\BookmarkNotFoundException
235 */ 233 */
236 public function testAddMinimalNoWrite() 234 public function testAddMinimalNoWrite()
237 { 235 {
236 $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class);
237
238 $bookmark = new Bookmark(); 238 $bookmark = new Bookmark();
239 $this->privateLinkDB->add($bookmark); 239 $this->privateLinkDB->add($bookmark, false);
240 240
241 $bookmark = $this->privateLinkDB->get(43); 241 $bookmark = $this->privateLinkDB->get(43);
242 $this->assertEquals(43, $bookmark->getId()); 242 $this->assertEquals(43, $bookmark->getId());
@@ -249,34 +249,34 @@ class BookmarkFileServiceTest extends TestCase
249 249
250 /** 250 /**
251 * Test add() method while logged out 251 * Test add() method while logged out
252 *
253 * @expectedException \Exception
254 * @expectedExceptionMessage You're not authorized to alter the datastore
255 */ 252 */
256 public function testAddLoggedOut() 253 public function testAddLoggedOut()
257 { 254 {
255 $this->expectException(\Exception::class);
256 $this->expectExceptionMessage('You\'re not authorized to alter the datastore');
257
258 $this->publicLinkDB->add(new Bookmark()); 258 $this->publicLinkDB->add(new Bookmark());
259 } 259 }
260 260
261 /** 261 /**
262 * Test add() method with an entry which is not a bookmark instance 262 * Test add() method with an entry which is not a bookmark instance
263 *
264 * @expectedException \Exception
265 * @expectedExceptionMessage Provided data is invalid
266 */ 263 */
267 public function testAddNotABookmark() 264 public function testAddNotABookmark()
268 { 265 {
266 $this->expectException(\Exception::class);
267 $this->expectExceptionMessage('Provided data is invalid');
268
269 $this->privateLinkDB->add(['title' => 'hi!']); 269 $this->privateLinkDB->add(['title' => 'hi!']);
270 } 270 }
271 271
272 /** 272 /**
273 * Test add() method with a Bookmark already containing an ID 273 * Test add() method with a Bookmark already containing an ID
274 *
275 * @expectedException \Exception
276 * @expectedExceptionMessage This bookmarks already exists
277 */ 274 */
278 public function testAddWithId() 275 public function testAddWithId()
279 { 276 {
277 $this->expectException(\Exception::class);
278 $this->expectExceptionMessage('This bookmarks already exists');
279
280 $bookmark = new Bookmark(); 280 $bookmark = new Bookmark();
281 $bookmark->setId(43); 281 $bookmark->setId(43);
282 $this->privateLinkDB->add($bookmark); 282 $this->privateLinkDB->add($bookmark);
@@ -397,44 +397,44 @@ class BookmarkFileServiceTest extends TestCase
397 397
398 /** 398 /**
399 * Test set() method while logged out 399 * Test set() method while logged out
400 *
401 * @expectedException \Exception
402 * @expectedExceptionMessage You're not authorized to alter the datastore
403 */ 400 */
404 public function testSetLoggedOut() 401 public function testSetLoggedOut()
405 { 402 {
403 $this->expectException(\Exception::class);
404 $this->expectExceptionMessage('You\'re not authorized to alter the datastore');
405
406 $this->publicLinkDB->set(new Bookmark()); 406 $this->publicLinkDB->set(new Bookmark());
407 } 407 }
408 408
409 /** 409 /**
410 * Test set() method with an entry which is not a bookmark instance 410 * Test set() method with an entry which is not a bookmark instance
411 *
412 * @expectedException \Exception
413 * @expectedExceptionMessage Provided data is invalid
414 */ 411 */
415 public function testSetNotABookmark() 412 public function testSetNotABookmark()
416 { 413 {
414 $this->expectException(\Exception::class);
415 $this->expectExceptionMessage('Provided data is invalid');
416
417 $this->privateLinkDB->set(['title' => 'hi!']); 417 $this->privateLinkDB->set(['title' => 'hi!']);
418 } 418 }
419 419
420 /** 420 /**
421 * Test set() method with a Bookmark without an ID defined. 421 * Test set() method with a Bookmark without an ID defined.
422 *
423 * @expectedException Shaarli\Bookmark\Exception\BookmarkNotFoundException
424 */ 422 */
425 public function testSetWithoutId() 423 public function testSetWithoutId()
426 { 424 {
425 $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class);
426
427 $bookmark = new Bookmark(); 427 $bookmark = new Bookmark();
428 $this->privateLinkDB->set($bookmark); 428 $this->privateLinkDB->set($bookmark);
429 } 429 }
430 430
431 /** 431 /**
432 * Test set() method with a Bookmark with an unknow ID 432 * Test set() method with a Bookmark with an unknow ID
433 *
434 * @expectedException Shaarli\Bookmark\Exception\BookmarkNotFoundException
435 */ 433 */
436 public function testSetWithUnknownId() 434 public function testSetWithUnknownId()
437 { 435 {
436 $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class);
437
438 $bookmark = new Bookmark(); 438 $bookmark = new Bookmark();
439 $bookmark->setId(666); 439 $bookmark->setId(666);
440 $this->privateLinkDB->set($bookmark); 440 $this->privateLinkDB->set($bookmark);
@@ -481,23 +481,23 @@ class BookmarkFileServiceTest extends TestCase
481 481
482 /** 482 /**
483 * Test addOrSet() method while logged out 483 * Test addOrSet() method while logged out
484 *
485 * @expectedException \Exception
486 * @expectedExceptionMessage You're not authorized to alter the datastore
487 */ 484 */
488 public function testAddOrSetLoggedOut() 485 public function testAddOrSetLoggedOut()
489 { 486 {
487 $this->expectException(\Exception::class);
488 $this->expectExceptionMessage('You\'re not authorized to alter the datastore');
489
490 $this->publicLinkDB->addOrSet(new Bookmark()); 490 $this->publicLinkDB->addOrSet(new Bookmark());
491 } 491 }
492 492
493 /** 493 /**
494 * Test addOrSet() method with an entry which is not a bookmark instance 494 * Test addOrSet() method with an entry which is not a bookmark instance
495 *
496 * @expectedException \Exception
497 * @expectedExceptionMessage Provided data is invalid
498 */ 495 */
499 public function testAddOrSetNotABookmark() 496 public function testAddOrSetNotABookmark()
500 { 497 {
498 $this->expectException(\Exception::class);
499 $this->expectExceptionMessage('Provided data is invalid');
500
501 $this->privateLinkDB->addOrSet(['title' => 'hi!']); 501 $this->privateLinkDB->addOrSet(['title' => 'hi!']);
502 } 502 }
503 503
@@ -524,11 +524,11 @@ class BookmarkFileServiceTest extends TestCase
524 524
525 /** 525 /**
526 * Test remove() method with an existing Bookmark 526 * Test remove() method with an existing Bookmark
527 *
528 * @expectedException Shaarli\Bookmark\Exception\BookmarkNotFoundException
529 */ 527 */
530 public function testRemoveExisting() 528 public function testRemoveExisting()
531 { 529 {
530 $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class);
531
532 $bookmark = $this->privateLinkDB->get(42); 532 $bookmark = $this->privateLinkDB->get(42);
533 $this->privateLinkDB->remove($bookmark); 533 $this->privateLinkDB->remove($bookmark);
534 534
@@ -548,34 +548,34 @@ class BookmarkFileServiceTest extends TestCase
548 548
549 /** 549 /**
550 * Test remove() method while logged out 550 * Test remove() method while logged out
551 *
552 * @expectedException \Exception
553 * @expectedExceptionMessage You're not authorized to alter the datastore
554 */ 551 */
555 public function testRemoveLoggedOut() 552 public function testRemoveLoggedOut()
556 { 553 {
554 $this->expectException(\Exception::class);
555 $this->expectExceptionMessage('You\'re not authorized to alter the datastore');
556
557 $bookmark = $this->privateLinkDB->get(42); 557 $bookmark = $this->privateLinkDB->get(42);
558 $this->publicLinkDB->remove($bookmark); 558 $this->publicLinkDB->remove($bookmark);
559 } 559 }
560 560
561 /** 561 /**
562 * Test remove() method with an entry which is not a bookmark instance 562 * Test remove() method with an entry which is not a bookmark instance
563 *
564 * @expectedException \Exception
565 * @expectedExceptionMessage Provided data is invalid
566 */ 563 */
567 public function testRemoveNotABookmark() 564 public function testRemoveNotABookmark()
568 { 565 {
566 $this->expectException(\Exception::class);
567 $this->expectExceptionMessage('Provided data is invalid');
568
569 $this->privateLinkDB->remove(['title' => 'hi!']); 569 $this->privateLinkDB->remove(['title' => 'hi!']);
570 } 570 }
571 571
572 /** 572 /**
573 * Test remove() method with a Bookmark with an unknown ID 573 * Test remove() method with a Bookmark with an unknown ID
574 *
575 * @expectedException Shaarli\Bookmark\Exception\BookmarkNotFoundException
576 */ 574 */
577 public function testRemoveWithUnknownId() 575 public function testRemoveWithUnknownId()
578 { 576 {
577 $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class);
578
579 $bookmark = new Bookmark(); 579 $bookmark = new Bookmark();
580 $bookmark->setId(666); 580 $bookmark->setId(666);
581 $this->privateLinkDB->remove($bookmark); 581 $this->privateLinkDB->remove($bookmark);
@@ -615,14 +615,18 @@ class BookmarkFileServiceTest extends TestCase
615 { 615 {
616 $dbSize = $this->privateLinkDB->count(); 616 $dbSize = $this->privateLinkDB->count();
617 $this->privateLinkDB->initialize(); 617 $this->privateLinkDB->initialize();
618 $this->assertEquals($dbSize + 2, $this->privateLinkDB->count()); 618 $this->assertEquals($dbSize + 3, $this->privateLinkDB->count());
619 $this->assertEquals( 619 $this->assertStringStartsWith(
620 'My secret stuff... - Pastebin.com', 620 'Shaarli will automatically pick up the thumbnail for links to a variety of websites.',
621 $this->privateLinkDB->get(43)->getTitle() 621 $this->privateLinkDB->get(43)->getDescription()
622 ); 622 );
623 $this->assertEquals( 623 $this->assertStringStartsWith(
624 'The personal, minimalist, super-fast, database free, bookmarking service', 624 'Adding a shaare without entering a URL creates a text-only "note" post such as this one.',
625 $this->privateLinkDB->get(44)->getTitle() 625 $this->privateLinkDB->get(44)->getDescription()
626 );
627 $this->assertStringStartsWith(
628 'Welcome to Shaarli!',
629 $this->privateLinkDB->get(45)->getDescription()
626 ); 630 );
627 } 631 }
628 632
@@ -631,15 +635,14 @@ class BookmarkFileServiceTest extends TestCase
631 * to make sure that nothing have been broken in the migration process. 635 * to make sure that nothing have been broken in the migration process.
632 * They mostly cover search/filters. Some of them might be redundant with the previous ones. 636 * They mostly cover search/filters. Some of them might be redundant with the previous ones.
633 */ 637 */
634
635 /** 638 /**
636 * Attempt to instantiate a LinkDB whereas the datastore is not writable 639 * Attempt to instantiate a LinkDB whereas the datastore is not writable
637 *
638 * @expectedException Shaarli\Bookmark\Exception\NotWritableDataStoreException
639 * @expectedExceptionMessageRegExp #Couldn't load data from the data store file "null".*#
640 */ 640 */
641 public function testConstructDatastoreNotWriteable() 641 public function testConstructDatastoreNotWriteable()
642 { 642 {
643 $this->expectException(\Shaarli\Bookmark\Exception\NotWritableDataStoreException::class);
644 $this->expectExceptionMessageRegExp('#Couldn\'t load data from the data store file "null".*#');
645
643 $conf = new ConfigManager('tests/utils/config/configJson'); 646 $conf = new ConfigManager('tests/utils/config/configJson');
644 $conf->set('resource.datastore', 'null/store.db'); 647 $conf->set('resource.datastore', 'null/store.db');
645 new BookmarkFileService($conf, $this->history, true); 648 new BookmarkFileService($conf, $this->history, true);
@@ -744,7 +747,7 @@ class BookmarkFileServiceTest extends TestCase
744 $link = $this->publicLinkDB->findByUrl('http://mediagoblin.org/'); 747 $link = $this->publicLinkDB->findByUrl('http://mediagoblin.org/');
745 748
746 $this->assertNotEquals(false, $link); 749 $this->assertNotEquals(false, $link);
747 $this->assertContains( 750 $this->assertContainsPolyfill(
748 'A free software media publishing platform', 751 'A free software media publishing platform',
749 $link->getDescription() 752 $link->getDescription()
750 ); 753 );
@@ -1062,6 +1065,36 @@ class BookmarkFileServiceTest extends TestCase
1062 } 1065 }
1063 1066
1064 /** 1067 /**
1068 * Test filterDay while logged in
1069 */
1070 public function testFilterDayLoggedIn(): void
1071 {
1072 $bookmarks = $this->privateLinkDB->filterDay('20121206');
1073 $expectedIds = [4, 9, 1, 0];
1074
1075 static::assertCount(4, $bookmarks);
1076 foreach ($bookmarks as $bookmark) {
1077 $i = ($i ?? -1) + 1;
1078 static::assertSame($expectedIds[$i], $bookmark->getId());
1079 }
1080 }
1081
1082 /**
1083 * Test filterDay while logged out
1084 */
1085 public function testFilterDayLoggedOut(): void
1086 {
1087 $bookmarks = $this->publicLinkDB->filterDay('20121206');
1088 $expectedIds = [4, 9, 1];
1089
1090 static::assertCount(3, $bookmarks);
1091 foreach ($bookmarks as $bookmark) {
1092 $i = ($i ?? -1) + 1;
1093 static::assertSame($expectedIds[$i], $bookmark->getId());
1094 }
1095 }
1096
1097 /**
1065 * Allows to test LinkDB's private methods 1098 * Allows to test LinkDB's private methods
1066 * 1099 *
1067 * @see 1100 * @see
diff --git a/tests/bookmark/BookmarkFilterTest.php b/tests/bookmark/BookmarkFilterTest.php
index d4c71cb9..48c7f824 100644
--- a/tests/bookmark/BookmarkFilterTest.php
+++ b/tests/bookmark/BookmarkFilterTest.php
@@ -3,11 +3,10 @@
3namespace Shaarli\Bookmark; 3namespace Shaarli\Bookmark;
4 4
5use Exception; 5use Exception;
6use PHPUnit\Framework\TestCase;
7use ReferenceLinkDB; 6use ReferenceLinkDB;
8use Shaarli\Config\ConfigManager; 7use Shaarli\Config\ConfigManager;
9use Shaarli\Formatter\FormatterFactory;
10use Shaarli\History; 8use Shaarli\History;
9use Shaarli\TestCase;
11 10
12/** 11/**
13 * Class BookmarkFilterTest. 12 * Class BookmarkFilterTest.
@@ -36,7 +35,7 @@ class BookmarkFilterTest extends TestCase
36 /** 35 /**
37 * Instantiate linkFilter with ReferenceLinkDB data. 36 * Instantiate linkFilter with ReferenceLinkDB data.
38 */ 37 */
39 public static function setUpBeforeClass() 38 public static function setUpBeforeClass(): void
40 { 39 {
41 $conf = new ConfigManager('tests/utils/config/configJson'); 40 $conf = new ConfigManager('tests/utils/config/configJson');
42 $conf->set('resource.datastore', self::$testDatastore); 41 $conf->set('resource.datastore', self::$testDatastore);
@@ -190,6 +189,17 @@ class BookmarkFilterTest extends TestCase
190 } 189 }
191 190
192 /** 191 /**
192 * Return bookmarks for a given day
193 */
194 public function testFilterDayRestrictedVisibility(): void
195 {
196 $this->assertEquals(
197 3,
198 count(self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, '20121206', false, BookmarkFilter::$PUBLIC))
199 );
200 }
201
202 /**
193 * 404 - day not found 203 * 404 - day not found
194 */ 204 */
195 public function testFilterUnknownDay() 205 public function testFilterUnknownDay()
@@ -202,21 +212,23 @@ class BookmarkFilterTest extends TestCase
202 212
203 /** 213 /**
204 * Use an invalid date format 214 * Use an invalid date format
205 * @expectedException Exception
206 * @expectedExceptionMessageRegExp /Invalid date format/
207 */ 215 */
208 public function testFilterInvalidDayWithChars() 216 public function testFilterInvalidDayWithChars()
209 { 217 {
218 $this->expectException(\Exception::class);
219 $this->expectExceptionMessageRegExp('/Invalid date format/');
220
210 self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, 'Rainy day, dream away'); 221 self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, 'Rainy day, dream away');
211 } 222 }
212 223
213 /** 224 /**
214 * Use an invalid date format 225 * Use an invalid date format
215 * @expectedException Exception
216 * @expectedExceptionMessageRegExp /Invalid date format/
217 */ 226 */
218 public function testFilterInvalidDayDigits() 227 public function testFilterInvalidDayDigits()
219 { 228 {
229 $this->expectException(\Exception::class);
230 $this->expectExceptionMessageRegExp('/Invalid date format/');
231
220 self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, '20'); 232 self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, '20');
221 } 233 }
222 234
@@ -240,11 +252,11 @@ class BookmarkFilterTest extends TestCase
240 252
241 /** 253 /**
242 * No link for this hash 254 * No link for this hash
243 *
244 * @expectedException \Shaarli\Bookmark\Exception\BookmarkNotFoundException
245 */ 255 */
246 public function testFilterUnknownSmallHash() 256 public function testFilterUnknownSmallHash()
247 { 257 {
258 $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class);
259
248 self::$linkFilter->filter(BookmarkFilter::$FILTER_HASH, 'Iblaah'); 260 self::$linkFilter->filter(BookmarkFilter::$FILTER_HASH, 'Iblaah');
249 } 261 }
250 262
diff --git a/tests/bookmark/BookmarkInitializerTest.php b/tests/bookmark/BookmarkInitializerTest.php
index 3906cc7f..25704004 100644
--- a/tests/bookmark/BookmarkInitializerTest.php
+++ b/tests/bookmark/BookmarkInitializerTest.php
@@ -2,9 +2,9 @@
2 2
3namespace Shaarli\Bookmark; 3namespace Shaarli\Bookmark;
4 4
5use PHPUnit\Framework\TestCase;
6use Shaarli\Config\ConfigManager; 5use Shaarli\Config\ConfigManager;
7use Shaarli\History; 6use Shaarli\History;
7use Shaarli\TestCase;
8 8
9/** 9/**
10 * Class BookmarkInitializerTest 10 * Class BookmarkInitializerTest
@@ -37,7 +37,7 @@ class BookmarkInitializerTest extends TestCase
37 /** 37 /**
38 * Initialize an empty BookmarkFileService 38 * Initialize an empty BookmarkFileService
39 */ 39 */
40 public function setUp() 40 public function setUp(): void
41 { 41 {
42 if (file_exists(self::$testDatastore)) { 42 if (file_exists(self::$testDatastore)) {
43 unlink(self::$testDatastore); 43 unlink(self::$testDatastore);
@@ -64,17 +64,26 @@ class BookmarkInitializerTest extends TestCase
64 64
65 $this->initializer->initialize(); 65 $this->initializer->initialize();
66 66
67 $this->assertEquals($refDB->countLinks() + 2, $this->bookmarkService->count()); 67 $this->assertEquals($refDB->countLinks() + 3, $this->bookmarkService->count());
68
68 $bookmark = $this->bookmarkService->get(43); 69 $bookmark = $this->bookmarkService->get(43);
69 $this->assertEquals(43, $bookmark->getId()); 70 $this->assertStringStartsWith(
70 $this->assertEquals('My secret stuff... - Pastebin.com', $bookmark->getTitle()); 71 'Shaarli will automatically pick up the thumbnail for links to a variety of websites.',
72 $bookmark->getDescription()
73 );
71 $this->assertTrue($bookmark->isPrivate()); 74 $this->assertTrue($bookmark->isPrivate());
72 75
73 $bookmark = $this->bookmarkService->get(44); 76 $bookmark = $this->bookmarkService->get(44);
74 $this->assertEquals(44, $bookmark->getId()); 77 $this->assertStringStartsWith(
75 $this->assertEquals( 78 'Adding a shaare without entering a URL creates a text-only "note" post such as this one.',
76 'The personal, minimalist, super-fast, database free, bookmarking service', 79 $bookmark->getDescription()
77 $bookmark->getTitle() 80 );
81 $this->assertTrue($bookmark->isPrivate());
82
83 $bookmark = $this->bookmarkService->get(45);
84 $this->assertStringStartsWith(
85 'Welcome to Shaarli!',
86 $bookmark->getDescription()
78 ); 87 );
79 $this->assertFalse($bookmark->isPrivate()); 88 $this->assertFalse($bookmark->isPrivate());
80 89
@@ -82,17 +91,26 @@ class BookmarkInitializerTest extends TestCase
82 91
83 // Reload from file 92 // Reload from file
84 $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); 93 $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true);
85 $this->assertEquals($refDB->countLinks() + 2, $this->bookmarkService->count()); 94 $this->assertEquals($refDB->countLinks() + 3, $this->bookmarkService->count());
95
86 $bookmark = $this->bookmarkService->get(43); 96 $bookmark = $this->bookmarkService->get(43);
87 $this->assertEquals(43, $bookmark->getId()); 97 $this->assertStringStartsWith(
88 $this->assertEquals('My secret stuff... - Pastebin.com', $bookmark->getTitle()); 98 'Shaarli will automatically pick up the thumbnail for links to a variety of websites.',
99 $bookmark->getDescription()
100 );
89 $this->assertTrue($bookmark->isPrivate()); 101 $this->assertTrue($bookmark->isPrivate());
90 102
91 $bookmark = $this->bookmarkService->get(44); 103 $bookmark = $this->bookmarkService->get(44);
92 $this->assertEquals(44, $bookmark->getId()); 104 $this->assertStringStartsWith(
93 $this->assertEquals( 105 'Adding a shaare without entering a URL creates a text-only "note" post such as this one.',
94 'The personal, minimalist, super-fast, database free, bookmarking service', 106 $bookmark->getDescription()
95 $bookmark->getTitle() 107 );
108 $this->assertTrue($bookmark->isPrivate());
109
110 $bookmark = $this->bookmarkService->get(45);
111 $this->assertStringStartsWith(
112 'Welcome to Shaarli!',
113 $bookmark->getDescription()
96 ); 114 );
97 $this->assertFalse($bookmark->isPrivate()); 115 $this->assertFalse($bookmark->isPrivate());
98 } 116 }
@@ -107,17 +125,25 @@ class BookmarkInitializerTest extends TestCase
107 125
108 $this->initializer->initialize(); 126 $this->initializer->initialize();
109 127
110 $this->assertEquals(2, $this->bookmarkService->count()); 128 $this->assertEquals(3, $this->bookmarkService->count());
111 $bookmark = $this->bookmarkService->get(0); 129 $bookmark = $this->bookmarkService->get(0);
112 $this->assertEquals(0, $bookmark->getId()); 130 $this->assertStringStartsWith(
113 $this->assertEquals('My secret stuff... - Pastebin.com', $bookmark->getTitle()); 131 'Shaarli will automatically pick up the thumbnail for links to a variety of websites.',
132 $bookmark->getDescription()
133 );
114 $this->assertTrue($bookmark->isPrivate()); 134 $this->assertTrue($bookmark->isPrivate());
115 135
116 $bookmark = $this->bookmarkService->get(1); 136 $bookmark = $this->bookmarkService->get(1);
117 $this->assertEquals(1, $bookmark->getId()); 137 $this->assertStringStartsWith(
118 $this->assertEquals( 138 'Adding a shaare without entering a URL creates a text-only "note" post such as this one.',
119 'The personal, minimalist, super-fast, database free, bookmarking service', 139 $bookmark->getDescription()
120 $bookmark->getTitle() 140 );
141 $this->assertTrue($bookmark->isPrivate());
142
143 $bookmark = $this->bookmarkService->get(2);
144 $this->assertStringStartsWith(
145 'Welcome to Shaarli!',
146 $bookmark->getDescription()
121 ); 147 );
122 $this->assertFalse($bookmark->isPrivate()); 148 $this->assertFalse($bookmark->isPrivate());
123 } 149 }
diff --git a/tests/bookmark/BookmarkTest.php b/tests/bookmark/BookmarkTest.php
index 4b6a3c07..afec2440 100644
--- a/tests/bookmark/BookmarkTest.php
+++ b/tests/bookmark/BookmarkTest.php
@@ -2,8 +2,8 @@
2 2
3namespace Shaarli\Bookmark; 3namespace Shaarli\Bookmark;
4 4
5use PHPUnit\Framework\TestCase;
6use Shaarli\Bookmark\Exception\InvalidBookmarkException; 5use Shaarli\Bookmark\Exception\InvalidBookmarkException;
6use Shaarli\TestCase;
7 7
8/** 8/**
9 * Class BookmarkTest 9 * Class BookmarkTest
@@ -150,7 +150,7 @@ class BookmarkTest extends TestCase
150 $exception = $e; 150 $exception = $e;
151 } 151 }
152 $this->assertNotNull($exception); 152 $this->assertNotNull($exception);
153 $this->assertContains('- ID: '. PHP_EOL, $exception->getMessage()); 153 $this->assertContainsPolyfill('- ID: '. PHP_EOL, $exception->getMessage());
154 } 154 }
155 155
156 /** 156 /**
@@ -169,7 +169,7 @@ class BookmarkTest extends TestCase
169 $exception = $e; 169 $exception = $e;
170 } 170 }
171 $this->assertNotNull($exception); 171 $this->assertNotNull($exception);
172 $this->assertContains('- ID: str'. PHP_EOL, $exception->getMessage()); 172 $this->assertContainsPolyfill('- ID: str'. PHP_EOL, $exception->getMessage());
173 } 173 }
174 174
175 /** 175 /**
@@ -188,7 +188,7 @@ class BookmarkTest extends TestCase
188 $exception = $e; 188 $exception = $e;
189 } 189 }
190 $this->assertNotNull($exception); 190 $this->assertNotNull($exception);
191 $this->assertContains('- ShortUrl: '. PHP_EOL, $exception->getMessage()); 191 $this->assertContainsPolyfill('- ShortUrl: '. PHP_EOL, $exception->getMessage());
192 } 192 }
193 193
194 /** 194 /**
@@ -207,7 +207,7 @@ class BookmarkTest extends TestCase
207 $exception = $e; 207 $exception = $e;
208 } 208 }
209 $this->assertNotNull($exception); 209 $this->assertNotNull($exception);
210 $this->assertContains('- Created: '. PHP_EOL, $exception->getMessage()); 210 $this->assertContainsPolyfill('- Created: '. PHP_EOL, $exception->getMessage());
211 } 211 }
212 212
213 /** 213 /**
@@ -226,7 +226,7 @@ class BookmarkTest extends TestCase
226 $exception = $e; 226 $exception = $e;
227 } 227 }
228 $this->assertNotNull($exception); 228 $this->assertNotNull($exception);
229 $this->assertContains('- Created: Not a DateTime object'. PHP_EOL, $exception->getMessage()); 229 $this->assertContainsPolyfill('- Created: Not a DateTime object'. PHP_EOL, $exception->getMessage());
230 } 230 }
231 231
232 /** 232 /**
diff --git a/tests/bookmark/LinkUtilsTest.php b/tests/bookmark/LinkUtilsTest.php
index 7d4a7b89..ef00b92f 100644
--- a/tests/bookmark/LinkUtilsTest.php
+++ b/tests/bookmark/LinkUtilsTest.php
@@ -2,7 +2,7 @@
2 2
3namespace Shaarli\Bookmark; 3namespace Shaarli\Bookmark;
4 4
5use PHPUnit\Framework\TestCase; 5use Shaarli\TestCase;
6 6
7require_once 'tests/utils/CurlUtils.php'; 7require_once 'tests/utils/CurlUtils.php';
8 8
@@ -43,6 +43,19 @@ class LinkUtilsTest extends TestCase
43 } 43 }
44 44
45 /** 45 /**
46 * Test headers_extract_charset() when the charset is found with odd quotes.
47 */
48 public function testHeadersExtractExistentCharsetWithQuotes()
49 {
50 $charset = 'x-MacCroatian';
51 $headers = 'text/html; charset="' . $charset . '"otherstuff="test"';
52 $this->assertEquals(strtolower($charset), header_extract_charset($headers));
53
54 $headers = 'text/html; charset=\'' . $charset . '\'otherstuff="test"';
55 $this->assertEquals(strtolower($charset), header_extract_charset($headers));
56 }
57
58 /**
46 * Test headers_extract_charset() when the charset is not found. 59 * Test headers_extract_charset() when the charset is not found.
47 */ 60 */
48 public function testHeadersExtractNonExistentCharset() 61 public function testHeadersExtractNonExistentCharset()
@@ -437,13 +450,13 @@ class LinkUtilsTest extends TestCase
437 カタカナ #カタカナ」カタカナ\n'; 450 カタカナ #カタカナ」カタカナ\n';
438 $autolinkedDescription = hashtag_autolink($rawDescription, $index); 451 $autolinkedDescription = hashtag_autolink($rawDescription, $index);
439 452
440 $this->assertContains($this->getHashtagLink('hashtag', $index), $autolinkedDescription); 453 $this->assertContainsPolyfill($this->getHashtagLink('hashtag', $index), $autolinkedDescription);
441 $this->assertNotContains(' #hashtag', $autolinkedDescription); 454 $this->assertNotContainsPolyfill(' #hashtag', $autolinkedDescription);
442 $this->assertNotContains('>#nothashtag', $autolinkedDescription); 455 $this->assertNotContainsPolyfill('>#nothashtag', $autolinkedDescription);
443 $this->assertContains($this->getHashtagLink('ашок', $index), $autolinkedDescription); 456 $this->assertContainsPolyfill($this->getHashtagLink('ашок', $index), $autolinkedDescription);
444 $this->assertContains($this->getHashtagLink('カタカナ', $index), $autolinkedDescription); 457 $this->assertContainsPolyfill($this->getHashtagLink('カタカナ', $index), $autolinkedDescription);
445 $this->assertContains($this->getHashtagLink('hashtag_hashtag', $index), $autolinkedDescription); 458 $this->assertContainsPolyfill($this->getHashtagLink('hashtag_hashtag', $index), $autolinkedDescription);
446 $this->assertNotContains($this->getHashtagLink('hashtag-nothashtag', $index), $autolinkedDescription); 459 $this->assertNotContainsPolyfill($this->getHashtagLink('hashtag-nothashtag', $index), $autolinkedDescription);
447 } 460 }
448 461
449 /** 462 /**
@@ -454,9 +467,9 @@ class LinkUtilsTest extends TestCase
454 $rawDescription = 'blabla #hashtag x#nothashtag'; 467 $rawDescription = 'blabla #hashtag x#nothashtag';
455 $autolinkedDescription = hashtag_autolink($rawDescription); 468 $autolinkedDescription = hashtag_autolink($rawDescription);
456 469
457 $this->assertContains($this->getHashtagLink('hashtag'), $autolinkedDescription); 470 $this->assertContainsPolyfill($this->getHashtagLink('hashtag'), $autolinkedDescription);
458 $this->assertNotContains(' #hashtag', $autolinkedDescription); 471 $this->assertNotContainsPolyfill(' #hashtag', $autolinkedDescription);
459 $this->assertNotContains('>#nothashtag', $autolinkedDescription); 472 $this->assertNotContainsPolyfill('>#nothashtag', $autolinkedDescription);
460 } 473 }
461 474
462 /** 475 /**
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index d4ddedd5..2d675c9a 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -18,6 +18,7 @@ require_once 'application/bookmark/LinkUtils.php';
18require_once 'application/Utils.php'; 18require_once 'application/Utils.php';
19require_once 'application/http/UrlUtils.php'; 19require_once 'application/http/UrlUtils.php';
20require_once 'application/http/HttpUtils.php'; 20require_once 'application/http/HttpUtils.php';
21require_once 'tests/TestCase.php';
21require_once 'tests/container/ShaarliTestContainer.php'; 22require_once 'tests/container/ShaarliTestContainer.php';
22require_once 'tests/front/controller/visitor/FrontControllerMockHelper.php'; 23require_once 'tests/front/controller/visitor/FrontControllerMockHelper.php';
23require_once 'tests/front/controller/admin/FrontAdminControllerMockHelper.php'; 24require_once 'tests/front/controller/admin/FrontAdminControllerMockHelper.php';
diff --git a/tests/config/ConfigJsonTest.php b/tests/config/ConfigJsonTest.php
index 33160eb0..c0ba5b8f 100644
--- a/tests/config/ConfigJsonTest.php
+++ b/tests/config/ConfigJsonTest.php
@@ -4,14 +4,14 @@ namespace Shaarli\Config;
4/** 4/**
5 * Class ConfigJsonTest 5 * Class ConfigJsonTest
6 */ 6 */
7class ConfigJsonTest extends \PHPUnit\Framework\TestCase 7class ConfigJsonTest extends \Shaarli\TestCase
8{ 8{
9 /** 9 /**
10 * @var ConfigJson 10 * @var ConfigJson
11 */ 11 */
12 protected $configIO; 12 protected $configIO;
13 13
14 public function setUp() 14 protected function setUp(): void
15 { 15 {
16 $this->configIO = new ConfigJson(); 16 $this->configIO = new ConfigJson();
17 } 17 }
@@ -38,12 +38,12 @@ class ConfigJsonTest extends \PHPUnit\Framework\TestCase
38 38
39 /** 39 /**
40 * Read a non existent config file -> empty array. 40 * Read a non existent config file -> empty array.
41 *
42 * @expectedException \Exception
43 * @expectedExceptionMessageRegExp /An error occurred while parsing JSON configuration file \([\w\/\.]+\): error code #4/
44 */ 41 */
45 public function testReadInvalidJson() 42 public function testReadInvalidJson()
46 { 43 {
44 $this->expectException(\Exception::class);
45 $this->expectExceptionMessageRegExp('/An error occurred while parsing JSON configuration file \\([\\w\\/\\.]+\\): error code #4/');
46
47 $this->configIO->read('tests/utils/config/configInvalid.json.php'); 47 $this->configIO->read('tests/utils/config/configInvalid.json.php');
48 } 48 }
49 49
@@ -110,22 +110,11 @@ class ConfigJsonTest extends \PHPUnit\Framework\TestCase
110 110
111 /** 111 /**
112 * Write to invalid path. 112 * Write to invalid path.
113 *
114 * @expectedException \Shaarli\Exceptions\IOException
115 */
116 public function testWriteInvalidArray()
117 {
118 $conf = array('conf' => 'value');
119 @$this->configIO->write(array(), $conf);
120 }
121
122 /**
123 * Write to invalid path.
124 *
125 * @expectedException \Shaarli\Exceptions\IOException
126 */ 113 */
127 public function testWriteInvalidBlank() 114 public function testWriteInvalidBlank()
128 { 115 {
116 $this->expectException(\Shaarli\Exceptions\IOException::class);
117
129 $conf = array('conf' => 'value'); 118 $conf = array('conf' => 'value');
130 @$this->configIO->write('', $conf); 119 @$this->configIO->write('', $conf);
131 } 120 }
diff --git a/tests/config/ConfigManagerTest.php b/tests/config/ConfigManagerTest.php
index 33830bc9..65d8ba2c 100644
--- a/tests/config/ConfigManagerTest.php
+++ b/tests/config/ConfigManagerTest.php
@@ -7,14 +7,14 @@ namespace Shaarli\Config;
7 * Note: it only test the manager with ConfigJson, 7 * Note: it only test the manager with ConfigJson,
8 * ConfigPhp is only a workaround to handle the transition to JSON type. 8 * ConfigPhp is only a workaround to handle the transition to JSON type.
9 */ 9 */
10class ConfigManagerTest extends \PHPUnit\Framework\TestCase 10class ConfigManagerTest extends \Shaarli\TestCase
11{ 11{
12 /** 12 /**
13 * @var ConfigManager 13 * @var ConfigManager
14 */ 14 */
15 protected $conf; 15 protected $conf;
16 16
17 public function setUp() 17 protected function setUp(): void
18 { 18 {
19 $this->conf = new ConfigManager('tests/utils/config/configJson'); 19 $this->conf = new ConfigManager('tests/utils/config/configJson');
20 } 20 }
@@ -95,44 +95,44 @@ class ConfigManagerTest extends \PHPUnit\Framework\TestCase
95 95
96 /** 96 /**
97 * Set with an empty key. 97 * Set with an empty key.
98 *
99 * @expectedException \Exception
100 * @expectedExceptionMessageRegExp #^Invalid setting key parameter. String expected, got.*#
101 */ 98 */
102 public function testSetEmptyKey() 99 public function testSetEmptyKey()
103 { 100 {
101 $this->expectException(\Exception::class);
102 $this->expectExceptionMessageRegExp('#^Invalid setting key parameter. String expected, got.*#');
103
104 $this->conf->set('', 'stuff'); 104 $this->conf->set('', 'stuff');
105 } 105 }
106 106
107 /** 107 /**
108 * Set with an array key. 108 * Set with an array key.
109 *
110 * @expectedException \Exception
111 * @expectedExceptionMessageRegExp #^Invalid setting key parameter. String expected, got.*#
112 */ 109 */
113 public function testSetArrayKey() 110 public function testSetArrayKey()
114 { 111 {
112 $this->expectException(\Exception::class);
113 $this->expectExceptionMessageRegExp('#^Invalid setting key parameter. String expected, got.*#');
114
115 $this->conf->set(array('foo' => 'bar'), 'stuff'); 115 $this->conf->set(array('foo' => 'bar'), 'stuff');
116 } 116 }
117 117
118 /** 118 /**
119 * Remove with an empty key. 119 * Remove with an empty key.
120 *
121 * @expectedException \Exception
122 * @expectedExceptionMessageRegExp #^Invalid setting key parameter. String expected, got.*#
123 */ 120 */
124 public function testRmoveEmptyKey() 121 public function testRmoveEmptyKey()
125 { 122 {
123 $this->expectException(\Exception::class);
124 $this->expectExceptionMessageRegExp('#^Invalid setting key parameter. String expected, got.*#');
125
126 $this->conf->remove(''); 126 $this->conf->remove('');
127 } 127 }
128 128
129 /** 129 /**
130 * Try to write the config without mandatory parameter (e.g. 'login'). 130 * Try to write the config without mandatory parameter (e.g. 'login').
131 *
132 * @expectedException Shaarli\Config\Exception\MissingFieldConfigException
133 */ 131 */
134 public function testWriteMissingParameter() 132 public function testWriteMissingParameter()
135 { 133 {
134 $this->expectException(\Shaarli\Config\Exception\MissingFieldConfigException::class);
135
136 $this->conf->setConfigFile('tests/utils/config/configTmp'); 136 $this->conf->setConfigFile('tests/utils/config/configTmp');
137 $this->assertFalse(file_exists($this->conf->getConfigFileExt())); 137 $this->assertFalse(file_exists($this->conf->getConfigFileExt()));
138 $this->conf->reload(); 138 $this->conf->reload();
diff --git a/tests/config/ConfigPhpTest.php b/tests/config/ConfigPhpTest.php
index fb91b51b..7bf9fe64 100644
--- a/tests/config/ConfigPhpTest.php
+++ b/tests/config/ConfigPhpTest.php
@@ -8,14 +8,14 @@ namespace Shaarli\Config;
8 * which are kept between tests. 8 * which are kept between tests.
9 * @runTestsInSeparateProcesses 9 * @runTestsInSeparateProcesses
10 */ 10 */
11class ConfigPhpTest extends \PHPUnit\Framework\TestCase 11class ConfigPhpTest extends \Shaarli\TestCase
12{ 12{
13 /** 13 /**
14 * @var ConfigPhp 14 * @var ConfigPhp
15 */ 15 */
16 protected $configIO; 16 protected $configIO;
17 17
18 public function setUp() 18 protected function setUp(): void
19 { 19 {
20 $this->configIO = new ConfigPhp(); 20 $this->configIO = new ConfigPhp();
21 } 21 }
diff --git a/tests/config/ConfigPluginTest.php b/tests/config/ConfigPluginTest.php
index b2cc0045..fa72d8c4 100644
--- a/tests/config/ConfigPluginTest.php
+++ b/tests/config/ConfigPluginTest.php
@@ -9,7 +9,7 @@ require_once 'application/config/ConfigPlugin.php';
9/** 9/**
10 * Unitary tests for Shaarli config related functions 10 * Unitary tests for Shaarli config related functions
11 */ 11 */
12class ConfigPluginTest extends \PHPUnit\Framework\TestCase 12class ConfigPluginTest extends \Shaarli\TestCase
13{ 13{
14 /** 14 /**
15 * Test save_plugin_config with valid data. 15 * Test save_plugin_config with valid data.
@@ -46,11 +46,11 @@ class ConfigPluginTest extends \PHPUnit\Framework\TestCase
46 46
47 /** 47 /**
48 * Test save_plugin_config with invalid data. 48 * Test save_plugin_config with invalid data.
49 *
50 * @expectedException Shaarli\Config\Exception\PluginConfigOrderException
51 */ 49 */
52 public function testSavePluginConfigInvalid() 50 public function testSavePluginConfigInvalid()
53 { 51 {
52 $this->expectException(\Shaarli\Config\Exception\PluginConfigOrderException::class);
53
54 $data = array( 54 $data = array(
55 'plugin2' => 0, 55 'plugin2' => 0,
56 'plugin3' => 0, 56 'plugin3' => 0,
diff --git a/tests/container/ContainerBuilderTest.php b/tests/container/ContainerBuilderTest.php
index c08010ae..5d52daef 100644
--- a/tests/container/ContainerBuilderTest.php
+++ b/tests/container/ContainerBuilderTest.php
@@ -4,12 +4,12 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Container; 5namespace Shaarli\Container;
6 6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Bookmark\BookmarkServiceInterface; 7use Shaarli\Bookmark\BookmarkServiceInterface;
9use Shaarli\Config\ConfigManager; 8use Shaarli\Config\ConfigManager;
10use Shaarli\Feed\FeedBuilder; 9use Shaarli\Feed\FeedBuilder;
11use Shaarli\Formatter\FormatterFactory; 10use Shaarli\Formatter\FormatterFactory;
12use Shaarli\Front\Controller\Visitor\ErrorController; 11use Shaarli\Front\Controller\Visitor\ErrorController;
12use Shaarli\Front\Controller\Visitor\ErrorNotFoundController;
13use Shaarli\History; 13use Shaarli\History;
14use Shaarli\Http\HttpAccess; 14use Shaarli\Http\HttpAccess;
15use Shaarli\Netscape\NetscapeBookmarkUtils; 15use Shaarli\Netscape\NetscapeBookmarkUtils;
@@ -19,6 +19,7 @@ use Shaarli\Render\PageCacheManager;
19use Shaarli\Security\CookieManager; 19use Shaarli\Security\CookieManager;
20use Shaarli\Security\LoginManager; 20use Shaarli\Security\LoginManager;
21use Shaarli\Security\SessionManager; 21use Shaarli\Security\SessionManager;
22use Shaarli\TestCase;
22use Shaarli\Thumbnailer; 23use Shaarli\Thumbnailer;
23use Shaarli\Updater\Updater; 24use Shaarli\Updater\Updater;
24use Slim\Http\Environment; 25use Slim\Http\Environment;
@@ -75,6 +76,7 @@ class ContainerBuilderTest extends TestCase
75 static::assertInstanceOf(PageBuilder::class, $container->pageBuilder); 76 static::assertInstanceOf(PageBuilder::class, $container->pageBuilder);
76 static::assertInstanceOf(PageCacheManager::class, $container->pageCacheManager); 77 static::assertInstanceOf(PageCacheManager::class, $container->pageCacheManager);
77 static::assertInstanceOf(ErrorController::class, $container->phpErrorHandler); 78 static::assertInstanceOf(ErrorController::class, $container->phpErrorHandler);
79 static::assertInstanceOf(ErrorNotFoundController::class, $container->notFoundHandler);
78 static::assertInstanceOf(PluginManager::class, $container->pluginManager); 80 static::assertInstanceOf(PluginManager::class, $container->pluginManager);
79 static::assertInstanceOf(SessionManager::class, $container->sessionManager); 81 static::assertInstanceOf(SessionManager::class, $container->sessionManager);
80 static::assertInstanceOf(Thumbnailer::class, $container->thumbnailer); 82 static::assertInstanceOf(Thumbnailer::class, $container->thumbnailer);
diff --git a/tests/feed/CachedPageTest.php b/tests/feed/CachedPageTest.php
index 2e716432..904db9dc 100644
--- a/tests/feed/CachedPageTest.php
+++ b/tests/feed/CachedPageTest.php
@@ -7,7 +7,7 @@ namespace Shaarli\Feed;
7/** 7/**
8 * Unitary tests for cached pages 8 * Unitary tests for cached pages
9 */ 9 */
10class CachedPageTest extends \PHPUnit\Framework\TestCase 10class CachedPageTest extends \Shaarli\TestCase
11{ 11{
12 // test cache directory 12 // test cache directory
13 protected static $testCacheDir = 'sandbox/pagecache'; 13 protected static $testCacheDir = 'sandbox/pagecache';
@@ -17,7 +17,7 @@ class CachedPageTest extends \PHPUnit\Framework\TestCase
17 /** 17 /**
18 * Create the cache directory if needed 18 * Create the cache directory if needed
19 */ 19 */
20 public static function setUpBeforeClass() 20 public static function setUpBeforeClass(): void
21 { 21 {
22 if (!is_dir(self::$testCacheDir)) { 22 if (!is_dir(self::$testCacheDir)) {
23 mkdir(self::$testCacheDir); 23 mkdir(self::$testCacheDir);
@@ -28,7 +28,7 @@ class CachedPageTest extends \PHPUnit\Framework\TestCase
28 /** 28 /**
29 * Reset the page cache 29 * Reset the page cache
30 */ 30 */
31 public function setUp() 31 protected function setUp(): void
32 { 32 {
33 if (file_exists(self::$filename)) { 33 if (file_exists(self::$filename)) {
34 unlink(self::$filename); 34 unlink(self::$filename);
diff --git a/tests/feed/FeedBuilderTest.php b/tests/feed/FeedBuilderTest.php
index 5c2aaedb..c29e8ef3 100644
--- a/tests/feed/FeedBuilderTest.php
+++ b/tests/feed/FeedBuilderTest.php
@@ -10,13 +10,14 @@ use Shaarli\Bookmark\LinkDB;
10use Shaarli\Config\ConfigManager; 10use Shaarli\Config\ConfigManager;
11use Shaarli\Formatter\FormatterFactory; 11use Shaarli\Formatter\FormatterFactory;
12use Shaarli\History; 12use Shaarli\History;
13use Shaarli\TestCase;
13 14
14/** 15/**
15 * FeedBuilderTest class. 16 * FeedBuilderTest class.
16 * 17 *
17 * Unit tests for FeedBuilder. 18 * Unit tests for FeedBuilder.
18 */ 19 */
19class FeedBuilderTest extends \PHPUnit\Framework\TestCase 20class FeedBuilderTest extends TestCase
20{ 21{
21 /** 22 /**
22 * @var string locale Basque (Spain). 23 * @var string locale Basque (Spain).
@@ -44,7 +45,7 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
44 /** 45 /**
45 * Called before every test method. 46 * Called before every test method.
46 */ 47 */
47 public static function setUpBeforeClass() 48 public static function setUpBeforeClass(): void
48 { 49 {
49 $conf = new ConfigManager('tests/utils/config/configJson'); 50 $conf = new ConfigManager('tests/utils/config/configJson');
50 $conf->set('resource.datastore', self::$testDatastore); 51 $conf->set('resource.datastore', self::$testDatastore);
@@ -60,7 +61,7 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
60 'SERVER_NAME' => 'host.tld', 61 'SERVER_NAME' => 'host.tld',
61 'SERVER_PORT' => '80', 62 'SERVER_PORT' => '80',
62 'SCRIPT_NAME' => '/index.php', 63 'SCRIPT_NAME' => '/index.php',
63 'REQUEST_URI' => '/index.php?do=feed', 64 'REQUEST_URI' => '/feed/atom',
64 ); 65 );
65 } 66 }
66 67
@@ -81,13 +82,13 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
81 $this->assertEquals(self::$RSS_LANGUAGE, $data['language']); 82 $this->assertEquals(self::$RSS_LANGUAGE, $data['language']);
82 $this->assertRegExp('/Wed, 03 Aug 2016 09:30:33 \+\d{4}/', $data['last_update']); 83 $this->assertRegExp('/Wed, 03 Aug 2016 09:30:33 \+\d{4}/', $data['last_update']);
83 $this->assertEquals(true, $data['show_dates']); 84 $this->assertEquals(true, $data['show_dates']);
84 $this->assertEquals('http://host.tld/index.php?do=feed', $data['self_link']); 85 $this->assertEquals('http://host.tld/feed/atom', $data['self_link']);
85 $this->assertEquals('http://host.tld/', $data['index_url']); 86 $this->assertEquals('http://host.tld/', $data['index_url']);
86 $this->assertFalse($data['usepermalinks']); 87 $this->assertFalse($data['usepermalinks']);
87 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); 88 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links']));
88 89
89 // Test first not pinned link (note link) 90 // Test first not pinned link (note link)
90 $link = $data['links'][array_keys($data['links'])[2]]; 91 $link = $data['links'][array_keys($data['links'])[0]];
91 $this->assertEquals(41, $link['id']); 92 $this->assertEquals(41, $link['id']);
92 $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']); 93 $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']);
93 $this->assertEquals('http://host.tld/shaare/WDWyig', $link['guid']); 94 $this->assertEquals('http://host.tld/shaare/WDWyig', $link['guid']);
@@ -96,9 +97,9 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
96 $pub = DateTime::createFromFormat(DateTime::RSS, $link['pub_iso_date']); 97 $pub = DateTime::createFromFormat(DateTime::RSS, $link['pub_iso_date']);
97 $up = DateTime::createFromFormat(DateTime::ATOM, $link['up_iso_date']); 98 $up = DateTime::createFromFormat(DateTime::ATOM, $link['up_iso_date']);
98 $this->assertEquals($pub, $up); 99 $this->assertEquals($pub, $up);
99 $this->assertContains('Stallman has a beard', $link['description']); 100 $this->assertContainsPolyfill('Stallman has a beard', $link['description']);
100 $this->assertContains('Permalink', $link['description']); 101 $this->assertContainsPolyfill('Permalink', $link['description']);
101 $this->assertContains('http://host.tld/shaare/WDWyig', $link['description']); 102 $this->assertContainsPolyfill('http://host.tld/shaare/WDWyig', $link['description']);
102 $this->assertEquals(1, count($link['taglist'])); 103 $this->assertEquals(1, count($link['taglist']));
103 $this->assertEquals('sTuff', $link['taglist'][0]); 104 $this->assertEquals('sTuff', $link['taglist'][0]);
104 105
@@ -128,7 +129,7 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
128 $data = $feedBuilder->buildData(FeedBuilder::$FEED_ATOM, null); 129 $data = $feedBuilder->buildData(FeedBuilder::$FEED_ATOM, null);
129 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); 130 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links']));
130 $this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['last_update']); 131 $this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['last_update']);
131 $link = $data['links'][array_keys($data['links'])[2]]; 132 $link = $data['links'][array_keys($data['links'])[0]];
132 $this->assertRegExp('/2015-03-10T11:46:51\+\d{2}:\d{2}/', $link['pub_iso_date']); 133 $this->assertRegExp('/2015-03-10T11:46:51\+\d{2}:\d{2}/', $link['pub_iso_date']);
133 $this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['links'][8]['up_iso_date']); 134 $this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['links'][8]['up_iso_date']);
134 } 135 }
@@ -173,7 +174,7 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
173 $feedBuilder->setLocale(self::$LOCALE); 174 $feedBuilder->setLocale(self::$LOCALE);
174 $data = $feedBuilder->buildData(FeedBuilder::$FEED_ATOM, $criteria); 175 $data = $feedBuilder->buildData(FeedBuilder::$FEED_ATOM, $criteria);
175 $this->assertEquals(3, count($data['links'])); 176 $this->assertEquals(3, count($data['links']));
176 $link = $data['links'][array_keys($data['links'])[2]]; 177 $link = $data['links'][array_keys($data['links'])[0]];
177 $this->assertEquals(41, $link['id']); 178 $this->assertEquals(41, $link['id']);
178 $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']); 179 $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']);
179 } 180 }
@@ -195,21 +196,21 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
195 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); 196 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links']));
196 $this->assertTrue($data['usepermalinks']); 197 $this->assertTrue($data['usepermalinks']);
197 // First link is a permalink 198 // First link is a permalink
198 $link = $data['links'][array_keys($data['links'])[2]]; 199 $link = $data['links'][array_keys($data['links'])[0]];
199 $this->assertEquals(41, $link['id']); 200 $this->assertEquals(41, $link['id']);
200 $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']); 201 $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']);
201 $this->assertEquals('http://host.tld/shaare/WDWyig', $link['guid']); 202 $this->assertEquals('http://host.tld/shaare/WDWyig', $link['guid']);
202 $this->assertEquals('http://host.tld/shaare/WDWyig', $link['url']); 203 $this->assertEquals('http://host.tld/shaare/WDWyig', $link['url']);
203 $this->assertContains('Direct link', $link['description']); 204 $this->assertContainsPolyfill('Direct link', $link['description']);
204 $this->assertContains('http://host.tld/shaare/WDWyig', $link['description']); 205 $this->assertContainsPolyfill('http://host.tld/shaare/WDWyig', $link['description']);
205 // Second link is a direct link 206 // Second link is a direct link
206 $link = $data['links'][array_keys($data['links'])[3]]; 207 $link = $data['links'][array_keys($data['links'])[1]];
207 $this->assertEquals(8, $link['id']); 208 $this->assertEquals(8, $link['id']);
208 $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114633'), $link['created']); 209 $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114633'), $link['created']);
209 $this->assertEquals('http://host.tld/shaare/RttfEw', $link['guid']); 210 $this->assertEquals('http://host.tld/shaare/RttfEw', $link['guid']);
210 $this->assertEquals('https://static.fsf.org/nosvn/faif-2.0.pdf', $link['url']); 211 $this->assertEquals('https://static.fsf.org/nosvn/faif-2.0.pdf', $link['url']);
211 $this->assertContains('Direct link', $link['description']); 212 $this->assertContainsPolyfill('Direct link', $link['description']);
212 $this->assertContains('https://static.fsf.org/nosvn/faif-2.0.pdf', $link['description']); 213 $this->assertContainsPolyfill('https://static.fsf.org/nosvn/faif-2.0.pdf', $link['description']);
213 } 214 }
214 215
215 /** 216 /**
@@ -253,7 +254,7 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
253 'SERVER_NAME' => 'host.tld', 254 'SERVER_NAME' => 'host.tld',
254 'SERVER_PORT' => '8080', 255 'SERVER_PORT' => '8080',
255 'SCRIPT_NAME' => '/~user/shaarli/index.php', 256 'SCRIPT_NAME' => '/~user/shaarli/index.php',
256 'REQUEST_URI' => '/~user/shaarli/index.php?do=feed', 257 'REQUEST_URI' => '/~user/shaarli/feed/atom',
257 ); 258 );
258 $feedBuilder = new FeedBuilder( 259 $feedBuilder = new FeedBuilder(
259 self::$bookmarkService, 260 self::$bookmarkService,
@@ -265,14 +266,14 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
265 $data = $feedBuilder->buildData(FeedBuilder::$FEED_ATOM, null); 266 $data = $feedBuilder->buildData(FeedBuilder::$FEED_ATOM, null);
266 267
267 $this->assertEquals( 268 $this->assertEquals(
268 'http://host.tld:8080/~user/shaarli/index.php?do=feed', 269 'http://host.tld:8080/~user/shaarli/feed/atom',
269 $data['self_link'] 270 $data['self_link']
270 ); 271 );
271 272
272 // Test first link (note link) 273 // Test first link (note link)
273 $link = $data['links'][array_keys($data['links'])[2]]; 274 $link = $data['links'][array_keys($data['links'])[0]];
274 $this->assertEquals('http://host.tld:8080/~user/shaarli/shaare/WDWyig', $link['guid']); 275 $this->assertEquals('http://host.tld:8080/~user/shaarli/shaare/WDWyig', $link['guid']);
275 $this->assertEquals('http://host.tld:8080/~user/shaarli/shaare/WDWyig', $link['url']); 276 $this->assertEquals('http://host.tld:8080/~user/shaarli/shaare/WDWyig', $link['url']);
276 $this->assertContains('http://host.tld:8080/~user/shaarli/./add-tag/hashtag', $link['description']); 277 $this->assertContainsPolyfill('http://host.tld:8080/~user/shaarli/./add-tag/hashtag', $link['description']);
277 } 278 }
278} 279}
diff --git a/tests/formatter/BookmarkDefaultFormatterTest.php b/tests/formatter/BookmarkDefaultFormatterTest.php
index cf48b00b..9534436e 100644
--- a/tests/formatter/BookmarkDefaultFormatterTest.php
+++ b/tests/formatter/BookmarkDefaultFormatterTest.php
@@ -3,9 +3,9 @@
3namespace Shaarli\Formatter; 3namespace Shaarli\Formatter;
4 4
5use DateTime; 5use DateTime;
6use PHPUnit\Framework\TestCase;
7use Shaarli\Bookmark\Bookmark; 6use Shaarli\Bookmark\Bookmark;
8use Shaarli\Config\ConfigManager; 7use Shaarli\Config\ConfigManager;
8use Shaarli\TestCase;
9 9
10/** 10/**
11 * Class BookmarkDefaultFormatterTest 11 * Class BookmarkDefaultFormatterTest
@@ -25,7 +25,7 @@ class BookmarkDefaultFormatterTest extends TestCase
25 /** 25 /**
26 * Initialize formatter instance. 26 * Initialize formatter instance.
27 */ 27 */
28 public function setUp() 28 protected function setUp(): void
29 { 29 {
30 copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php'); 30 copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php');
31 $this->conf = new ConfigManager(self::$testConf); 31 $this->conf = new ConfigManager(self::$testConf);
diff --git a/tests/formatter/BookmarkMarkdownExtraFormatterTest.php b/tests/formatter/BookmarkMarkdownExtraFormatterTest.php
new file mode 100644
index 00000000..d4941ef3
--- /dev/null
+++ b/tests/formatter/BookmarkMarkdownExtraFormatterTest.php
@@ -0,0 +1,162 @@
1<?php
2
3namespace Shaarli\Formatter;
4
5use DateTime;
6use PHPUnit\Framework\TestCase;
7use Shaarli\Bookmark\Bookmark;
8use Shaarli\Config\ConfigManager;
9
10/**
11 * Class BookmarkMarkdownExtraFormatterTest
12 * @package Shaarli\Formatter
13 */
14class BookmarkMarkdownExtraFormatterTest extends TestCase
15{
16 /** @var string Path of test config file */
17 protected static $testConf = 'sandbox/config';
18
19 /** @var BookmarkFormatter */
20 protected $formatter;
21
22 /** @var ConfigManager instance */
23 protected $conf;
24
25 /**
26 * Initialize formatter instance.
27 */
28 public function setUp(): void
29 {
30 copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php');
31 $this->conf = new ConfigManager(self::$testConf);
32 $this->formatter = new BookmarkMarkdownExtraFormatter($this->conf, true);
33 }
34
35 /**
36 * Test formatting a bookmark with all its attribute filled.
37 */
38 public function testFormatExtra(): void
39 {
40 $bookmark = new Bookmark();
41 $bookmark->setId($id = 11);
42 $bookmark->setShortUrl($short = 'abcdef');
43 $bookmark->setUrl('https://sub.domain.tld?query=here&for=real#hash');
44 $bookmark->setTitle($title = 'This is a <strong>bookmark</strong>');
45 $bookmark->setDescription('<h2>Content</h2><p>`Here is some content</p>');
46 $bookmark->setTags($tags = ['tag1', 'bookmark', 'other', '<script>alert("xss");</script>']);
47 $bookmark->setThumbnail('http://domain2.tdl2/?type=img&name=file.png');
48 $bookmark->setSticky(true);
49 $bookmark->setCreated($created = DateTime::createFromFormat('Ymd_His', '20190521_190412'));
50 $bookmark->setUpdated($updated = DateTime::createFromFormat('Ymd_His', '20190521_191213'));
51 $bookmark->setPrivate(true);
52
53 $link = $this->formatter->format($bookmark);
54 $this->assertEquals($id, $link['id']);
55 $this->assertEquals($short, $link['shorturl']);
56 $this->assertEquals('https://sub.domain.tld?query=here&amp;for=real#hash', $link['url']);
57 $this->assertEquals(
58 'https://sub.domain.tld?query=here&amp;for=real#hash',
59 $link['real_url']
60 );
61 $this->assertEquals('This is a &lt;strong&gt;bookmark&lt;/strong&gt;', $link['title']);
62 $this->assertEquals(
63 '<div class="markdown"><p>'.
64 '&lt;h2&gt;Content&lt;/h2&gt;&lt;p&gt;`Here is some content&lt;/p&gt;'.
65 '</p></div>',
66 $link['description']
67 );
68 $tags[3] = '&lt;script&gt;alert(&quot;xss&quot;);&lt;/script&gt;';
69 $this->assertEquals($tags, $link['taglist']);
70 $this->assertEquals(implode(' ', $tags), $link['tags']);
71 $this->assertEquals(
72 'http://domain2.tdl2/?type=img&amp;name=file.png',
73 $link['thumbnail']
74 );
75 $this->assertEquals($created, $link['created']);
76 $this->assertEquals($created->getTimestamp(), $link['timestamp']);
77 $this->assertEquals($updated, $link['updated']);
78 $this->assertEquals($updated->getTimestamp(), $link['updated_timestamp']);
79 $this->assertTrue($link['private']);
80 $this->assertTrue($link['sticky']);
81 $this->assertEquals('private', $link['class']);
82 }
83
84 /**
85 * Test formatting a bookmark with all its attribute filled.
86 */
87 public function testFormatExtraMinimal(): void
88 {
89 $bookmark = new Bookmark();
90
91 $link = $this->formatter->format($bookmark);
92 $this->assertEmpty($link['id']);
93 $this->assertEmpty($link['shorturl']);
94 $this->assertEmpty($link['url']);
95 $this->assertEmpty($link['real_url']);
96 $this->assertEmpty($link['title']);
97 $this->assertEmpty($link['description']);
98 $this->assertEmpty($link['taglist']);
99 $this->assertEmpty($link['tags']);
100 $this->assertEmpty($link['thumbnail']);
101 $this->assertEmpty($link['created']);
102 $this->assertEmpty($link['timestamp']);
103 $this->assertEmpty($link['updated']);
104 $this->assertEmpty($link['updated_timestamp']);
105 $this->assertFalse($link['private']);
106 $this->assertFalse($link['sticky']);
107 $this->assertEmpty($link['class']);
108 }
109
110 /**
111 * Make sure that the description is properly formatted by the default formatter.
112 */
113 public function testFormatExtrraDescription(): void
114 {
115 $description = 'This a <strong>description</strong>'. PHP_EOL;
116 $description .= 'text https://sub.domain.tld?query=here&for=real#hash more text'. PHP_EOL;
117 $description .= 'Also, there is an #hashtag added'. PHP_EOL;
118 $description .= ' A N D KEEP SPACES ! '. PHP_EOL;
119 $description .= '# Header {.class}'. PHP_EOL;
120
121 $bookmark = new Bookmark();
122 $bookmark->setDescription($description);
123 $link = $this->formatter->format($bookmark);
124
125 $description = '<div class="markdown"><p>';
126 $description .= 'This a &lt;strong&gt;description&lt;/strong&gt;<br />'. PHP_EOL;
127 $url = 'https://sub.domain.tld?query=here&amp;for=real#hash';
128 $description .= 'text <a href="'. $url .'">'. $url .'</a> more text<br />'. PHP_EOL;
129 $description .= 'Also, there is an <a href="./add-tag/hashtag">#hashtag</a> added<br />'. PHP_EOL;
130 $description .= 'A N D KEEP SPACES ! </p>' . PHP_EOL;
131 $description .= '<h1 class="class">Header</h1>';
132 $description .= '</div>';
133
134 $this->assertEquals($description, $link['description']);
135 }
136
137 /**
138 * Test formatting URL with an index_url set
139 * It should prepend relative links.
140 */
141 public function testFormatExtraNoteWithIndexUrl(): void
142 {
143 $bookmark = new Bookmark();
144 $bookmark->setUrl($short = '?abcdef');
145 $description = 'Text #hashtag more text';
146 $bookmark->setDescription($description);
147
148 $this->formatter->addContextData('index_url', $root = 'https://domain.tld/hithere/');
149
150 $description = '<div class="markdown"><p>';
151 $description .= 'Text <a href="'. $root .'./add-tag/hashtag">#hashtag</a> more text';
152 $description .= '</p></div>';
153
154 $link = $this->formatter->format($bookmark);
155 $this->assertEquals($root . $short, $link['url']);
156 $this->assertEquals($root . $short, $link['real_url']);
157 $this->assertEquals(
158 $description,
159 $link['description']
160 );
161 }
162}
diff --git a/tests/formatter/BookmarkMarkdownFormatterTest.php b/tests/formatter/BookmarkMarkdownFormatterTest.php
index 3e72d1ee..ab6b4080 100644
--- a/tests/formatter/BookmarkMarkdownFormatterTest.php
+++ b/tests/formatter/BookmarkMarkdownFormatterTest.php
@@ -3,9 +3,9 @@
3namespace Shaarli\Formatter; 3namespace Shaarli\Formatter;
4 4
5use DateTime; 5use DateTime;
6use PHPUnit\Framework\TestCase;
7use Shaarli\Bookmark\Bookmark; 6use Shaarli\Bookmark\Bookmark;
8use Shaarli\Config\ConfigManager; 7use Shaarli\Config\ConfigManager;
8use Shaarli\TestCase;
9 9
10/** 10/**
11 * Class BookmarkMarkdownFormatterTest 11 * Class BookmarkMarkdownFormatterTest
@@ -25,7 +25,7 @@ class BookmarkMarkdownFormatterTest extends TestCase
25 /** 25 /**
26 * Initialize formatter instance. 26 * Initialize formatter instance.
27 */ 27 */
28 public function setUp() 28 protected function setUp(): void
29 { 29 {
30 copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php'); 30 copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php');
31 $this->conf = new ConfigManager(self::$testConf); 31 $this->conf = new ConfigManager(self::$testConf);
diff --git a/tests/formatter/BookmarkRawFormatterTest.php b/tests/formatter/BookmarkRawFormatterTest.php
index 4491b035..c76bb7b9 100644
--- a/tests/formatter/BookmarkRawFormatterTest.php
+++ b/tests/formatter/BookmarkRawFormatterTest.php
@@ -3,9 +3,9 @@
3namespace Shaarli\Formatter; 3namespace Shaarli\Formatter;
4 4
5use DateTime; 5use DateTime;
6use PHPUnit\Framework\TestCase;
7use Shaarli\Bookmark\Bookmark; 6use Shaarli\Bookmark\Bookmark;
8use Shaarli\Config\ConfigManager; 7use Shaarli\Config\ConfigManager;
8use Shaarli\TestCase;
9 9
10/** 10/**
11 * Class BookmarkRawFormatterTest 11 * Class BookmarkRawFormatterTest
@@ -25,7 +25,7 @@ class BookmarkRawFormatterTest extends TestCase
25 /** 25 /**
26 * Initialize formatter instance. 26 * Initialize formatter instance.
27 */ 27 */
28 public function setUp() 28 protected function setUp(): void
29 { 29 {
30 copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php'); 30 copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php');
31 $this->conf = new ConfigManager(self::$testConf); 31 $this->conf = new ConfigManager(self::$testConf);
diff --git a/tests/formatter/FormatterFactoryTest.php b/tests/formatter/FormatterFactoryTest.php
index 5adf3ffd..ae476cb5 100644
--- a/tests/formatter/FormatterFactoryTest.php
+++ b/tests/formatter/FormatterFactoryTest.php
@@ -2,8 +2,8 @@
2 2
3namespace Shaarli\Formatter; 3namespace Shaarli\Formatter;
4 4
5use PHPUnit\Framework\TestCase;
6use Shaarli\Config\ConfigManager; 5use Shaarli\Config\ConfigManager;
6use Shaarli\TestCase;
7 7
8/** 8/**
9 * Class FormatterFactoryTest 9 * Class FormatterFactoryTest
@@ -24,7 +24,7 @@ class FormatterFactoryTest extends TestCase
24 /** 24 /**
25 * Initialize FormatterFactory instance 25 * Initialize FormatterFactory instance
26 */ 26 */
27 public function setUp() 27 protected function setUp(): void
28 { 28 {
29 copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php'); 29 copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php');
30 $this->conf = new ConfigManager(self::$testConf); 30 $this->conf = new ConfigManager(self::$testConf);
diff --git a/tests/front/ShaarliAdminMiddlewareTest.php b/tests/front/ShaarliAdminMiddlewareTest.php
index 7451330b..44025f11 100644
--- a/tests/front/ShaarliAdminMiddlewareTest.php
+++ b/tests/front/ShaarliAdminMiddlewareTest.php
@@ -4,10 +4,10 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front; 5namespace Shaarli\Front;
6 6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Config\ConfigManager; 7use Shaarli\Config\ConfigManager;
9use Shaarli\Container\ShaarliContainer; 8use Shaarli\Container\ShaarliContainer;
10use Shaarli\Security\LoginManager; 9use Shaarli\Security\LoginManager;
10use Shaarli\TestCase;
11use Shaarli\Updater\Updater; 11use Shaarli\Updater\Updater;
12use Slim\Http\Request; 12use Slim\Http\Request;
13use Slim\Http\Response; 13use Slim\Http\Response;
diff --git a/tests/front/ShaarliMiddlewareTest.php b/tests/front/ShaarliMiddlewareTest.php
index 05aa34a9..655c5bba 100644
--- a/tests/front/ShaarliMiddlewareTest.php
+++ b/tests/front/ShaarliMiddlewareTest.php
@@ -4,7 +4,6 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front; 5namespace Shaarli\Front;
6 6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Config\ConfigManager; 7use Shaarli\Config\ConfigManager;
9use Shaarli\Container\ShaarliContainer; 8use Shaarli\Container\ShaarliContainer;
10use Shaarli\Front\Exception\LoginBannedException; 9use Shaarli\Front\Exception\LoginBannedException;
@@ -12,6 +11,7 @@ use Shaarli\Front\Exception\UnauthorizedException;
12use Shaarli\Render\PageBuilder; 11use Shaarli\Render\PageBuilder;
13use Shaarli\Render\PageCacheManager; 12use Shaarli\Render\PageCacheManager;
14use Shaarli\Security\LoginManager; 13use Shaarli\Security\LoginManager;
14use Shaarli\TestCase;
15use Shaarli\Updater\Updater; 15use Shaarli\Updater\Updater;
16use Slim\Http\Request; 16use Slim\Http\Request;
17use Slim\Http\Response; 17use Slim\Http\Response;
diff --git a/tests/front/controller/admin/ConfigureControllerTest.php b/tests/front/controller/admin/ConfigureControllerTest.php
index f2f84bac..d82db0a7 100644
--- a/tests/front/controller/admin/ConfigureControllerTest.php
+++ b/tests/front/controller/admin/ConfigureControllerTest.php
@@ -4,10 +4,10 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Admin; 5namespace Shaarli\Front\Controller\Admin;
6 6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Config\ConfigManager; 7use Shaarli\Config\ConfigManager;
9use Shaarli\Front\Exception\WrongTokenException; 8use Shaarli\Front\Exception\WrongTokenException;
10use Shaarli\Security\SessionManager; 9use Shaarli\Security\SessionManager;
10use Shaarli\TestCase;
11use Shaarli\Thumbnailer; 11use Shaarli\Thumbnailer;
12use Slim\Http\Request; 12use Slim\Http\Request;
13use Slim\Http\Response; 13use Slim\Http\Response;
@@ -51,7 +51,7 @@ class ConfigureControllerTest extends TestCase
51 static::assertSame('general.title', $assignedVariables['title']); 51 static::assertSame('general.title', $assignedVariables['title']);
52 static::assertSame('resource.theme', $assignedVariables['theme']); 52 static::assertSame('resource.theme', $assignedVariables['theme']);
53 static::assertEmpty($assignedVariables['theme_available']); 53 static::assertEmpty($assignedVariables['theme_available']);
54 static::assertSame(['default', 'markdown'], $assignedVariables['formatter_available']); 54 static::assertSame(['default', 'markdown', 'markdownExtra'], $assignedVariables['formatter_available']);
55 static::assertNotEmpty($assignedVariables['continents']); 55 static::assertNotEmpty($assignedVariables['continents']);
56 static::assertNotEmpty($assignedVariables['cities']); 56 static::assertNotEmpty($assignedVariables['cities']);
57 static::assertSame('general.retrieve_description', $assignedVariables['retrieve_description']); 57 static::assertSame('general.retrieve_description', $assignedVariables['retrieve_description']);
@@ -62,7 +62,7 @@ class ConfigureControllerTest extends TestCase
62 static::assertSame('privacy.hide_public_links', $assignedVariables['hide_public_links']); 62 static::assertSame('privacy.hide_public_links', $assignedVariables['hide_public_links']);
63 static::assertSame('api.enabled', $assignedVariables['api_enabled']); 63 static::assertSame('api.enabled', $assignedVariables['api_enabled']);
64 static::assertSame('api.secret', $assignedVariables['api_secret']); 64 static::assertSame('api.secret', $assignedVariables['api_secret']);
65 static::assertCount(4, $assignedVariables['languages']); 65 static::assertCount(5, $assignedVariables['languages']);
66 static::assertArrayHasKey('gd_enabled', $assignedVariables); 66 static::assertArrayHasKey('gd_enabled', $assignedVariables);
67 static::assertSame('thumbnails.mode', $assignedVariables['thumbnails_mode']); 67 static::assertSame('thumbnails.mode', $assignedVariables['thumbnails_mode']);
68 } 68 }
diff --git a/tests/front/controller/admin/ExportControllerTest.php b/tests/front/controller/admin/ExportControllerTest.php
index 50d9e378..0e6f2762 100644
--- a/tests/front/controller/admin/ExportControllerTest.php
+++ b/tests/front/controller/admin/ExportControllerTest.php
@@ -4,12 +4,12 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Admin; 5namespace Shaarli\Front\Controller\Admin;
6 6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Bookmark\Bookmark; 7use Shaarli\Bookmark\Bookmark;
9use Shaarli\Formatter\BookmarkFormatter; 8use Shaarli\Formatter\BookmarkFormatter;
10use Shaarli\Formatter\BookmarkRawFormatter; 9use Shaarli\Formatter\BookmarkRawFormatter;
11use Shaarli\Netscape\NetscapeBookmarkUtils; 10use Shaarli\Netscape\NetscapeBookmarkUtils;
12use Shaarli\Security\SessionManager; 11use Shaarli\Security\SessionManager;
12use Shaarli\TestCase;
13use Slim\Http\Request; 13use Slim\Http\Request;
14use Slim\Http\Response; 14use Slim\Http\Response;
15 15
@@ -84,7 +84,7 @@ class ExportControllerTest extends TestCase
84 static::assertInstanceOf(BookmarkRawFormatter::class, $formatter); 84 static::assertInstanceOf(BookmarkRawFormatter::class, $formatter);
85 static::assertSame($parameters['selection'], $selection); 85 static::assertSame($parameters['selection'], $selection);
86 static::assertTrue($prependNoteUrl); 86 static::assertTrue($prependNoteUrl);
87 static::assertSame('http://shaarli', $indexUrl); 87 static::assertSame('http://shaarli/subfolder/', $indexUrl);
88 88
89 return $bookmarks; 89 return $bookmarks;
90 } 90 }
diff --git a/tests/front/controller/admin/ImportControllerTest.php b/tests/front/controller/admin/ImportControllerTest.php
index eb31fad0..c266caa5 100644
--- a/tests/front/controller/admin/ImportControllerTest.php
+++ b/tests/front/controller/admin/ImportControllerTest.php
@@ -4,10 +4,10 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Admin; 5namespace Shaarli\Front\Controller\Admin;
6 6
7use PHPUnit\Framework\TestCase;
8use Psr\Http\Message\UploadedFileInterface; 7use Psr\Http\Message\UploadedFileInterface;
9use Shaarli\Netscape\NetscapeBookmarkUtils; 8use Shaarli\Netscape\NetscapeBookmarkUtils;
10use Shaarli\Security\SessionManager; 9use Shaarli\Security\SessionManager;
10use Shaarli\TestCase;
11use Slim\Http\Request; 11use Slim\Http\Request;
12use Slim\Http\Response; 12use Slim\Http\Response;
13use Slim\Http\UploadedFile; 13use Slim\Http\UploadedFile;
diff --git a/tests/front/controller/admin/LogoutControllerTest.php b/tests/front/controller/admin/LogoutControllerTest.php
index 45e84dc0..94e53019 100644
--- a/tests/front/controller/admin/LogoutControllerTest.php
+++ b/tests/front/controller/admin/LogoutControllerTest.php
@@ -4,10 +4,9 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Admin; 5namespace Shaarli\Front\Controller\Admin;
6 6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Security\CookieManager; 7use Shaarli\Security\CookieManager;
9use Shaarli\Security\LoginManager;
10use Shaarli\Security\SessionManager; 8use Shaarli\Security\SessionManager;
9use Shaarli\TestCase;
11use Slim\Http\Request; 10use Slim\Http\Request;
12use Slim\Http\Response; 11use Slim\Http\Response;
13 12
diff --git a/tests/front/controller/admin/ManageShaareControllerTest/AddShaareTest.php b/tests/front/controller/admin/ManageShaareControllerTest/AddShaareTest.php
index 7d5b752a..0f27ec2f 100644
--- a/tests/front/controller/admin/ManageShaareControllerTest/AddShaareTest.php
+++ b/tests/front/controller/admin/ManageShaareControllerTest/AddShaareTest.php
@@ -4,10 +4,10 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Admin\ManageShaareControllerTest; 5namespace Shaarli\Front\Controller\Admin\ManageShaareControllerTest;
6 6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Front\Controller\Admin\FrontAdminControllerMockHelper; 7use Shaarli\Front\Controller\Admin\FrontAdminControllerMockHelper;
9use Shaarli\Front\Controller\Admin\ManageShaareController; 8use Shaarli\Front\Controller\Admin\ManageShaareController;
10use Shaarli\Http\HttpAccess; 9use Shaarli\Http\HttpAccess;
10use Shaarli\TestCase;
11use Slim\Http\Request; 11use Slim\Http\Request;
12use Slim\Http\Response; 12use Slim\Http\Response;
13 13
diff --git a/tests/front/controller/admin/ManageShaareControllerTest/ChangeVisibilityBookmarkTest.php b/tests/front/controller/admin/ManageShaareControllerTest/ChangeVisibilityBookmarkTest.php
index 5a615791..096d0774 100644
--- a/tests/front/controller/admin/ManageShaareControllerTest/ChangeVisibilityBookmarkTest.php
+++ b/tests/front/controller/admin/ManageShaareControllerTest/ChangeVisibilityBookmarkTest.php
@@ -4,7 +4,6 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Admin\ManageShaareControllerTest; 5namespace Shaarli\Front\Controller\Admin\ManageShaareControllerTest;
6 6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Bookmark\Bookmark; 7use Shaarli\Bookmark\Bookmark;
9use Shaarli\Bookmark\Exception\BookmarkNotFoundException; 8use Shaarli\Bookmark\Exception\BookmarkNotFoundException;
10use Shaarli\Formatter\BookmarkFormatter; 9use Shaarli\Formatter\BookmarkFormatter;
@@ -14,6 +13,7 @@ use Shaarli\Front\Controller\Admin\FrontAdminControllerMockHelper;
14use Shaarli\Front\Controller\Admin\ManageShaareController; 13use Shaarli\Front\Controller\Admin\ManageShaareController;
15use Shaarli\Http\HttpAccess; 14use Shaarli\Http\HttpAccess;
16use Shaarli\Security\SessionManager; 15use Shaarli\Security\SessionManager;
16use Shaarli\TestCase;
17use Slim\Http\Request; 17use Slim\Http\Request;
18use Slim\Http\Response; 18use Slim\Http\Response;
19 19
diff --git a/tests/front/controller/admin/ManageShaareControllerTest/DeleteBookmarkTest.php b/tests/front/controller/admin/ManageShaareControllerTest/DeleteBookmarkTest.php
index dee622bb..ba774e21 100644
--- a/tests/front/controller/admin/ManageShaareControllerTest/DeleteBookmarkTest.php
+++ b/tests/front/controller/admin/ManageShaareControllerTest/DeleteBookmarkTest.php
@@ -4,7 +4,6 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Admin\ManageShaareControllerTest; 5namespace Shaarli\Front\Controller\Admin\ManageShaareControllerTest;
6 6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Bookmark\Bookmark; 7use Shaarli\Bookmark\Bookmark;
9use Shaarli\Bookmark\Exception\BookmarkNotFoundException; 8use Shaarli\Bookmark\Exception\BookmarkNotFoundException;
10use Shaarli\Formatter\BookmarkFormatter; 9use Shaarli\Formatter\BookmarkFormatter;
@@ -13,6 +12,7 @@ use Shaarli\Front\Controller\Admin\FrontAdminControllerMockHelper;
13use Shaarli\Front\Controller\Admin\ManageShaareController; 12use Shaarli\Front\Controller\Admin\ManageShaareController;
14use Shaarli\Http\HttpAccess; 13use Shaarli\Http\HttpAccess;
15use Shaarli\Security\SessionManager; 14use Shaarli\Security\SessionManager;
15use Shaarli\TestCase;
16use Slim\Http\Request; 16use Slim\Http\Request;
17use Slim\Http\Response; 17use Slim\Http\Response;
18 18
diff --git a/tests/front/controller/admin/ManageShaareControllerTest/DisplayCreateFormTest.php b/tests/front/controller/admin/ManageShaareControllerTest/DisplayCreateFormTest.php
index 777583d5..2eb95251 100644
--- a/tests/front/controller/admin/ManageShaareControllerTest/DisplayCreateFormTest.php
+++ b/tests/front/controller/admin/ManageShaareControllerTest/DisplayCreateFormTest.php
@@ -4,12 +4,12 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Admin\ManageShaareControllerTest; 5namespace Shaarli\Front\Controller\Admin\ManageShaareControllerTest;
6 6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Bookmark\Bookmark; 7use Shaarli\Bookmark\Bookmark;
9use Shaarli\Config\ConfigManager; 8use Shaarli\Config\ConfigManager;
10use Shaarli\Front\Controller\Admin\FrontAdminControllerMockHelper; 9use Shaarli\Front\Controller\Admin\FrontAdminControllerMockHelper;
11use Shaarli\Front\Controller\Admin\ManageShaareController; 10use Shaarli\Front\Controller\Admin\ManageShaareController;
12use Shaarli\Http\HttpAccess; 11use Shaarli\Http\HttpAccess;
12use Shaarli\TestCase;
13use Slim\Http\Request; 13use Slim\Http\Request;
14use Slim\Http\Response; 14use Slim\Http\Response;
15 15
@@ -96,12 +96,14 @@ class DisplayCreateFormTest extends TestCase
96 96
97 // Make sure that PluginManager hook is triggered 97 // Make sure that PluginManager hook is triggered
98 $this->container->pluginManager 98 $this->container->pluginManager
99 ->expects(static::at(0)) 99 ->expects(static::atLeastOnce())
100 ->method('executeHooks') 100 ->method('executeHooks')
101 ->withConsecutive(['render_editlink'], ['render_includes'])
101 ->willReturnCallback(function (string $hook, array $data) use ($remoteTitle, $remoteDesc): array { 102 ->willReturnCallback(function (string $hook, array $data) use ($remoteTitle, $remoteDesc): array {
102 static::assertSame('render_editlink', $hook); 103 if ('render_editlink' === $hook) {
103 static::assertSame($remoteTitle, $data['link']['title']); 104 static::assertSame($remoteTitle, $data['link']['title']);
104 static::assertSame($remoteDesc, $data['link']['description']); 105 static::assertSame($remoteDesc, $data['link']['description']);
106 }
105 107
106 return $data; 108 return $data;
107 }) 109 })
diff --git a/tests/front/controller/admin/ManageShaareControllerTest/DisplayEditFormTest.php b/tests/front/controller/admin/ManageShaareControllerTest/DisplayEditFormTest.php
index 1a1cdcf3..2dc3f41c 100644
--- a/tests/front/controller/admin/ManageShaareControllerTest/DisplayEditFormTest.php
+++ b/tests/front/controller/admin/ManageShaareControllerTest/DisplayEditFormTest.php
@@ -4,13 +4,13 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Admin\ManageShaareControllerTest; 5namespace Shaarli\Front\Controller\Admin\ManageShaareControllerTest;
6 6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Bookmark\Bookmark; 7use Shaarli\Bookmark\Bookmark;
9use Shaarli\Bookmark\Exception\BookmarkNotFoundException; 8use Shaarli\Bookmark\Exception\BookmarkNotFoundException;
10use Shaarli\Front\Controller\Admin\FrontAdminControllerMockHelper; 9use Shaarli\Front\Controller\Admin\FrontAdminControllerMockHelper;
11use Shaarli\Front\Controller\Admin\ManageShaareController; 10use Shaarli\Front\Controller\Admin\ManageShaareController;
12use Shaarli\Http\HttpAccess; 11use Shaarli\Http\HttpAccess;
13use Shaarli\Security\SessionManager; 12use Shaarli\Security\SessionManager;
13use Shaarli\TestCase;
14use Slim\Http\Request; 14use Slim\Http\Request;
15use Slim\Http\Response; 15use Slim\Http\Response;
16 16
diff --git a/tests/front/controller/admin/ManageShaareControllerTest/PinBookmarkTest.php b/tests/front/controller/admin/ManageShaareControllerTest/PinBookmarkTest.php
index 1607b475..50ce7df1 100644
--- a/tests/front/controller/admin/ManageShaareControllerTest/PinBookmarkTest.php
+++ b/tests/front/controller/admin/ManageShaareControllerTest/PinBookmarkTest.php
@@ -4,13 +4,13 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Admin\ManageShaareControllerTest; 5namespace Shaarli\Front\Controller\Admin\ManageShaareControllerTest;
6 6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Bookmark\Bookmark; 7use Shaarli\Bookmark\Bookmark;
9use Shaarli\Bookmark\Exception\BookmarkNotFoundException; 8use Shaarli\Bookmark\Exception\BookmarkNotFoundException;
10use Shaarli\Front\Controller\Admin\FrontAdminControllerMockHelper; 9use Shaarli\Front\Controller\Admin\FrontAdminControllerMockHelper;
11use Shaarli\Front\Controller\Admin\ManageShaareController; 10use Shaarli\Front\Controller\Admin\ManageShaareController;
12use Shaarli\Http\HttpAccess; 11use Shaarli\Http\HttpAccess;
13use Shaarli\Security\SessionManager; 12use Shaarli\Security\SessionManager;
13use Shaarli\TestCase;
14use Slim\Http\Request; 14use Slim\Http\Request;
15use Slim\Http\Response; 15use Slim\Http\Response;
16 16
diff --git a/tests/front/controller/admin/ManageShaareControllerTest/SaveBookmarkTest.php b/tests/front/controller/admin/ManageShaareControllerTest/SaveBookmarkTest.php
index dabcd60d..f7a68226 100644
--- a/tests/front/controller/admin/ManageShaareControllerTest/SaveBookmarkTest.php
+++ b/tests/front/controller/admin/ManageShaareControllerTest/SaveBookmarkTest.php
@@ -4,7 +4,6 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Admin\ManageShaareControllerTest; 5namespace Shaarli\Front\Controller\Admin\ManageShaareControllerTest;
6 6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Bookmark\Bookmark; 7use Shaarli\Bookmark\Bookmark;
9use Shaarli\Config\ConfigManager; 8use Shaarli\Config\ConfigManager;
10use Shaarli\Front\Controller\Admin\FrontAdminControllerMockHelper; 9use Shaarli\Front\Controller\Admin\FrontAdminControllerMockHelper;
@@ -12,6 +11,7 @@ use Shaarli\Front\Controller\Admin\ManageShaareController;
12use Shaarli\Front\Exception\WrongTokenException; 11use Shaarli\Front\Exception\WrongTokenException;
13use Shaarli\Http\HttpAccess; 12use Shaarli\Http\HttpAccess;
14use Shaarli\Security\SessionManager; 13use Shaarli\Security\SessionManager;
14use Shaarli\TestCase;
15use Shaarli\Thumbnailer; 15use Shaarli\Thumbnailer;
16use Slim\Http\Request; 16use Slim\Http\Request;
17use Slim\Http\Response; 17use Slim\Http\Response;
@@ -43,7 +43,7 @@ class SaveBookmarkTest extends TestCase
43 'lf_description' => 'Provided description.', 43 'lf_description' => 'Provided description.',
44 'lf_tags' => 'abc def', 44 'lf_tags' => 'abc def',
45 'lf_private' => '1', 45 'lf_private' => '1',
46 'returnurl' => 'http://shaarli.tld/subfolder/admin/add-shaare' 46 'returnurl' => 'http://shaarli/subfolder/admin/add-shaare'
47 ]; 47 ];
48 48
49 $request = $this->createMock(Request::class); 49 $request = $this->createMock(Request::class);
@@ -88,17 +88,18 @@ class SaveBookmarkTest extends TestCase
88 88
89 // Make sure that PluginManager hook is triggered 89 // Make sure that PluginManager hook is triggered
90 $this->container->pluginManager 90 $this->container->pluginManager
91 ->expects(static::at(0)) 91 ->expects(static::atLeastOnce())
92 ->method('executeHooks') 92 ->method('executeHooks')
93 ->withConsecutive(['save_link'])
93 ->willReturnCallback(function (string $hook, array $data) use ($parameters, $id): array { 94 ->willReturnCallback(function (string $hook, array $data) use ($parameters, $id): array {
94 static::assertSame('save_link', $hook); 95 if ('save_link' === $hook) {
95 96 static::assertSame($id, $data['id']);
96 static::assertSame($id, $data['id']); 97 static::assertSame($parameters['lf_url'], $data['url']);
97 static::assertSame($parameters['lf_url'], $data['url']); 98 static::assertSame($parameters['lf_title'], $data['title']);
98 static::assertSame($parameters['lf_title'], $data['title']); 99 static::assertSame($parameters['lf_description'], $data['description']);
99 static::assertSame($parameters['lf_description'], $data['description']); 100 static::assertSame($parameters['lf_tags'], $data['tags']);
100 static::assertSame($parameters['lf_tags'], $data['tags']); 101 static::assertTrue($data['private']);
101 static::assertTrue($data['private']); 102 }
102 103
103 return $data; 104 return $data;
104 }) 105 })
@@ -124,7 +125,7 @@ class SaveBookmarkTest extends TestCase
124 'lf_description' => 'Provided description.', 125 'lf_description' => 'Provided description.',
125 'lf_tags' => 'abc def', 126 'lf_tags' => 'abc def',
126 'lf_private' => '1', 127 'lf_private' => '1',
127 'returnurl' => 'http://shaarli.tld/subfolder/?page=2' 128 'returnurl' => 'http://shaarli/subfolder/?page=2'
128 ]; 129 ];
129 130
130 $request = $this->createMock(Request::class); 131 $request = $this->createMock(Request::class);
@@ -174,17 +175,18 @@ class SaveBookmarkTest extends TestCase
174 175
175 // Make sure that PluginManager hook is triggered 176 // Make sure that PluginManager hook is triggered
176 $this->container->pluginManager 177 $this->container->pluginManager
177 ->expects(static::at(0)) 178 ->expects(static::atLeastOnce())
178 ->method('executeHooks') 179 ->method('executeHooks')
180 ->withConsecutive(['save_link'])
179 ->willReturnCallback(function (string $hook, array $data) use ($parameters, $id): array { 181 ->willReturnCallback(function (string $hook, array $data) use ($parameters, $id): array {
180 static::assertSame('save_link', $hook); 182 if ('save_link' === $hook) {
181 183 static::assertSame($id, $data['id']);
182 static::assertSame($id, $data['id']); 184 static::assertSame($parameters['lf_url'], $data['url']);
183 static::assertSame($parameters['lf_url'], $data['url']); 185 static::assertSame($parameters['lf_title'], $data['title']);
184 static::assertSame($parameters['lf_title'], $data['title']); 186 static::assertSame($parameters['lf_description'], $data['description']);
185 static::assertSame($parameters['lf_description'], $data['description']); 187 static::assertSame($parameters['lf_tags'], $data['tags']);
186 static::assertSame($parameters['lf_tags'], $data['tags']); 188 static::assertTrue($data['private']);
187 static::assertTrue($data['private']); 189 }
188 190
189 return $data; 191 return $data;
190 }) 192 })
@@ -239,6 +241,30 @@ class SaveBookmarkTest extends TestCase
239 } 241 }
240 242
241 /** 243 /**
244 * Test save a bookmark - with ID #0
245 */
246 public function testSaveBookmarkWithIdZero(): void
247 {
248 $parameters = ['lf_id' => '0'];
249
250 $request = $this->createMock(Request::class);
251 $request
252 ->method('getParam')
253 ->willReturnCallback(function (string $key) use ($parameters): ?string {
254 return $parameters[$key] ?? null;
255 })
256 ;
257 $response = new Response();
258
259 $this->container->bookmarkService->expects(static::once())->method('exists')->with(0)->willReturn(true);
260 $this->container->bookmarkService->expects(static::once())->method('get')->with(0)->willReturn(new Bookmark());
261
262 $result = $this->controller->save($request, $response);
263
264 static::assertSame(302, $result->getStatusCode());
265 }
266
267 /**
242 * Change the password with a wrong existing password 268 * Change the password with a wrong existing password
243 */ 269 */
244 public function testSaveBookmarkFromBookmarklet(): void 270 public function testSaveBookmarkFromBookmarklet(): void
diff --git a/tests/front/controller/admin/ManageTagControllerTest.php b/tests/front/controller/admin/ManageTagControllerTest.php
index 09ba0b4b..8a0ff7a9 100644
--- a/tests/front/controller/admin/ManageTagControllerTest.php
+++ b/tests/front/controller/admin/ManageTagControllerTest.php
@@ -4,11 +4,11 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Admin; 5namespace Shaarli\Front\Controller\Admin;
6 6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Bookmark\Bookmark; 7use Shaarli\Bookmark\Bookmark;
9use Shaarli\Bookmark\BookmarkFilter; 8use Shaarli\Bookmark\BookmarkFilter;
10use Shaarli\Front\Exception\WrongTokenException; 9use Shaarli\Front\Exception\WrongTokenException;
11use Shaarli\Security\SessionManager; 10use Shaarli\Security\SessionManager;
11use Shaarli\TestCase;
12use Slim\Http\Request; 12use Slim\Http\Request;
13use Slim\Http\Response; 13use Slim\Http\Response;
14 14
diff --git a/tests/front/controller/admin/PasswordControllerTest.php b/tests/front/controller/admin/PasswordControllerTest.php
index 9a01089e..58f47b49 100644
--- a/tests/front/controller/admin/PasswordControllerTest.php
+++ b/tests/front/controller/admin/PasswordControllerTest.php
@@ -4,11 +4,11 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Admin; 5namespace Shaarli\Front\Controller\Admin;
6 6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Config\ConfigManager; 7use Shaarli\Config\ConfigManager;
9use Shaarli\Front\Exception\OpenShaarliPasswordException; 8use Shaarli\Front\Exception\OpenShaarliPasswordException;
10use Shaarli\Front\Exception\WrongTokenException; 9use Shaarli\Front\Exception\WrongTokenException;
11use Shaarli\Security\SessionManager; 10use Shaarli\Security\SessionManager;
11use Shaarli\TestCase;
12use Slim\Http\Request; 12use Slim\Http\Request;
13use Slim\Http\Response; 13use Slim\Http\Response;
14 14
diff --git a/tests/front/controller/admin/PluginsControllerTest.php b/tests/front/controller/admin/PluginsControllerTest.php
index 5b59285c..974d614d 100644
--- a/tests/front/controller/admin/PluginsControllerTest.php
+++ b/tests/front/controller/admin/PluginsControllerTest.php
@@ -4,11 +4,11 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Admin; 5namespace Shaarli\Front\Controller\Admin;
6 6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Config\ConfigManager; 7use Shaarli\Config\ConfigManager;
9use Shaarli\Front\Exception\WrongTokenException; 8use Shaarli\Front\Exception\WrongTokenException;
10use Shaarli\Plugin\PluginManager; 9use Shaarli\Plugin\PluginManager;
11use Shaarli\Security\SessionManager; 10use Shaarli\Security\SessionManager;
11use Shaarli\TestCase;
12use Slim\Http\Request; 12use Slim\Http\Request;
13use Slim\Http\Response; 13use Slim\Http\Response;
14 14
@@ -32,7 +32,7 @@ class PluginsControllerTest extends TestCase
32 array_map(function (string $plugin) use ($path) { touch($path . '/' . $plugin); }, static::PLUGIN_NAMES); 32 array_map(function (string $plugin) use ($path) { touch($path . '/' . $plugin); }, static::PLUGIN_NAMES);
33 } 33 }
34 34
35 public function tearDown() 35 public function tearDown(): void
36 { 36 {
37 $path = __DIR__ . '/folder'; 37 $path = __DIR__ . '/folder';
38 array_map(function (string $plugin) use ($path) { unlink($path . '/' . $plugin); }, static::PLUGIN_NAMES); 38 array_map(function (string $plugin) use ($path) { unlink($path . '/' . $plugin); }, static::PLUGIN_NAMES);
@@ -125,6 +125,7 @@ class PluginsControllerTest extends TestCase
125 'parameters_form' => true, 125 'parameters_form' => true,
126 'parameter1' => 'blip', 126 'parameter1' => 'blip',
127 'parameter2' => 'blop', 127 'parameter2' => 'blop',
128 'token' => 'this parameter should not be saved'
128 ]; 129 ];
129 130
130 $request = $this->createMock(Request::class); 131 $request = $this->createMock(Request::class);
@@ -143,7 +144,7 @@ class PluginsControllerTest extends TestCase
143 ->with('save_plugin_parameters', $parameters) 144 ->with('save_plugin_parameters', $parameters)
144 ; 145 ;
145 $this->container->conf 146 $this->container->conf
146 ->expects(static::atLeastOnce()) 147 ->expects(static::exactly(2))
147 ->method('set') 148 ->method('set')
148 ->withConsecutive(['plugins.parameter1', 'blip'], ['plugins.parameter2', 'blop']) 149 ->withConsecutive(['plugins.parameter1', 'blip'], ['plugins.parameter2', 'blop'])
149 ; 150 ;
diff --git a/tests/front/controller/admin/SessionFilterControllerTest.php b/tests/front/controller/admin/SessionFilterControllerTest.php
index d306c6e9..712a625b 100644
--- a/tests/front/controller/admin/SessionFilterControllerTest.php
+++ b/tests/front/controller/admin/SessionFilterControllerTest.php
@@ -4,9 +4,9 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Admin; 5namespace Shaarli\Front\Controller\Admin;
6 6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Security\LoginManager; 7use Shaarli\Security\LoginManager;
9use Shaarli\Security\SessionManager; 8use Shaarli\Security\SessionManager;
9use Shaarli\TestCase;
10use Slim\Http\Request; 10use Slim\Http\Request;
11use Slim\Http\Response; 11use Slim\Http\Response;
12 12
@@ -31,7 +31,7 @@ class SessionFilterControllerTest extends TestCase
31 { 31 {
32 $arg = ['visibility' => 'private']; 32 $arg = ['visibility' => 'private'];
33 33
34 $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/subfolder/controller/?searchtag=abc']; 34 $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller/?searchtag=abc';
35 35
36 $this->container->loginManager->method('isLoggedIn')->willReturn(true); 36 $this->container->loginManager->method('isLoggedIn')->willReturn(true);
37 $this->container->sessionManager 37 $this->container->sessionManager
@@ -57,7 +57,7 @@ class SessionFilterControllerTest extends TestCase
57 { 57 {
58 $arg = ['visibility' => 'private']; 58 $arg = ['visibility' => 'private'];
59 59
60 $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/subfolder/controller/?searchtag=abc']; 60 $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller/?searchtag=abc';
61 61
62 $this->container->loginManager->method('isLoggedIn')->willReturn(true); 62 $this->container->loginManager->method('isLoggedIn')->willReturn(true);
63 $this->container->sessionManager 63 $this->container->sessionManager
@@ -121,7 +121,7 @@ class SessionFilterControllerTest extends TestCase
121 { 121 {
122 $arg = ['visibility' => 'test']; 122 $arg = ['visibility' => 'test'];
123 123
124 $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/subfolder/controller/?searchtag=abc']; 124 $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller/?searchtag=abc';
125 125
126 $this->container->loginManager->method('isLoggedIn')->willReturn(true); 126 $this->container->loginManager->method('isLoggedIn')->willReturn(true);
127 $this->container->sessionManager 127 $this->container->sessionManager
@@ -151,7 +151,7 @@ class SessionFilterControllerTest extends TestCase
151 { 151 {
152 $arg = ['visibility' => 'test']; 152 $arg = ['visibility' => 'test'];
153 153
154 $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/subfolder/controller/?searchtag=abc']; 154 $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller/?searchtag=abc';
155 155
156 $this->container->loginManager = $this->createMock(LoginManager::class); 156 $this->container->loginManager = $this->createMock(LoginManager::class);
157 $this->container->loginManager->method('isLoggedIn')->willReturn(false); 157 $this->container->loginManager->method('isLoggedIn')->willReturn(false);
diff --git a/tests/front/controller/admin/ShaarliAdminControllerTest.php b/tests/front/controller/admin/ShaarliAdminControllerTest.php
index fff427cb..486d5d2d 100644
--- a/tests/front/controller/admin/ShaarliAdminControllerTest.php
+++ b/tests/front/controller/admin/ShaarliAdminControllerTest.php
@@ -4,9 +4,9 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Admin; 5namespace Shaarli\Front\Controller\Admin;
6 6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Front\Exception\WrongTokenException; 7use Shaarli\Front\Exception\WrongTokenException;
9use Shaarli\Security\SessionManager; 8use Shaarli\Security\SessionManager;
9use Shaarli\TestCase;
10use Slim\Http\Request; 10use Slim\Http\Request;
11 11
12/** 12/**
diff --git a/tests/front/controller/admin/ThumbnailsControllerTest.php b/tests/front/controller/admin/ThumbnailsControllerTest.php
index 0c0c8a83..f4a8acff 100644
--- a/tests/front/controller/admin/ThumbnailsControllerTest.php
+++ b/tests/front/controller/admin/ThumbnailsControllerTest.php
@@ -4,9 +4,9 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Admin; 5namespace Shaarli\Front\Controller\Admin;
6 6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Bookmark\Bookmark; 7use Shaarli\Bookmark\Bookmark;
9use Shaarli\Bookmark\Exception\BookmarkNotFoundException; 8use Shaarli\Bookmark\Exception\BookmarkNotFoundException;
9use Shaarli\TestCase;
10use Shaarli\Thumbnailer; 10use Shaarli\Thumbnailer;
11use Slim\Http\Request; 11use Slim\Http\Request;
12use Slim\Http\Response; 12use Slim\Http\Response;
diff --git a/tests/front/controller/admin/TokenControllerTest.php b/tests/front/controller/admin/TokenControllerTest.php
index 04b0c0fa..d2f0907f 100644
--- a/tests/front/controller/admin/TokenControllerTest.php
+++ b/tests/front/controller/admin/TokenControllerTest.php
@@ -4,7 +4,7 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Admin; 5namespace Shaarli\Front\Controller\Admin;
6 6
7use PHPUnit\Framework\TestCase; 7use Shaarli\TestCase;
8use Slim\Http\Request; 8use Slim\Http\Request;
9use Slim\Http\Response; 9use Slim\Http\Response;
10 10
diff --git a/tests/front/controller/admin/ToolsControllerTest.php b/tests/front/controller/admin/ToolsControllerTest.php
index fc756f0f..e82f8b14 100644
--- a/tests/front/controller/admin/ToolsControllerTest.php
+++ b/tests/front/controller/admin/ToolsControllerTest.php
@@ -4,11 +4,11 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Admin; 5namespace Shaarli\Front\Controller\Admin;
6 6
7use PHPUnit\Framework\TestCase; 7use Shaarli\TestCase;
8use Slim\Http\Request; 8use Slim\Http\Request;
9use Slim\Http\Response; 9use Slim\Http\Response;
10 10
11class ToolsControllerTestControllerTest extends TestCase 11class ToolsControllerTest extends TestCase
12{ 12{
13 use FrontAdminControllerMockHelper; 13 use FrontAdminControllerMockHelper;
14 14
@@ -41,7 +41,7 @@ class ToolsControllerTestControllerTest extends TestCase
41 41
42 static::assertSame(200, $result->getStatusCode()); 42 static::assertSame(200, $result->getStatusCode());
43 static::assertSame('tools', (string) $result->getBody()); 43 static::assertSame('tools', (string) $result->getBody());
44 static::assertSame('https://shaarli', $assignedVariables['pageabsaddr']); 44 static::assertSame('https://shaarli/', $assignedVariables['pageabsaddr']);
45 static::assertTrue($assignedVariables['sslenabled']); 45 static::assertTrue($assignedVariables['sslenabled']);
46 } 46 }
47 47
@@ -63,7 +63,7 @@ class ToolsControllerTestControllerTest extends TestCase
63 63
64 static::assertSame(200, $result->getStatusCode()); 64 static::assertSame(200, $result->getStatusCode());
65 static::assertSame('tools', (string) $result->getBody()); 65 static::assertSame('tools', (string) $result->getBody());
66 static::assertSame('http://shaarli', $assignedVariables['pageabsaddr']); 66 static::assertSame('http://shaarli/', $assignedVariables['pageabsaddr']);
67 static::assertFalse($assignedVariables['sslenabled']); 67 static::assertFalse($assignedVariables['sslenabled']);
68 } 68 }
69} 69}
diff --git a/tests/front/controller/visitor/BookmarkListControllerTest.php b/tests/front/controller/visitor/BookmarkListControllerTest.php
index 5daaa2c4..0c95df97 100644
--- a/tests/front/controller/visitor/BookmarkListControllerTest.php
+++ b/tests/front/controller/visitor/BookmarkListControllerTest.php
@@ -4,11 +4,11 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Visitor; 5namespace Shaarli\Front\Controller\Visitor;
6 6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Bookmark\Bookmark; 7use Shaarli\Bookmark\Bookmark;
9use Shaarli\Bookmark\Exception\BookmarkNotFoundException; 8use Shaarli\Bookmark\Exception\BookmarkNotFoundException;
10use Shaarli\Config\ConfigManager; 9use Shaarli\Config\ConfigManager;
11use Shaarli\Security\LoginManager; 10use Shaarli\Security\LoginManager;
11use Shaarli\TestCase;
12use Shaarli\Thumbnailer; 12use Shaarli\Thumbnailer;
13use Slim\Http\Request; 13use Slim\Http\Request;
14use Slim\Http\Response; 14use Slim\Http\Response;
diff --git a/tests/front/controller/visitor/DailyControllerTest.php b/tests/front/controller/visitor/DailyControllerTest.php
index b802c62c..fc78bc13 100644
--- a/tests/front/controller/visitor/DailyControllerTest.php
+++ b/tests/front/controller/visitor/DailyControllerTest.php
@@ -4,9 +4,9 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Visitor; 5namespace Shaarli\Front\Controller\Visitor;
6 6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Bookmark\Bookmark; 7use Shaarli\Bookmark\Bookmark;
9use Shaarli\Feed\CachedPage; 8use Shaarli\Feed\CachedPage;
9use Shaarli\TestCase;
10use Slim\Http\Request; 10use Slim\Http\Request;
11use Slim\Http\Response; 11use Slim\Http\Response;
12 12
@@ -78,19 +78,20 @@ class DailyControllerTest extends TestCase
78 78
79 // Make sure that PluginManager hook is triggered 79 // Make sure that PluginManager hook is triggered
80 $this->container->pluginManager 80 $this->container->pluginManager
81 ->expects(static::at(0)) 81 ->expects(static::atLeastOnce())
82 ->method('executeHooks') 82 ->method('executeHooks')
83 ->withConsecutive(['render_daily'])
83 ->willReturnCallback(function (string $hook, array $data, array $param) use ($currentDay): array { 84 ->willReturnCallback(function (string $hook, array $data, array $param) use ($currentDay): array {
84 static::assertSame('render_daily', $hook); 85 if ('render_daily' === $hook) {
86 static::assertArrayHasKey('linksToDisplay', $data);
87 static::assertCount(3, $data['linksToDisplay']);
88 static::assertSame(1, $data['linksToDisplay'][0]['id']);
89 static::assertSame($currentDay->getTimestamp(), $data['day']);
90 static::assertSame('20200510', $data['previousday']);
91 static::assertSame('20200516', $data['nextday']);
85 92
86 static::assertArrayHasKey('linksToDisplay', $data); 93 static::assertArrayHasKey('loggedin', $param);
87 static::assertCount(3, $data['linksToDisplay']); 94 }
88 static::assertSame(1, $data['linksToDisplay'][0]['id']);
89 static::assertSame($currentDay->getTimestamp(), $data['day']);
90 static::assertSame('20200510', $data['previousday']);
91 static::assertSame('20200516', $data['nextday']);
92
93 static::assertArrayHasKey('loggedin', $param);
94 95
95 return $data; 96 return $data;
96 }) 97 })
@@ -203,19 +204,20 @@ class DailyControllerTest extends TestCase
203 204
204 // Make sure that PluginManager hook is triggered 205 // Make sure that PluginManager hook is triggered
205 $this->container->pluginManager 206 $this->container->pluginManager
206 ->expects(static::at(0)) 207 ->expects(static::atLeastOnce())
207 ->method('executeHooks') 208 ->method('executeHooks')
209 ->withConsecutive(['render_daily'])
208 ->willReturnCallback(function (string $hook, array $data, array $param) use ($currentDay): array { 210 ->willReturnCallback(function (string $hook, array $data, array $param) use ($currentDay): array {
209 static::assertSame('render_daily', $hook); 211 if ('render_daily' === $hook) {
210 212 static::assertArrayHasKey('linksToDisplay', $data);
211 static::assertArrayHasKey('linksToDisplay', $data); 213 static::assertCount(1, $data['linksToDisplay']);
212 static::assertCount(1, $data['linksToDisplay']); 214 static::assertSame(1, $data['linksToDisplay'][0]['id']);
213 static::assertSame(1, $data['linksToDisplay'][0]['id']); 215 static::assertSame($currentDay->getTimestamp(), $data['day']);
214 static::assertSame($currentDay->getTimestamp(), $data['day']); 216 static::assertEmpty($data['previousday']);
215 static::assertEmpty($data['previousday']); 217 static::assertEmpty($data['nextday']);
216 static::assertEmpty($data['nextday']);
217 218
218 static::assertArrayHasKey('loggedin', $param); 219 static::assertArrayHasKey('loggedin', $param);
220 }
219 221
220 return $data; 222 return $data;
221 }); 223 });
@@ -281,7 +283,7 @@ class DailyControllerTest extends TestCase
281 283
282 // Make sure that PluginManager hook is triggered 284 // Make sure that PluginManager hook is triggered
283 $this->container->pluginManager 285 $this->container->pluginManager
284 ->expects(static::at(0)) 286 ->expects(static::atLeastOnce())
285 ->method('executeHooks') 287 ->method('executeHooks')
286 ->willReturnCallback(function (string $hook, array $data, array $param): array { 288 ->willReturnCallback(function (string $hook, array $data, array $param): array {
287 return $data; 289 return $data;
@@ -333,7 +335,7 @@ class DailyControllerTest extends TestCase
333 335
334 // Make sure that PluginManager hook is triggered 336 // Make sure that PluginManager hook is triggered
335 $this->container->pluginManager 337 $this->container->pluginManager
336 ->expects(static::at(0)) 338 ->expects(static::atLeastOnce())
337 ->method('executeHooks') 339 ->method('executeHooks')
338 ->willReturnCallback(function (string $hook, array $data, array $param): array { 340 ->willReturnCallback(function (string $hook, array $data, array $param): array {
339 return $data; 341 return $data;
@@ -392,8 +394,8 @@ class DailyControllerTest extends TestCase
392 static::assertStringContainsString('application/rss', $result->getHeader('Content-Type')[0]); 394 static::assertStringContainsString('application/rss', $result->getHeader('Content-Type')[0]);
393 static::assertSame('dailyrss', (string) $result->getBody()); 395 static::assertSame('dailyrss', (string) $result->getBody());
394 static::assertSame('Shaarli', $assignedVariables['title']); 396 static::assertSame('Shaarli', $assignedVariables['title']);
395 static::assertSame('http://shaarli', $assignedVariables['index_url']); 397 static::assertSame('http://shaarli/subfolder/', $assignedVariables['index_url']);
396 static::assertSame('http://shaarli/daily-rss', $assignedVariables['page_url']); 398 static::assertSame('http://shaarli/subfolder/daily-rss', $assignedVariables['page_url']);
397 static::assertFalse($assignedVariables['hide_timestamps']); 399 static::assertFalse($assignedVariables['hide_timestamps']);
398 static::assertCount(2, $assignedVariables['days']); 400 static::assertCount(2, $assignedVariables['days']);
399 401
@@ -402,7 +404,7 @@ class DailyControllerTest extends TestCase
402 static::assertEquals($dates[0], $day['date']); 404 static::assertEquals($dates[0], $day['date']);
403 static::assertSame($dates[0]->format(\DateTime::RSS), $day['date_rss']); 405 static::assertSame($dates[0]->format(\DateTime::RSS), $day['date_rss']);
404 static::assertSame(format_date($dates[0], false), $day['date_human']); 406 static::assertSame(format_date($dates[0], false), $day['date_human']);
405 static::assertSame('http://shaarli/daily?day='. $dates[0]->format('Ymd'), $day['absolute_url']); 407 static::assertSame('http://shaarli/subfolder/daily?day='. $dates[0]->format('Ymd'), $day['absolute_url']);
406 static::assertCount(1, $day['links']); 408 static::assertCount(1, $day['links']);
407 static::assertSame(1, $day['links'][0]['id']); 409 static::assertSame(1, $day['links'][0]['id']);
408 static::assertSame('http://domain.tld/1', $day['links'][0]['url']); 410 static::assertSame('http://domain.tld/1', $day['links'][0]['url']);
@@ -413,7 +415,7 @@ class DailyControllerTest extends TestCase
413 static::assertEquals($dates[1], $day['date']); 415 static::assertEquals($dates[1], $day['date']);
414 static::assertSame($dates[1]->format(\DateTime::RSS), $day['date_rss']); 416 static::assertSame($dates[1]->format(\DateTime::RSS), $day['date_rss']);
415 static::assertSame(format_date($dates[1], false), $day['date_human']); 417 static::assertSame(format_date($dates[1], false), $day['date_human']);
416 static::assertSame('http://shaarli/daily?day='. $dates[1]->format('Ymd'), $day['absolute_url']); 418 static::assertSame('http://shaarli/subfolder/daily?day='. $dates[1]->format('Ymd'), $day['absolute_url']);
417 static::assertCount(2, $day['links']); 419 static::assertCount(2, $day['links']);
418 420
419 static::assertSame(2, $day['links'][0]['id']); 421 static::assertSame(2, $day['links'][0]['id']);
@@ -468,8 +470,8 @@ class DailyControllerTest extends TestCase
468 static::assertStringContainsString('application/rss', $result->getHeader('Content-Type')[0]); 470 static::assertStringContainsString('application/rss', $result->getHeader('Content-Type')[0]);
469 static::assertSame('dailyrss', (string) $result->getBody()); 471 static::assertSame('dailyrss', (string) $result->getBody());
470 static::assertSame('Shaarli', $assignedVariables['title']); 472 static::assertSame('Shaarli', $assignedVariables['title']);
471 static::assertSame('http://shaarli', $assignedVariables['index_url']); 473 static::assertSame('http://shaarli/subfolder/', $assignedVariables['index_url']);
472 static::assertSame('http://shaarli/daily-rss', $assignedVariables['page_url']); 474 static::assertSame('http://shaarli/subfolder/daily-rss', $assignedVariables['page_url']);
473 static::assertFalse($assignedVariables['hide_timestamps']); 475 static::assertFalse($assignedVariables['hide_timestamps']);
474 static::assertCount(0, $assignedVariables['days']); 476 static::assertCount(0, $assignedVariables['days']);
475 } 477 }
diff --git a/tests/front/controller/visitor/ErrorControllerTest.php b/tests/front/controller/visitor/ErrorControllerTest.php
index e497bfef..75408cf4 100644
--- a/tests/front/controller/visitor/ErrorControllerTest.php
+++ b/tests/front/controller/visitor/ErrorControllerTest.php
@@ -4,8 +4,8 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Visitor; 5namespace Shaarli\Front\Controller\Visitor;
6 6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Front\Exception\ShaarliFrontException; 7use Shaarli\Front\Exception\ShaarliFrontException;
8use Shaarli\TestCase;
9use Slim\Http\Request; 9use Slim\Http\Request;
10use Slim\Http\Response; 10use Slim\Http\Response;
11 11
diff --git a/tests/front/controller/visitor/ErrorNotFoundControllerTest.php b/tests/front/controller/visitor/ErrorNotFoundControllerTest.php
new file mode 100644
index 00000000..a1cbbecf
--- /dev/null
+++ b/tests/front/controller/visitor/ErrorNotFoundControllerTest.php
@@ -0,0 +1,81 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Shaarli\Front\Controller\Visitor;
6
7use Shaarli\TestCase;
8use Slim\Http\Request;
9use Slim\Http\Response;
10use Slim\Http\Uri;
11
12class ErrorNotFoundControllerTest extends TestCase
13{
14 use FrontControllerMockHelper;
15
16 /** @var ErrorNotFoundController */
17 protected $controller;
18
19 public function setUp(): void
20 {
21 $this->createContainer();
22
23 $this->controller = new ErrorNotFoundController($this->container);
24 }
25
26 /**
27 * Test displaying 404 error
28 */
29 public function testDisplayNotFoundError(): void
30 {
31 $request = $this->createMock(Request::class);
32 $request->expects(static::once())->method('getRequestTarget')->willReturn('/');
33 $request->method('getUri')->willReturnCallback(function (): Uri {
34 $uri = $this->createMock(Uri::class);
35 $uri->method('getBasePath')->willReturn('/subfolder');
36
37 return $uri;
38 });
39
40 $response = new Response();
41
42 // Save RainTPL assigned variables
43 $assignedVariables = [];
44 $this->assignTemplateVars($assignedVariables);
45
46 $result = ($this->controller)(
47 $request,
48 $response
49 );
50
51 static::assertSame(404, $result->getStatusCode());
52 static::assertSame('404', (string) $result->getBody());
53 static::assertSame('Requested page could not be found.', $assignedVariables['error_message']);
54 }
55
56 /**
57 * Test displaying 404 error from REST API
58 */
59 public function testDisplayNotFoundErrorFromAPI(): void
60 {
61 $request = $this->createMock(Request::class);
62 $request->expects(static::once())->method('getRequestTarget')->willReturn('/sufolder/api/v1/links');
63 $request->method('getUri')->willReturnCallback(function (): Uri {
64 $uri = $this->createMock(Uri::class);
65 $uri->method('getBasePath')->willReturn('/subfolder');
66
67 return $uri;
68 });
69
70 $response = new Response();
71
72 // Save RainTPL assigned variables
73 $assignedVariables = [];
74 $this->assignTemplateVars($assignedVariables);
75
76 $result = ($this->controller)($request, $response);
77
78 static::assertSame(404, $result->getStatusCode());
79 static::assertSame([], $assignedVariables);
80 }
81}
diff --git a/tests/front/controller/visitor/FeedControllerTest.php b/tests/front/controller/visitor/FeedControllerTest.php
index fb417e2a..4ae7c925 100644
--- a/tests/front/controller/visitor/FeedControllerTest.php
+++ b/tests/front/controller/visitor/FeedControllerTest.php
@@ -4,8 +4,8 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Visitor; 5namespace Shaarli\Front\Controller\Visitor;
6 6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Feed\FeedBuilder; 7use Shaarli\Feed\FeedBuilder;
8use Shaarli\TestCase;
9use Slim\Http\Request; 9use Slim\Http\Request;
10use Slim\Http\Response; 10use Slim\Http\Response;
11 11
@@ -45,14 +45,16 @@ class FeedControllerTest extends TestCase
45 45
46 // Make sure that PluginManager hook is triggered 46 // Make sure that PluginManager hook is triggered
47 $this->container->pluginManager 47 $this->container->pluginManager
48 ->expects(static::at(0)) 48 ->expects(static::atLeastOnce())
49 ->method('executeHooks') 49 ->method('executeHooks')
50 ->withConsecutive(['render_feed'])
50 ->willReturnCallback(function (string $hook, array $data, array $param): void { 51 ->willReturnCallback(function (string $hook, array $data, array $param): void {
51 static::assertSame('render_feed', $hook); 52 if ('render_feed' === $hook) {
52 static::assertSame('data', $data['content']); 53 static::assertSame('data', $data['content']);
53 54
54 static::assertArrayHasKey('loggedin', $param); 55 static::assertArrayHasKey('loggedin', $param);
55 static::assertSame('rss', $param['target']); 56 static::assertSame('feed.rss', $param['target']);
57 }
56 }) 58 })
57 ; 59 ;
58 60
@@ -84,14 +86,16 @@ class FeedControllerTest extends TestCase
84 86
85 // Make sure that PluginManager hook is triggered 87 // Make sure that PluginManager hook is triggered
86 $this->container->pluginManager 88 $this->container->pluginManager
87 ->expects(static::at(0)) 89 ->expects(static::atLeastOnce())
88 ->method('executeHooks') 90 ->method('executeHooks')
91 ->withConsecutive(['render_feed'])
89 ->willReturnCallback(function (string $hook, array $data, array $param): void { 92 ->willReturnCallback(function (string $hook, array $data, array $param): void {
90 static::assertSame('render_feed', $hook); 93 if ('render_feed' === $hook) {
91 static::assertSame('data', $data['content']); 94 static::assertSame('data', $data['content']);
92 95
93 static::assertArrayHasKey('loggedin', $param); 96 static::assertArrayHasKey('loggedin', $param);
94 static::assertSame('atom', $param['target']); 97 static::assertSame('feed.atom', $param['target']);
98 }
95 }) 99 })
96 ; 100 ;
97 101
@@ -124,14 +128,16 @@ class FeedControllerTest extends TestCase
124 128
125 // Make sure that PluginManager hook is triggered 129 // Make sure that PluginManager hook is triggered
126 $this->container->pluginManager 130 $this->container->pluginManager
127 ->expects(static::at(0)) 131 ->expects(static::atLeastOnce())
128 ->method('executeHooks') 132 ->method('executeHooks')
133 ->withConsecutive(['render_feed'])
129 ->willReturnCallback(function (string $hook, array $data, array $param): void { 134 ->willReturnCallback(function (string $hook, array $data, array $param): void {
130 static::assertSame('render_feed', $hook); 135 if ('render_feed' === $hook) {
131 static::assertSame('data', $data['content']); 136 static::assertSame('data', $data['content']);
132 137
133 static::assertArrayHasKey('loggedin', $param); 138 static::assertArrayHasKey('loggedin', $param);
134 static::assertSame('atom', $param['target']); 139 static::assertSame('feed.atom', $param['target']);
140 }
135 }) 141 })
136 ; 142 ;
137 143
diff --git a/tests/front/controller/visitor/FrontControllerMockHelper.php b/tests/front/controller/visitor/FrontControllerMockHelper.php
index e0bd4ecf..fc0bb7d1 100644
--- a/tests/front/controller/visitor/FrontControllerMockHelper.php
+++ b/tests/front/controller/visitor/FrontControllerMockHelper.php
@@ -4,7 +4,6 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Visitor; 5namespace Shaarli\Front\Controller\Visitor;
6 6
7use PHPUnit\Framework\MockObject\MockObject;
8use Shaarli\Bookmark\BookmarkServiceInterface; 7use Shaarli\Bookmark\BookmarkServiceInterface;
9use Shaarli\Config\ConfigManager; 8use Shaarli\Config\ConfigManager;
10use Shaarli\Container\ShaarliTestContainer; 9use Shaarli\Container\ShaarliTestContainer;
@@ -79,8 +78,9 @@ trait FrontControllerMockHelper
79 $this->container->environment = [ 78 $this->container->environment = [
80 'SERVER_NAME' => 'shaarli', 79 'SERVER_NAME' => 'shaarli',
81 'SERVER_PORT' => '80', 80 'SERVER_PORT' => '80',
82 'REQUEST_URI' => '/daily-rss', 81 'REQUEST_URI' => '/subfolder/daily-rss',
83 'REMOTE_ADDR' => '1.2.3.4', 82 'REMOTE_ADDR' => '1.2.3.4',
83 'SCRIPT_NAME' => '/subfolder/index.php',
84 ]; 84 ];
85 85
86 $this->container->basePath = '/subfolder'; 86 $this->container->basePath = '/subfolder';
@@ -94,7 +94,6 @@ trait FrontControllerMockHelper
94 protected function assignTemplateVars(array &$variables): void 94 protected function assignTemplateVars(array &$variables): void
95 { 95 {
96 $this->container->pageBuilder 96 $this->container->pageBuilder
97 ->expects(static::atLeastOnce())
98 ->method('assign') 97 ->method('assign')
99 ->willReturnCallback(function ($key, $value) use (&$variables) { 98 ->willReturnCallback(function ($key, $value) use (&$variables) {
100 $variables[$key] = $value; 99 $variables[$key] = $value;
@@ -115,5 +114,5 @@ trait FrontControllerMockHelper
115 /** 114 /**
116 * Force to be used in PHPUnit context. 115 * Force to be used in PHPUnit context.
117 */ 116 */
118 protected abstract function createMock($originalClassName): MockObject; 117 protected abstract function isInTestsContext(): bool;
119} 118}
diff --git a/tests/front/controller/visitor/InstallControllerTest.php b/tests/front/controller/visitor/InstallControllerTest.php
index 3b855365..345ad544 100644
--- a/tests/front/controller/visitor/InstallControllerTest.php
+++ b/tests/front/controller/visitor/InstallControllerTest.php
@@ -4,10 +4,10 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Visitor; 5namespace Shaarli\Front\Controller\Visitor;
6 6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Config\ConfigManager; 7use Shaarli\Config\ConfigManager;
9use Shaarli\Front\Exception\AlreadyInstalledException; 8use Shaarli\Front\Exception\AlreadyInstalledException;
10use Shaarli\Security\SessionManager; 9use Shaarli\Security\SessionManager;
10use Shaarli\TestCase;
11use Slim\Http\Request; 11use Slim\Http\Request;
12use Slim\Http\Response; 12use Slim\Http\Response;
13 13
@@ -257,6 +257,39 @@ class InstallControllerTest extends TestCase
257 static::assertSame('/subfolder/login', $result->getHeader('location')[0]); 257 static::assertSame('/subfolder/login', $result->getHeader('location')[0]);
258 258
259 static::assertSame('UTC', $confSettings['general.timezone']); 259 static::assertSame('UTC', $confSettings['general.timezone']);
260 static::assertSame('Shared bookmarks on http://shaarli', $confSettings['general.title']); 260 static::assertSame('Shared bookmarks on http://shaarli/subfolder/', $confSettings['general.title']);
261 }
262
263 /**
264 * Same test as testSaveInstallDefaultValues() but for an instance install in root directory.
265 */
266 public function testSaveInstallDefaultValuesWithoutSubfolder(): void
267 {
268 $confSettings = [];
269
270 $this->container->environment = [
271 'SERVER_NAME' => 'shaarli',
272 'SERVER_PORT' => '80',
273 'REQUEST_URI' => '/install',
274 'REMOTE_ADDR' => '1.2.3.4',
275 'SCRIPT_NAME' => '/index.php',
276 ];
277
278 $this->container->basePath = '';
279
280 $request = $this->createMock(Request::class);
281 $response = new Response();
282
283 $this->container->conf->method('set')->willReturnCallback(function (string $key, $value) use (&$confSettings) {
284 $confSettings[$key] = $value;
285 });
286
287 $result = $this->controller->save($request, $response);
288
289 static::assertSame(302, $result->getStatusCode());
290 static::assertSame('/login', $result->getHeader('location')[0]);
291
292 static::assertSame('UTC', $confSettings['general.timezone']);
293 static::assertSame('Shared bookmarks on http://shaarli/', $confSettings['general.title']);
261 } 294 }
262} 295}
diff --git a/tests/front/controller/visitor/LoginControllerTest.php b/tests/front/controller/visitor/LoginControllerTest.php
index 0a21f938..1312ccb7 100644
--- a/tests/front/controller/visitor/LoginControllerTest.php
+++ b/tests/front/controller/visitor/LoginControllerTest.php
@@ -4,13 +4,13 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Visitor; 5namespace Shaarli\Front\Controller\Visitor;
6 6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Config\ConfigManager; 7use Shaarli\Config\ConfigManager;
9use Shaarli\Front\Exception\LoginBannedException; 8use Shaarli\Front\Exception\LoginBannedException;
10use Shaarli\Front\Exception\WrongTokenException; 9use Shaarli\Front\Exception\WrongTokenException;
11use Shaarli\Render\TemplatePage; 10use Shaarli\Render\TemplatePage;
12use Shaarli\Security\CookieManager; 11use Shaarli\Security\CookieManager;
13use Shaarli\Security\SessionManager; 12use Shaarli\Security\SessionManager;
13use Shaarli\TestCase;
14use Slim\Http\Request; 14use Slim\Http\Request;
15use Slim\Http\Response; 15use Slim\Http\Response;
16 16
diff --git a/tests/front/controller/visitor/OpenSearchControllerTest.php b/tests/front/controller/visitor/OpenSearchControllerTest.php
index 5f9f5b12..42d876c3 100644
--- a/tests/front/controller/visitor/OpenSearchControllerTest.php
+++ b/tests/front/controller/visitor/OpenSearchControllerTest.php
@@ -4,7 +4,7 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Visitor; 5namespace Shaarli\Front\Controller\Visitor;
6 6
7use PHPUnit\Framework\TestCase; 7use Shaarli\TestCase;
8use Slim\Http\Request; 8use Slim\Http\Request;
9use Slim\Http\Response; 9use Slim\Http\Response;
10 10
@@ -39,6 +39,6 @@ class OpenSearchControllerTest extends TestCase
39 $result->getHeader('Content-Type')[0] 39 $result->getHeader('Content-Type')[0]
40 ); 40 );
41 static::assertSame('opensearch', (string) $result->getBody()); 41 static::assertSame('opensearch', (string) $result->getBody());
42 static::assertSame('http://shaarli', $assignedVariables['serverurl']); 42 static::assertSame('http://shaarli/subfolder/', $assignedVariables['serverurl']);
43 } 43 }
44} 44}
diff --git a/tests/front/controller/visitor/PictureWallControllerTest.php b/tests/front/controller/visitor/PictureWallControllerTest.php
index 3dc3f292..b868231d 100644
--- a/tests/front/controller/visitor/PictureWallControllerTest.php
+++ b/tests/front/controller/visitor/PictureWallControllerTest.php
@@ -4,10 +4,10 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Visitor; 5namespace Shaarli\Front\Controller\Visitor;
6 6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Bookmark\Bookmark; 7use Shaarli\Bookmark\Bookmark;
9use Shaarli\Config\ConfigManager; 8use Shaarli\Config\ConfigManager;
10use Shaarli\Front\Exception\ThumbnailsDisabledException; 9use Shaarli\Front\Exception\ThumbnailsDisabledException;
10use Shaarli\TestCase;
11use Shaarli\Thumbnailer; 11use Shaarli\Thumbnailer;
12use Slim\Http\Request; 12use Slim\Http\Request;
13use Slim\Http\Response; 13use Slim\Http\Response;
@@ -67,15 +67,17 @@ class PictureWallControllerTest extends TestCase
67 67
68 // Make sure that PluginManager hook is triggered 68 // Make sure that PluginManager hook is triggered
69 $this->container->pluginManager 69 $this->container->pluginManager
70 ->expects(static::at(0)) 70 ->expects(static::atLeastOnce())
71 ->method('executeHooks') 71 ->method('executeHooks')
72 ->withConsecutive(['render_picwall'])
72 ->willReturnCallback(function (string $hook, array $data, array $param): array { 73 ->willReturnCallback(function (string $hook, array $data, array $param): array {
73 static::assertSame('render_picwall', $hook); 74 if ('render_picwall' === $hook) {
74 static::assertArrayHasKey('linksToDisplay', $data); 75 static::assertArrayHasKey('linksToDisplay', $data);
75 static::assertCount(2, $data['linksToDisplay']); 76 static::assertCount(2, $data['linksToDisplay']);
76 static::assertSame(1, $data['linksToDisplay'][0]['id']); 77 static::assertSame(1, $data['linksToDisplay'][0]['id']);
77 static::assertSame(3, $data['linksToDisplay'][1]['id']); 78 static::assertSame(3, $data['linksToDisplay'][1]['id']);
78 static::assertArrayHasKey('loggedin', $param); 79 static::assertArrayHasKey('loggedin', $param);
80 }
79 81
80 return $data; 82 return $data;
81 }); 83 });
diff --git a/tests/front/controller/visitor/PublicSessionFilterControllerTest.php b/tests/front/controller/visitor/PublicSessionFilterControllerTest.php
index 06352750..7e3b00af 100644
--- a/tests/front/controller/visitor/PublicSessionFilterControllerTest.php
+++ b/tests/front/controller/visitor/PublicSessionFilterControllerTest.php
@@ -4,8 +4,8 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Visitor; 5namespace Shaarli\Front\Controller\Visitor;
6 6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Security\SessionManager; 7use Shaarli\Security\SessionManager;
8use Shaarli\TestCase;
9use Slim\Http\Request; 9use Slim\Http\Request;
10use Slim\Http\Response; 10use Slim\Http\Response;
11 11
@@ -28,7 +28,7 @@ class PublicSessionFilterControllerTest extends TestCase
28 */ 28 */
29 public function testLinksPerPage(): void 29 public function testLinksPerPage(): void
30 { 30 {
31 $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/subfolder/controller/?searchtag=abc']; 31 $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller/?searchtag=abc';
32 32
33 $request = $this->createMock(Request::class); 33 $request = $this->createMock(Request::class);
34 $request->method('getParam')->with('nb')->willReturn('8'); 34 $request->method('getParam')->with('nb')->willReturn('8');
@@ -74,7 +74,7 @@ class PublicSessionFilterControllerTest extends TestCase
74 */ 74 */
75 public function testUntaggedOnly(): void 75 public function testUntaggedOnly(): void
76 { 76 {
77 $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/subfolder/controller/?searchtag=abc']; 77 $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller/?searchtag=abc';
78 78
79 $request = $this->createMock(Request::class); 79 $request = $this->createMock(Request::class);
80 $response = new Response(); 80 $response = new Response();
@@ -97,7 +97,7 @@ class PublicSessionFilterControllerTest extends TestCase
97 */ 97 */
98 public function testUntaggedOnlyToggleOff(): void 98 public function testUntaggedOnlyToggleOff(): void
99 { 99 {
100 $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/subfolder/controller/?searchtag=abc']; 100 $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller/?searchtag=abc';
101 101
102 $request = $this->createMock(Request::class); 102 $request = $this->createMock(Request::class);
103 $response = new Response(); 103 $response = new Response();
diff --git a/tests/front/controller/visitor/ShaarliVisitorControllerTest.php b/tests/front/controller/visitor/ShaarliVisitorControllerTest.php
index 316ce49c..935ec24e 100644
--- a/tests/front/controller/visitor/ShaarliVisitorControllerTest.php
+++ b/tests/front/controller/visitor/ShaarliVisitorControllerTest.php
@@ -4,8 +4,8 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Visitor; 5namespace Shaarli\Front\Controller\Visitor;
6 6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Bookmark\BookmarkFilter; 7use Shaarli\Bookmark\BookmarkFilter;
8use Shaarli\TestCase;
9use Slim\Http\Request; 9use Slim\Http\Request;
10use Slim\Http\Response; 10use Slim\Http\Response;
11 11
@@ -110,7 +110,7 @@ class ShaarliVisitorControllerTest extends TestCase
110 */ 110 */
111 public function testRedirectFromRefererDefault(): void 111 public function testRedirectFromRefererDefault(): void
112 { 112 {
113 $this->container->environment['HTTP_REFERER'] = 'http://shaarli.tld/subfolder/controller?query=param&other=2'; 113 $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller?query=param&other=2';
114 114
115 $response = new Response(); 115 $response = new Response();
116 116
@@ -125,7 +125,7 @@ class ShaarliVisitorControllerTest extends TestCase
125 */ 125 */
126 public function testRedirectFromRefererWithUnmatchedLoopTerm(): void 126 public function testRedirectFromRefererWithUnmatchedLoopTerm(): void
127 { 127 {
128 $this->container->environment['HTTP_REFERER'] = 'http://shaarli.tld/subfolder/controller?query=param&other=2'; 128 $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller?query=param&other=2';
129 129
130 $response = new Response(); 130 $response = new Response();
131 131
@@ -140,7 +140,7 @@ class ShaarliVisitorControllerTest extends TestCase
140 */ 140 */
141 public function testRedirectFromRefererWithMatchingLoopTermInPath(): void 141 public function testRedirectFromRefererWithMatchingLoopTermInPath(): void
142 { 142 {
143 $this->container->environment['HTTP_REFERER'] = 'http://shaarli.tld/subfolder/controller?query=param&other=2'; 143 $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller?query=param&other=2';
144 144
145 $response = new Response(); 145 $response = new Response();
146 146
@@ -155,7 +155,7 @@ class ShaarliVisitorControllerTest extends TestCase
155 */ 155 */
156 public function testRedirectFromRefererWithMatchingLoopTermInQueryParam(): void 156 public function testRedirectFromRefererWithMatchingLoopTermInQueryParam(): void
157 { 157 {
158 $this->container->environment['HTTP_REFERER'] = 'http://shaarli.tld/subfolder/controller?query=param&other=2'; 158 $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller?query=param&other=2';
159 159
160 $response = new Response(); 160 $response = new Response();
161 161
@@ -171,7 +171,7 @@ class ShaarliVisitorControllerTest extends TestCase
171 */ 171 */
172 public function testRedirectFromRefererWithMatchingLoopTermInQueryValue(): void 172 public function testRedirectFromRefererWithMatchingLoopTermInQueryValue(): void
173 { 173 {
174 $this->container->environment['HTTP_REFERER'] = 'http://shaarli.tld/subfolder/controller?query=param&other=2'; 174 $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller?query=param&other=2';
175 175
176 $response = new Response(); 176 $response = new Response();
177 177
@@ -187,7 +187,7 @@ class ShaarliVisitorControllerTest extends TestCase
187 */ 187 */
188 public function testRedirectFromRefererWithLoopTermInDomain(): void 188 public function testRedirectFromRefererWithLoopTermInDomain(): void
189 { 189 {
190 $this->container->environment['HTTP_REFERER'] = 'http://shaarli.tld/subfolder/controller?query=param&other=2'; 190 $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller?query=param&other=2';
191 191
192 $response = new Response(); 192 $response = new Response();
193 193
@@ -203,7 +203,7 @@ class ShaarliVisitorControllerTest extends TestCase
203 */ 203 */
204 public function testRedirectFromRefererWithMatchingClearedParam(): void 204 public function testRedirectFromRefererWithMatchingClearedParam(): void
205 { 205 {
206 $this->container->environment['HTTP_REFERER'] = 'http://shaarli.tld/subfolder/controller?query=param&other=2'; 206 $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller?query=param&other=2';
207 207
208 $response = new Response(); 208 $response = new Response();
209 209
@@ -212,4 +212,35 @@ class ShaarliVisitorControllerTest extends TestCase
212 static::assertSame(302, $result->getStatusCode()); 212 static::assertSame(302, $result->getStatusCode());
213 static::assertSame(['/subfolder/controller?other=2'], $result->getHeader('location')); 213 static::assertSame(['/subfolder/controller?other=2'], $result->getHeader('location'));
214 } 214 }
215
216 /**
217 * Test redirectFromReferer() - From another domain -> we ignore the given referrer.
218 */
219 public function testRedirectExternalReferer(): void
220 {
221 $this->container->environment['HTTP_REFERER'] = 'http://other.domain.tld/controller?query=param&other=2';
222
223 $response = new Response();
224
225 $result = $this->controller->redirectFromReferer($this->request, $response, ['query'], ['query']);
226
227 static::assertSame(302, $result->getStatusCode());
228 static::assertSame(['/subfolder/'], $result->getHeader('location'));
229 }
230
231 /**
232 * Test redirectFromReferer() - From another domain -> we ignore the given referrer.
233 */
234 public function testRedirectExternalRefererExplicitDomainName(): void
235 {
236 $this->container->environment['SERVER_NAME'] = 'my.shaarli.tld';
237 $this->container->environment['HTTP_REFERER'] = 'http://your.shaarli.tld/controller?query=param&other=2';
238
239 $response = new Response();
240
241 $result = $this->controller->redirectFromReferer($this->request, $response, ['query'], ['query']);
242
243 static::assertSame(302, $result->getStatusCode());
244 static::assertSame(['/subfolder/'], $result->getHeader('location'));
245 }
215} 246}
diff --git a/tests/front/controller/visitor/TagCloudControllerTest.php b/tests/front/controller/visitor/TagCloudControllerTest.php
index 9a6a4bc0..9305612e 100644
--- a/tests/front/controller/visitor/TagCloudControllerTest.php
+++ b/tests/front/controller/visitor/TagCloudControllerTest.php
@@ -4,8 +4,8 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Visitor; 5namespace Shaarli\Front\Controller\Visitor;
6 6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Bookmark\BookmarkFilter; 7use Shaarli\Bookmark\BookmarkFilter;
8use Shaarli\TestCase;
9use Slim\Http\Request; 9use Slim\Http\Request;
10use Slim\Http\Response; 10use Slim\Http\Response;
11 11
@@ -53,14 +53,16 @@ class TagCloudControllerTest extends TestCase
53 53
54 // Make sure that PluginManager hook is triggered 54 // Make sure that PluginManager hook is triggered
55 $this->container->pluginManager 55 $this->container->pluginManager
56 ->expects(static::at(0)) 56 ->expects(static::atLeastOnce())
57 ->method('executeHooks') 57 ->method('executeHooks')
58 ->withConsecutive(['render_tagcloud'])
58 ->willReturnCallback(function (string $hook, array $data, array $param): array { 59 ->willReturnCallback(function (string $hook, array $data, array $param): array {
59 static::assertSame('render_tagcloud', $hook); 60 if ('render_tagcloud' === $hook) {
60 static::assertSame('', $data['search_tags']); 61 static::assertSame('', $data['search_tags']);
61 static::assertCount(3, $data['tags']); 62 static::assertCount(3, $data['tags']);
62 63
63 static::assertArrayHasKey('loggedin', $param); 64 static::assertArrayHasKey('loggedin', $param);
65 }
64 66
65 return $data; 67 return $data;
66 }) 68 })
@@ -124,14 +126,16 @@ class TagCloudControllerTest extends TestCase
124 126
125 // Make sure that PluginManager hook is triggered 127 // Make sure that PluginManager hook is triggered
126 $this->container->pluginManager 128 $this->container->pluginManager
127 ->expects(static::at(0)) 129 ->expects(static::atLeastOnce())
128 ->method('executeHooks') 130 ->method('executeHooks')
131 ->withConsecutive(['render_tagcloud'])
129 ->willReturnCallback(function (string $hook, array $data, array $param): array { 132 ->willReturnCallback(function (string $hook, array $data, array $param): array {
130 static::assertSame('render_tagcloud', $hook); 133 if ('render_tagcloud' === $hook) {
131 static::assertSame('ghi def', $data['search_tags']); 134 static::assertSame('ghi def', $data['search_tags']);
132 static::assertCount(1, $data['tags']); 135 static::assertCount(1, $data['tags']);
133 136
134 static::assertArrayHasKey('loggedin', $param); 137 static::assertArrayHasKey('loggedin', $param);
138 }
135 139
136 return $data; 140 return $data;
137 }) 141 })
@@ -175,14 +179,16 @@ class TagCloudControllerTest extends TestCase
175 179
176 // Make sure that PluginManager hook is triggered 180 // Make sure that PluginManager hook is triggered
177 $this->container->pluginManager 181 $this->container->pluginManager
178 ->expects(static::at(0)) 182 ->expects(static::atLeastOnce())
179 ->method('executeHooks') 183 ->method('executeHooks')
184 ->withConsecutive(['render_tagcloud'])
180 ->willReturnCallback(function (string $hook, array $data, array $param): array { 185 ->willReturnCallback(function (string $hook, array $data, array $param): array {
181 static::assertSame('render_tagcloud', $hook); 186 if ('render_tagcloud' === $hook) {
182 static::assertSame('', $data['search_tags']); 187 static::assertSame('', $data['search_tags']);
183 static::assertCount(0, $data['tags']); 188 static::assertCount(0, $data['tags']);
184 189
185 static::assertArrayHasKey('loggedin', $param); 190 static::assertArrayHasKey('loggedin', $param);
191 }
186 192
187 return $data; 193 return $data;
188 }) 194 })
@@ -227,14 +233,16 @@ class TagCloudControllerTest extends TestCase
227 233
228 // Make sure that PluginManager hook is triggered 234 // Make sure that PluginManager hook is triggered
229 $this->container->pluginManager 235 $this->container->pluginManager
230 ->expects(static::at(0)) 236 ->expects(static::atLeastOnce())
231 ->method('executeHooks') 237 ->method('executeHooks')
238 ->withConsecutive(['render_taglist'])
232 ->willReturnCallback(function (string $hook, array $data, array $param): array { 239 ->willReturnCallback(function (string $hook, array $data, array $param): array {
233 static::assertSame('render_taglist', $hook); 240 if ('render_taglist' === $hook) {
234 static::assertSame('', $data['search_tags']); 241 static::assertSame('', $data['search_tags']);
235 static::assertCount(3, $data['tags']); 242 static::assertCount(3, $data['tags']);
236 243
237 static::assertArrayHasKey('loggedin', $param); 244 static::assertArrayHasKey('loggedin', $param);
245 }
238 246
239 return $data; 247 return $data;
240 }) 248 })
@@ -297,14 +305,16 @@ class TagCloudControllerTest extends TestCase
297 305
298 // Make sure that PluginManager hook is triggered 306 // Make sure that PluginManager hook is triggered
299 $this->container->pluginManager 307 $this->container->pluginManager
300 ->expects(static::at(0)) 308 ->expects(static::atLeastOnce())
301 ->method('executeHooks') 309 ->method('executeHooks')
310 ->withConsecutive(['render_taglist'])
302 ->willReturnCallback(function (string $hook, array $data, array $param): array { 311 ->willReturnCallback(function (string $hook, array $data, array $param): array {
303 static::assertSame('render_taglist', $hook); 312 if ('render_taglist' === $hook) {
304 static::assertSame('ghi def', $data['search_tags']); 313 static::assertSame('ghi def', $data['search_tags']);
305 static::assertCount(1, $data['tags']); 314 static::assertCount(1, $data['tags']);
306 315
307 static::assertArrayHasKey('loggedin', $param); 316 static::assertArrayHasKey('loggedin', $param);
317 }
308 318
309 return $data; 319 return $data;
310 }) 320 })
@@ -344,14 +354,16 @@ class TagCloudControllerTest extends TestCase
344 354
345 // Make sure that PluginManager hook is triggered 355 // Make sure that PluginManager hook is triggered
346 $this->container->pluginManager 356 $this->container->pluginManager
347 ->expects(static::at(0)) 357 ->expects(static::atLeastOnce())
348 ->method('executeHooks') 358 ->method('executeHooks')
359 ->withConsecutive(['render_taglist'])
349 ->willReturnCallback(function (string $hook, array $data, array $param): array { 360 ->willReturnCallback(function (string $hook, array $data, array $param): array {
350 static::assertSame('render_taglist', $hook); 361 if ('render_taglist' === $hook) {
351 static::assertSame('', $data['search_tags']); 362 static::assertSame('', $data['search_tags']);
352 static::assertCount(0, $data['tags']); 363 static::assertCount(0, $data['tags']);
353 364
354 static::assertArrayHasKey('loggedin', $param); 365 static::assertArrayHasKey('loggedin', $param);
366 }
355 367
356 return $data; 368 return $data;
357 }) 369 })
diff --git a/tests/front/controller/visitor/TagControllerTest.php b/tests/front/controller/visitor/TagControllerTest.php
index 43076086..750ea02d 100644
--- a/tests/front/controller/visitor/TagControllerTest.php
+++ b/tests/front/controller/visitor/TagControllerTest.php
@@ -4,7 +4,7 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Visitor; 5namespace Shaarli\Front\Controller\Visitor;
6 6
7use PHPUnit\Framework\TestCase; 7use Shaarli\TestCase;
8use Slim\Http\Request; 8use Slim\Http\Request;
9use Slim\Http\Response; 9use Slim\Http\Response;
10 10
diff --git a/tests/http/HttpUtils/ClientIpIdTest.php b/tests/http/HttpUtils/ClientIpIdTest.php
index 982e57e0..3a0fcf30 100644
--- a/tests/http/HttpUtils/ClientIpIdTest.php
+++ b/tests/http/HttpUtils/ClientIpIdTest.php
@@ -10,7 +10,7 @@ require_once 'application/http/HttpUtils.php';
10/** 10/**
11 * Unitary tests for client_ip_id() 11 * Unitary tests for client_ip_id()
12 */ 12 */
13class ClientIpIdTest extends \PHPUnit\Framework\TestCase 13class ClientIpIdTest extends \Shaarli\TestCase
14{ 14{
15 /** 15 /**
16 * Get a remote client ID based on its IP 16 * Get a remote client ID based on its IP
diff --git a/tests/http/HttpUtils/GetHttpUrlTest.php b/tests/http/HttpUtils/GetHttpUrlTest.php
index 3dc5bc9b..a868ac02 100644
--- a/tests/http/HttpUtils/GetHttpUrlTest.php
+++ b/tests/http/HttpUtils/GetHttpUrlTest.php
@@ -10,7 +10,7 @@ require_once 'application/http/HttpUtils.php';
10/** 10/**
11 * Unitary tests for get_http_response() 11 * Unitary tests for get_http_response()
12 */ 12 */
13class GetHttpUrlTest extends \PHPUnit\Framework\TestCase 13class GetHttpUrlTest extends \Shaarli\TestCase
14{ 14{
15 /** 15 /**
16 * Get an invalid local URL 16 * Get an invalid local URL
diff --git a/tests/http/HttpUtils/GetIpAdressFromProxyTest.php b/tests/http/HttpUtils/GetIpAdressFromProxyTest.php
index fe3a639e..60cdb992 100644
--- a/tests/http/HttpUtils/GetIpAdressFromProxyTest.php
+++ b/tests/http/HttpUtils/GetIpAdressFromProxyTest.php
@@ -7,7 +7,7 @@ require_once 'application/http/HttpUtils.php';
7/** 7/**
8 * Unitary tests for getIpAddressFromProxy() 8 * Unitary tests for getIpAddressFromProxy()
9 */ 9 */
10class GetIpAdressFromProxyTest extends \PHPUnit\Framework\TestCase 10class GetIpAdressFromProxyTest extends \Shaarli\TestCase
11{ 11{
12 12
13 /** 13 /**
diff --git a/tests/http/HttpUtils/IndexUrlTest.php b/tests/http/HttpUtils/IndexUrlTest.php
index 73d33cd4..f283d119 100644
--- a/tests/http/HttpUtils/IndexUrlTest.php
+++ b/tests/http/HttpUtils/IndexUrlTest.php
@@ -5,12 +5,14 @@
5 5
6namespace Shaarli\Http; 6namespace Shaarli\Http;
7 7
8use Shaarli\TestCase;
9
8require_once 'application/http/HttpUtils.php'; 10require_once 'application/http/HttpUtils.php';
9 11
10/** 12/**
11 * Unitary tests for index_url() 13 * Unitary tests for index_url()
12 */ 14 */
13class IndexUrlTest extends \PHPUnit\Framework\TestCase 15class IndexUrlTest extends TestCase
14{ 16{
15 /** 17 /**
16 * If on the main page, remove "index.php" from the URL resource 18 * If on the main page, remove "index.php" from the URL resource
@@ -103,4 +105,36 @@ class IndexUrlTest extends \PHPUnit\Framework\TestCase
103 ) 105 )
104 ); 106 );
105 } 107 }
108
109 /**
110 * The route is stored in REQUEST_URI and subfolder
111 */
112 public function testPageUrlWithRouteUnderSubfolder()
113 {
114 $this->assertEquals(
115 'http://host.tld/subfolder/picture-wall',
116 page_url(
117 array(
118 'HTTPS' => 'Off',
119 'SERVER_NAME' => 'host.tld',
120 'SERVER_PORT' => '80',
121 'SCRIPT_NAME' => '/subfolder/index.php',
122 'REQUEST_URI' => '/subfolder/picture-wall',
123 )
124 )
125 );
126
127 $this->assertEquals(
128 'http://host.tld/subfolder/admin/picture-wall',
129 page_url(
130 array(
131 'HTTPS' => 'Off',
132 'SERVER_NAME' => 'host.tld',
133 'SERVER_PORT' => '80',
134 'SCRIPT_NAME' => '/subfolder/admin/index.php',
135 'REQUEST_URI' => '/subfolder/admin/picture-wall',
136 )
137 )
138 );
139 }
106} 140}
diff --git a/tests/http/HttpUtils/IndexUrlTestWithConstant.php b/tests/http/HttpUtils/IndexUrlTestWithConstant.php
new file mode 100644
index 00000000..ecaea724
--- /dev/null
+++ b/tests/http/HttpUtils/IndexUrlTestWithConstant.php
@@ -0,0 +1,51 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Shaarli\Http;
6
7use Shaarli\TestCase;
8
9/**
10 * Test index_url with SHAARLI_ROOT_URL defined to override automatic retrieval.
11 * This should stay in its dedicated class to make sure to not alter other tests of the suite.
12 */
13class IndexUrlTestWithConstant extends TestCase
14{
15 public static function setUpBeforeClass(): void
16 {
17 define('SHAARLI_ROOT_URL', 'http://other-host.tld/subfolder/');
18 }
19
20 /**
21 * The route is stored in REQUEST_URI and subfolder
22 */
23 public function testIndexUrlWithConstantDefined()
24 {
25 $this->assertEquals(
26 'http://other-host.tld/subfolder/',
27 index_url(
28 array(
29 'HTTPS' => 'Off',
30 'SERVER_NAME' => 'host.tld',
31 'SERVER_PORT' => '80',
32 'SCRIPT_NAME' => '/index.php',
33 'REQUEST_URI' => '/picture-wall',
34 )
35 )
36 );
37
38 $this->assertEquals(
39 'http://other-host.tld/subfolder/',
40 index_url(
41 array(
42 'HTTPS' => 'Off',
43 'SERVER_NAME' => 'host.tld',
44 'SERVER_PORT' => '80',
45 'SCRIPT_NAME' => '/admin/index.php',
46 'REQUEST_URI' => '/admin/picture-wall',
47 )
48 )
49 );
50 }
51}
diff --git a/tests/http/HttpUtils/IsHttpsTest.php b/tests/http/HttpUtils/IsHttpsTest.php
index 348956c6..8b3fd93d 100644
--- a/tests/http/HttpUtils/IsHttpsTest.php
+++ b/tests/http/HttpUtils/IsHttpsTest.php
@@ -9,7 +9,7 @@ require_once 'application/http/HttpUtils.php';
9 * 9 *
10 * Test class for is_https() function. 10 * Test class for is_https() function.
11 */ 11 */
12class IsHttpsTest extends \PHPUnit\Framework\TestCase 12class IsHttpsTest extends \Shaarli\TestCase
13{ 13{
14 14
15 /** 15 /**
diff --git a/tests/http/HttpUtils/PageUrlTest.php b/tests/http/HttpUtils/PageUrlTest.php
index f1991716..ebb3e617 100644
--- a/tests/http/HttpUtils/PageUrlTest.php
+++ b/tests/http/HttpUtils/PageUrlTest.php
@@ -10,7 +10,7 @@ require_once 'application/http/HttpUtils.php';
10/** 10/**
11 * Unitary tests for page_url() 11 * Unitary tests for page_url()
12 */ 12 */
13class PageUrlTest extends \PHPUnit\Framework\TestCase 13class PageUrlTest extends \Shaarli\TestCase
14{ 14{
15 /** 15 /**
16 * If on the main page, remove "index.php" from the URL resource 16 * If on the main page, remove "index.php" from the URL resource
diff --git a/tests/http/HttpUtils/ServerUrlTest.php b/tests/http/HttpUtils/ServerUrlTest.php
index 9caf1049..339664e1 100644
--- a/tests/http/HttpUtils/ServerUrlTest.php
+++ b/tests/http/HttpUtils/ServerUrlTest.php
@@ -10,7 +10,7 @@ require_once 'application/http/HttpUtils.php';
10/** 10/**
11 * Unitary tests for server_url() 11 * Unitary tests for server_url()
12 */ 12 */
13class ServerUrlTest extends \PHPUnit\Framework\TestCase 13class ServerUrlTest extends \Shaarli\TestCase
14{ 14{
15 /** 15 /**
16 * Detect if the server uses SSL 16 * Detect if the server uses SSL
diff --git a/tests/http/UrlTest.php b/tests/http/UrlTest.php
index ae92f73a..c6b39c29 100644
--- a/tests/http/UrlTest.php
+++ b/tests/http/UrlTest.php
@@ -8,7 +8,7 @@ namespace Shaarli\Http;
8/** 8/**
9 * Unitary tests for URL utilities 9 * Unitary tests for URL utilities
10 */ 10 */
11class UrlTest extends \PHPUnit\Framework\TestCase 11class UrlTest extends \Shaarli\TestCase
12{ 12{
13 // base URL for tests 13 // base URL for tests
14 protected static $baseUrl = 'http://domain.tld:3000'; 14 protected static $baseUrl = 'http://domain.tld:3000';
diff --git a/tests/http/UrlUtils/CleanupUrlTest.php b/tests/http/UrlUtils/CleanupUrlTest.php
index 6c4d124b..45690ecf 100644
--- a/tests/http/UrlUtils/CleanupUrlTest.php
+++ b/tests/http/UrlUtils/CleanupUrlTest.php
@@ -7,7 +7,7 @@ namespace Shaarli\Http;
7 7
8require_once 'application/http/UrlUtils.php'; 8require_once 'application/http/UrlUtils.php';
9 9
10class CleanupUrlTest extends \PHPUnit\Framework\TestCase 10class CleanupUrlTest extends \Shaarli\TestCase
11{ 11{
12 /** 12 /**
13 * @var string reference URL 13 * @var string reference URL
diff --git a/tests/http/UrlUtils/GetUrlSchemeTest.php b/tests/http/UrlUtils/GetUrlSchemeTest.php
index 2b97f7be..18a9a5e5 100644
--- a/tests/http/UrlUtils/GetUrlSchemeTest.php
+++ b/tests/http/UrlUtils/GetUrlSchemeTest.php
@@ -7,7 +7,7 @@ namespace Shaarli\Http;
7 7
8require_once 'application/http/UrlUtils.php'; 8require_once 'application/http/UrlUtils.php';
9 9
10class GetUrlSchemeTest extends \PHPUnit\Framework\TestCase 10class GetUrlSchemeTest extends \Shaarli\TestCase
11{ 11{
12 /** 12 /**
13 * Get empty scheme string for empty UrlUtils 13 * Get empty scheme string for empty UrlUtils
diff --git a/tests/http/UrlUtils/UnparseUrlTest.php b/tests/http/UrlUtils/UnparseUrlTest.php
index 040d8c54..5e6246cc 100644
--- a/tests/http/UrlUtils/UnparseUrlTest.php
+++ b/tests/http/UrlUtils/UnparseUrlTest.php
@@ -10,7 +10,7 @@ require_once 'application/http/UrlUtils.php';
10/** 10/**
11 * Unitary tests for unparse_url() 11 * Unitary tests for unparse_url()
12 */ 12 */
13class UnparseUrlTest extends \PHPUnit\Framework\TestCase 13class UnparseUrlTest extends \Shaarli\TestCase
14{ 14{
15 /** 15 /**
16 * Thanks for building nothing 16 * Thanks for building nothing
diff --git a/tests/http/UrlUtils/WhitelistProtocolsTest.php b/tests/http/UrlUtils/WhitelistProtocolsTest.php
index 69512dbd..b8a6baaa 100644
--- a/tests/http/UrlUtils/WhitelistProtocolsTest.php
+++ b/tests/http/UrlUtils/WhitelistProtocolsTest.php
@@ -9,7 +9,7 @@ require_once 'application/http/UrlUtils.php';
9 * 9 *
10 * Test whitelist_protocols() function of UrlUtils. 10 * Test whitelist_protocols() function of UrlUtils.
11 */ 11 */
12class WhitelistProtocolsTest extends \PHPUnit\Framework\TestCase 12class WhitelistProtocolsTest extends \Shaarli\TestCase
13{ 13{
14 /** 14 /**
15 * Test whitelist_protocols() on a note (relative URL). 15 * Test whitelist_protocols() on a note (relative URL).
diff --git a/tests/languages/fr/LanguagesFrTest.php b/tests/languages/fr/LanguagesFrTest.php
index b8b7ca3a..d84feed1 100644
--- a/tests/languages/fr/LanguagesFrTest.php
+++ b/tests/languages/fr/LanguagesFrTest.php
@@ -12,7 +12,7 @@ use Shaarli\Config\ConfigManager;
12 * 12 *
13 * @package Shaarli 13 * @package Shaarli
14 */ 14 */
15class LanguagesFrTest extends \PHPUnit\Framework\TestCase 15class LanguagesFrTest extends \Shaarli\TestCase
16{ 16{
17 /** 17 /**
18 * @var string Config file path (without extension). 18 * @var string Config file path (without extension).
@@ -27,7 +27,7 @@ class LanguagesFrTest extends \PHPUnit\Framework\TestCase
27 /** 27 /**
28 * Init: force French 28 * Init: force French
29 */ 29 */
30 public function setUp() 30 protected function setUp(): void
31 { 31 {
32 $this->conf = new ConfigManager(self::$configFile); 32 $this->conf = new ConfigManager(self::$configFile);
33 $this->conf->set('translation.language', 'fr'); 33 $this->conf->set('translation.language', 'fr');
@@ -36,7 +36,7 @@ class LanguagesFrTest extends \PHPUnit\Framework\TestCase
36 /** 36 /**
37 * Reset the locale since gettext seems to mess with it, making it too long 37 * Reset the locale since gettext seems to mess with it, making it too long
38 */ 38 */
39 public static function tearDownAfterClass() 39 public static function tearDownAfterClass(): void
40 { 40 {
41 if (! empty(getenv('UT_LOCALE'))) { 41 if (! empty(getenv('UT_LOCALE'))) {
42 setlocale(LC_ALL, getenv('UT_LOCALE')); 42 setlocale(LC_ALL, getenv('UT_LOCALE'));
diff --git a/tests/legacy/LegacyControllerTest.php b/tests/legacy/LegacyControllerTest.php
index 759a5b2a..1a2549a3 100644
--- a/tests/legacy/LegacyControllerTest.php
+++ b/tests/legacy/LegacyControllerTest.php
@@ -4,8 +4,8 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Legacy; 5namespace Shaarli\Legacy;
6 6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Front\Controller\Visitor\FrontControllerMockHelper; 7use Shaarli\Front\Controller\Visitor\FrontControllerMockHelper;
8use Shaarli\TestCase;
9use Slim\Http\Request; 9use Slim\Http\Request;
10use Slim\Http\Response; 10use Slim\Http\Response;
11 11
@@ -66,11 +66,11 @@ class LegacyControllerTest extends TestCase
66 { 66 {
67 return [ 67 return [
68 ['post', [], '/admin/shaare', true], 68 ['post', [], '/admin/shaare', true],
69 ['post', [], '/login', false], 69 ['post', [], '/login?returnurl=/subfolder/admin/shaare', false],
70 ['post', ['title' => 'test'], '/admin/shaare?title=test', true], 70 ['post', ['title' => 'test'], '/admin/shaare?title=test', true],
71 ['post', ['title' => 'test'], '/login?title=test', false], 71 ['post', ['title' => 'test'], '/login?returnurl=/subfolder/admin/shaare?title=test', false],
72 ['addlink', [], '/admin/add-shaare', true], 72 ['addlink', [], '/admin/add-shaare', true],
73 ['addlink', [], '/login', false], 73 ['addlink', [], '/login?returnurl=/subfolder/admin/add-shaare', false],
74 ['login', [], '/login', true], 74 ['login', [], '/login', true],
75 ['login', [], '/login', false], 75 ['login', [], '/login', false],
76 ['logout', [], '/admin/logout', true], 76 ['logout', [], '/admin/logout', true],
@@ -94,6 +94,8 @@ class LegacyControllerTest extends TestCase
94 ['opensearch', [], '/open-search', true], 94 ['opensearch', [], '/open-search', true],
95 ['dailyrss', [], '/daily-rss', false], 95 ['dailyrss', [], '/daily-rss', false],
96 ['dailyrss', [], '/daily-rss', true], 96 ['dailyrss', [], '/daily-rss', true],
97 ['configure', [], '/login?returnurl=/subfolder/admin/configure', false],
98 ['configure', [], '/admin/configure', true],
97 ]; 99 ];
98 } 100 }
99} 101}
diff --git a/tests/legacy/LegacyLinkDBTest.php b/tests/legacy/LegacyLinkDBTest.php
index 0884ad03..df2cad62 100644
--- a/tests/legacy/LegacyLinkDBTest.php
+++ b/tests/legacy/LegacyLinkDBTest.php
@@ -18,7 +18,7 @@ require_once 'tests/utils/ReferenceLinkDB.php';
18/** 18/**
19 * Unitary tests for LegacyLinkDBTest 19 * Unitary tests for LegacyLinkDBTest
20 */ 20 */
21class LegacyLinkDBTest extends \PHPUnit\Framework\TestCase 21class LegacyLinkDBTest extends \Shaarli\TestCase
22{ 22{
23 // datastore to test write operations 23 // datastore to test write operations
24 protected static $testDatastore = 'sandbox/datastore.php'; 24 protected static $testDatastore = 'sandbox/datastore.php';
@@ -52,7 +52,7 @@ class LegacyLinkDBTest extends \PHPUnit\Framework\TestCase
52 * 52 *
53 * Resets test data for each test 53 * Resets test data for each test
54 */ 54 */
55 protected function setUp() 55 protected function setUp(): void
56 { 56 {
57 if (file_exists(self::$testDatastore)) { 57 if (file_exists(self::$testDatastore)) {
58 unlink(self::$testDatastore); 58 unlink(self::$testDatastore);
@@ -99,12 +99,12 @@ class LegacyLinkDBTest extends \PHPUnit\Framework\TestCase
99 99
100 /** 100 /**
101 * Attempt to instantiate a LinkDB whereas the datastore is not writable 101 * Attempt to instantiate a LinkDB whereas the datastore is not writable
102 *
103 * @expectedException Shaarli\Exceptions\IOException
104 * @expectedExceptionMessageRegExp /Error accessing "null"/
105 */ 102 */
106 public function testConstructDatastoreNotWriteable() 103 public function testConstructDatastoreNotWriteable()
107 { 104 {
105 $this->expectException(\Shaarli\Exceptions\IOException::class);
106 $this->expectExceptionMessageRegExp('/Error accessing "null"/');
107
108 new LegacyLinkDB('null/store.db', false, false); 108 new LegacyLinkDB('null/store.db', false, false);
109 } 109 }
110 110
@@ -257,7 +257,7 @@ class LegacyLinkDBTest extends \PHPUnit\Framework\TestCase
257 $link = self::$publicLinkDB->getLinkFromUrl('http://mediagoblin.org/'); 257 $link = self::$publicLinkDB->getLinkFromUrl('http://mediagoblin.org/');
258 258
259 $this->assertNotEquals(false, $link); 259 $this->assertNotEquals(false, $link);
260 $this->assertContains( 260 $this->assertContainsPolyfill(
261 'A free software media publishing platform', 261 'A free software media publishing platform',
262 $link['description'] 262 $link['description']
263 ); 263 );
@@ -420,22 +420,22 @@ class LegacyLinkDBTest extends \PHPUnit\Framework\TestCase
420 420
421 /** 421 /**
422 * Test filterHash() with an invalid smallhash. 422 * Test filterHash() with an invalid smallhash.
423 *
424 * @expectedException \Shaarli\Bookmark\Exception\BookmarkNotFoundException
425 */ 423 */
426 public function testFilterHashInValid1() 424 public function testFilterHashInValid1()
427 { 425 {
426 $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class);
427
428 $request = 'blabla'; 428 $request = 'blabla';
429 self::$publicLinkDB->filterHash($request); 429 self::$publicLinkDB->filterHash($request);
430 } 430 }
431 431
432 /** 432 /**
433 * Test filterHash() with an empty smallhash. 433 * Test filterHash() with an empty smallhash.
434 *
435 * @expectedException \Shaarli\Bookmark\Exception\BookmarkNotFoundException
436 */ 434 */
437 public function testFilterHashInValid() 435 public function testFilterHashInValid()
438 { 436 {
437 $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class);
438
439 self::$publicLinkDB->filterHash(''); 439 self::$publicLinkDB->filterHash('');
440 } 440 }
441 441
@@ -470,9 +470,9 @@ class LegacyLinkDBTest extends \PHPUnit\Framework\TestCase
470 470
471 $res = $linkDB->renameTag('cartoon', 'Taz'); 471 $res = $linkDB->renameTag('cartoon', 'Taz');
472 $this->assertEquals(3, count($res)); 472 $this->assertEquals(3, count($res));
473 $this->assertContains(' Taz ', $linkDB[4]['tags']); 473 $this->assertContainsPolyfill(' Taz ', $linkDB[4]['tags']);
474 $this->assertContains(' Taz ', $linkDB[1]['tags']); 474 $this->assertContainsPolyfill(' Taz ', $linkDB[1]['tags']);
475 $this->assertContains(' Taz ', $linkDB[0]['tags']); 475 $this->assertContainsPolyfill(' Taz ', $linkDB[0]['tags']);
476 } 476 }
477 477
478 /** 478 /**
@@ -512,7 +512,7 @@ class LegacyLinkDBTest extends \PHPUnit\Framework\TestCase
512 512
513 $res = $linkDB->renameTag('cartoon', null); 513 $res = $linkDB->renameTag('cartoon', null);
514 $this->assertEquals(3, count($res)); 514 $this->assertEquals(3, count($res));
515 $this->assertNotContains('cartoon', $linkDB[4]['tags']); 515 $this->assertNotContainsPolyfill('cartoon', $linkDB[4]['tags']);
516 } 516 }
517 517
518 /** 518 /**
diff --git a/tests/legacy/LegacyLinkFilterTest.php b/tests/legacy/LegacyLinkFilterTest.php
index ba9ec529..45d7754d 100644
--- a/tests/legacy/LegacyLinkFilterTest.php
+++ b/tests/legacy/LegacyLinkFilterTest.php
@@ -10,7 +10,7 @@ use Shaarli\Legacy\LegacyLinkFilter;
10/** 10/**
11 * Class LegacyLinkFilterTest. 11 * Class LegacyLinkFilterTest.
12 */ 12 */
13class LegacyLinkFilterTest extends \PHPUnit\Framework\TestCase 13class LegacyLinkFilterTest extends \Shaarli\TestCase
14{ 14{
15 /** 15 /**
16 * @var string Test datastore path. 16 * @var string Test datastore path.
@@ -34,7 +34,7 @@ class LegacyLinkFilterTest extends \PHPUnit\Framework\TestCase
34 /** 34 /**
35 * Instantiate linkFilter with ReferenceLinkDB data. 35 * Instantiate linkFilter with ReferenceLinkDB data.
36 */ 36 */
37 public static function setUpBeforeClass() 37 public static function setUpBeforeClass(): void
38 { 38 {
39 self::$refDB = new ReferenceLinkDB(true); 39 self::$refDB = new ReferenceLinkDB(true);
40 self::$refDB->write(self::$testDatastore); 40 self::$refDB->write(self::$testDatastore);
@@ -197,21 +197,23 @@ class LegacyLinkFilterTest extends \PHPUnit\Framework\TestCase
197 197
198 /** 198 /**
199 * Use an invalid date format 199 * Use an invalid date format
200 * @expectedException Exception
201 * @expectedExceptionMessageRegExp /Invalid date format/
202 */ 200 */
203 public function testFilterInvalidDayWithChars() 201 public function testFilterInvalidDayWithChars()
204 { 202 {
203 $this->expectException(\Exception::class);
204 $this->expectExceptionMessageRegExp('/Invalid date format/');
205
205 self::$linkFilter->filter(LegacyLinkFilter::$FILTER_DAY, 'Rainy day, dream away'); 206 self::$linkFilter->filter(LegacyLinkFilter::$FILTER_DAY, 'Rainy day, dream away');
206 } 207 }
207 208
208 /** 209 /**
209 * Use an invalid date format 210 * Use an invalid date format
210 * @expectedException Exception
211 * @expectedExceptionMessageRegExp /Invalid date format/
212 */ 211 */
213 public function testFilterInvalidDayDigits() 212 public function testFilterInvalidDayDigits()
214 { 213 {
214 $this->expectException(\Exception::class);
215 $this->expectExceptionMessageRegExp('/Invalid date format/');
216
215 self::$linkFilter->filter(LegacyLinkFilter::$FILTER_DAY, '20'); 217 self::$linkFilter->filter(LegacyLinkFilter::$FILTER_DAY, '20');
216 } 218 }
217 219
@@ -235,11 +237,11 @@ class LegacyLinkFilterTest extends \PHPUnit\Framework\TestCase
235 237
236 /** 238 /**
237 * No link for this hash 239 * No link for this hash
238 *
239 * @expectedException \Shaarli\Bookmark\Exception\BookmarkNotFoundException
240 */ 240 */
241 public function testFilterUnknownSmallHash() 241 public function testFilterUnknownSmallHash()
242 { 242 {
243 $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class);
244
243 self::$linkFilter->filter(LegacyLinkFilter::$FILTER_HASH, 'Iblaah'); 245 self::$linkFilter->filter(LegacyLinkFilter::$FILTER_HASH, 'Iblaah');
244 } 246 }
245 247
diff --git a/tests/legacy/LegacyRouterTest.php b/tests/legacy/LegacyRouterTest.php
deleted file mode 100644
index c2019ca7..00000000
--- a/tests/legacy/LegacyRouterTest.php
+++ /dev/null
@@ -1,512 +0,0 @@
1<?php
2
3namespace Shaarli\Legacy;
4
5use PHPUnit\Framework\TestCase;
6
7/**
8 * Unit tests for Router
9 */
10class LegacyRouterTest extends TestCase
11{
12 /**
13 * Test findPage: login page output.
14 * Valid: page should be return.
15 *
16 * @return void
17 */
18 public function testFindPageLoginValid()
19 {
20 $this->assertEquals(
21 LegacyRouter::$PAGE_LOGIN,
22 LegacyRouter::findPage('do=login', array(), false)
23 );
24
25 $this->assertEquals(
26 LegacyRouter::$PAGE_LOGIN,
27 LegacyRouter::findPage('do=login', array(), 1)
28 );
29
30 $this->assertEquals(
31 LegacyRouter::$PAGE_LOGIN,
32 LegacyRouter::findPage('do=login&stuff', array(), false)
33 );
34 }
35
36 /**
37 * Test findPage: login page output.
38 * Invalid: page shouldn't be return.
39 *
40 * @return void
41 */
42 public function testFindPageLoginInvalid()
43 {
44 $this->assertNotEquals(
45 LegacyRouter::$PAGE_LOGIN,
46 LegacyRouter::findPage('do=login', array(), true)
47 );
48
49 $this->assertNotEquals(
50 LegacyRouter::$PAGE_LOGIN,
51 LegacyRouter::findPage('do=other', array(), false)
52 );
53 }
54
55 /**
56 * Test findPage: picwall page output.
57 * Valid: page should be return.
58 *
59 * @return void
60 */
61 public function testFindPagePicwallValid()
62 {
63 $this->assertEquals(
64 LegacyRouter::$PAGE_PICWALL,
65 LegacyRouter::findPage('do=picwall', array(), false)
66 );
67
68 $this->assertEquals(
69 LegacyRouter::$PAGE_PICWALL,
70 LegacyRouter::findPage('do=picwall', array(), true)
71 );
72 }
73
74 /**
75 * Test findPage: picwall page output.
76 * Invalid: page shouldn't be return.
77 *
78 * @return void
79 */
80 public function testFindPagePicwallInvalid()
81 {
82 $this->assertEquals(
83 LegacyRouter::$PAGE_PICWALL,
84 LegacyRouter::findPage('do=picwall&stuff', array(), false)
85 );
86
87 $this->assertNotEquals(
88 LegacyRouter::$PAGE_PICWALL,
89 LegacyRouter::findPage('do=other', array(), false)
90 );
91 }
92
93 /**
94 * Test findPage: tagcloud page output.
95 * Valid: page should be return.
96 *
97 * @return void
98 */
99 public function testFindPageTagcloudValid()
100 {
101 $this->assertEquals(
102 LegacyRouter::$PAGE_TAGCLOUD,
103 LegacyRouter::findPage('do=tagcloud', array(), false)
104 );
105
106 $this->assertEquals(
107 LegacyRouter::$PAGE_TAGCLOUD,
108 LegacyRouter::findPage('do=tagcloud', array(), true)
109 );
110
111 $this->assertEquals(
112 LegacyRouter::$PAGE_TAGCLOUD,
113 LegacyRouter::findPage('do=tagcloud&stuff', array(), false)
114 );
115 }
116
117 /**
118 * Test findPage: tagcloud page output.
119 * Invalid: page shouldn't be return.
120 *
121 * @return void
122 */
123 public function testFindPageTagcloudInvalid()
124 {
125 $this->assertNotEquals(
126 LegacyRouter::$PAGE_TAGCLOUD,
127 LegacyRouter::findPage('do=other', array(), false)
128 );
129 }
130
131 /**
132 * Test findPage: linklist page output.
133 * Valid: page should be return.
134 *
135 * @return void
136 */
137 public function testFindPageLinklistValid()
138 {
139 $this->assertEquals(
140 LegacyRouter::$PAGE_LINKLIST,
141 LegacyRouter::findPage('', array(), true)
142 );
143
144 $this->assertEquals(
145 LegacyRouter::$PAGE_LINKLIST,
146 LegacyRouter::findPage('whatever', array(), true)
147 );
148
149 $this->assertEquals(
150 LegacyRouter::$PAGE_LINKLIST,
151 LegacyRouter::findPage('whatever', array(), false)
152 );
153
154 $this->assertEquals(
155 LegacyRouter::$PAGE_LINKLIST,
156 LegacyRouter::findPage('do=tools', array(), false)
157 );
158 }
159
160 /**
161 * Test findPage: tools page output.
162 * Valid: page should be return.
163 *
164 * @return void
165 */
166 public function testFindPageToolsValid()
167 {
168 $this->assertEquals(
169 LegacyRouter::$PAGE_TOOLS,
170 LegacyRouter::findPage('do=tools', array(), true)
171 );
172
173 $this->assertEquals(
174 LegacyRouter::$PAGE_TOOLS,
175 LegacyRouter::findPage('do=tools&stuff', array(), true)
176 );
177 }
178
179 /**
180 * Test findPage: tools page output.
181 * Invalid: page shouldn't be return.
182 *
183 * @return void
184 */
185 public function testFindPageToolsInvalid()
186 {
187 $this->assertNotEquals(
188 LegacyRouter::$PAGE_TOOLS,
189 LegacyRouter::findPage('do=tools', array(), 1)
190 );
191
192 $this->assertNotEquals(
193 LegacyRouter::$PAGE_TOOLS,
194 LegacyRouter::findPage('do=tools', array(), false)
195 );
196
197 $this->assertNotEquals(
198 LegacyRouter::$PAGE_TOOLS,
199 LegacyRouter::findPage('do=other', array(), true)
200 );
201 }
202
203 /**
204 * Test findPage: changepasswd page output.
205 * Valid: page should be return.
206 *
207 * @return void
208 */
209 public function testFindPageChangepasswdValid()
210 {
211 $this->assertEquals(
212 LegacyRouter::$PAGE_CHANGEPASSWORD,
213 LegacyRouter::findPage('do=changepasswd', array(), true)
214 );
215 $this->assertEquals(
216 LegacyRouter::$PAGE_CHANGEPASSWORD,
217 LegacyRouter::findPage('do=changepasswd&stuff', array(), true)
218 );
219 }
220
221 /**
222 * Test findPage: changepasswd page output.
223 * Invalid: page shouldn't be return.
224 *
225 * @return void
226 */
227 public function testFindPageChangepasswdInvalid()
228 {
229 $this->assertNotEquals(
230 LegacyRouter::$PAGE_CHANGEPASSWORD,
231 LegacyRouter::findPage('do=changepasswd', array(), 1)
232 );
233
234 $this->assertNotEquals(
235 LegacyRouter::$PAGE_CHANGEPASSWORD,
236 LegacyRouter::findPage('do=changepasswd', array(), false)
237 );
238
239 $this->assertNotEquals(
240 LegacyRouter::$PAGE_CHANGEPASSWORD,
241 LegacyRouter::findPage('do=other', array(), true)
242 );
243 }
244 /**
245 * Test findPage: configure page output.
246 * Valid: page should be return.
247 *
248 * @return void
249 */
250 public function testFindPageConfigureValid()
251 {
252 $this->assertEquals(
253 LegacyRouter::$PAGE_CONFIGURE,
254 LegacyRouter::findPage('do=configure', array(), true)
255 );
256
257 $this->assertEquals(
258 LegacyRouter::$PAGE_CONFIGURE,
259 LegacyRouter::findPage('do=configure&stuff', array(), true)
260 );
261 }
262
263 /**
264 * Test findPage: configure page output.
265 * Invalid: page shouldn't be return.
266 *
267 * @return void
268 */
269 public function testFindPageConfigureInvalid()
270 {
271 $this->assertNotEquals(
272 LegacyRouter::$PAGE_CONFIGURE,
273 LegacyRouter::findPage('do=configure', array(), 1)
274 );
275
276 $this->assertNotEquals(
277 LegacyRouter::$PAGE_CONFIGURE,
278 LegacyRouter::findPage('do=configure', array(), false)
279 );
280
281 $this->assertNotEquals(
282 LegacyRouter::$PAGE_CONFIGURE,
283 LegacyRouter::findPage('do=other', array(), true)
284 );
285 }
286
287 /**
288 * Test findPage: changetag page output.
289 * Valid: page should be return.
290 *
291 * @return void
292 */
293 public function testFindPageChangetagValid()
294 {
295 $this->assertEquals(
296 LegacyRouter::$PAGE_CHANGETAG,
297 LegacyRouter::findPage('do=changetag', array(), true)
298 );
299
300 $this->assertEquals(
301 LegacyRouter::$PAGE_CHANGETAG,
302 LegacyRouter::findPage('do=changetag&stuff', array(), true)
303 );
304 }
305
306 /**
307 * Test findPage: changetag page output.
308 * Invalid: page shouldn't be return.
309 *
310 * @return void
311 */
312 public function testFindPageChangetagInvalid()
313 {
314 $this->assertNotEquals(
315 LegacyRouter::$PAGE_CHANGETAG,
316 LegacyRouter::findPage('do=changetag', array(), 1)
317 );
318
319 $this->assertNotEquals(
320 LegacyRouter::$PAGE_CHANGETAG,
321 LegacyRouter::findPage('do=changetag', array(), false)
322 );
323
324 $this->assertNotEquals(
325 LegacyRouter::$PAGE_CHANGETAG,
326 LegacyRouter::findPage('do=other', array(), true)
327 );
328 }
329
330 /**
331 * Test findPage: addlink page output.
332 * Valid: page should be return.
333 *
334 * @return void
335 */
336 public function testFindPageAddlinkValid()
337 {
338 $this->assertEquals(
339 LegacyRouter::$PAGE_ADDLINK,
340 LegacyRouter::findPage('do=addlink', array(), true)
341 );
342
343 $this->assertEquals(
344 LegacyRouter::$PAGE_ADDLINK,
345 LegacyRouter::findPage('do=addlink&stuff', array(), true)
346 );
347 }
348
349 /**
350 * Test findPage: addlink page output.
351 * Invalid: page shouldn't be return.
352 *
353 * @return void
354 */
355 public function testFindPageAddlinkInvalid()
356 {
357 $this->assertNotEquals(
358 LegacyRouter::$PAGE_ADDLINK,
359 LegacyRouter::findPage('do=addlink', array(), 1)
360 );
361
362 $this->assertNotEquals(
363 LegacyRouter::$PAGE_ADDLINK,
364 LegacyRouter::findPage('do=addlink', array(), false)
365 );
366
367 $this->assertNotEquals(
368 LegacyRouter::$PAGE_ADDLINK,
369 LegacyRouter::findPage('do=other', array(), true)
370 );
371 }
372
373 /**
374 * Test findPage: export page output.
375 * Valid: page should be return.
376 *
377 * @return void
378 */
379 public function testFindPageExportValid()
380 {
381 $this->assertEquals(
382 LegacyRouter::$PAGE_EXPORT,
383 LegacyRouter::findPage('do=export', array(), true)
384 );
385
386 $this->assertEquals(
387 LegacyRouter::$PAGE_EXPORT,
388 LegacyRouter::findPage('do=export&stuff', array(), true)
389 );
390 }
391
392 /**
393 * Test findPage: export page output.
394 * Invalid: page shouldn't be return.
395 *
396 * @return void
397 */
398 public function testFindPageExportInvalid()
399 {
400 $this->assertNotEquals(
401 LegacyRouter::$PAGE_EXPORT,
402 LegacyRouter::findPage('do=export', array(), 1)
403 );
404
405 $this->assertNotEquals(
406 LegacyRouter::$PAGE_EXPORT,
407 LegacyRouter::findPage('do=export', array(), false)
408 );
409
410 $this->assertNotEquals(
411 LegacyRouter::$PAGE_EXPORT,
412 LegacyRouter::findPage('do=other', array(), true)
413 );
414 }
415
416 /**
417 * Test findPage: import page output.
418 * Valid: page should be return.
419 *
420 * @return void
421 */
422 public function testFindPageImportValid()
423 {
424 $this->assertEquals(
425 LegacyRouter::$PAGE_IMPORT,
426 LegacyRouter::findPage('do=import', array(), true)
427 );
428
429 $this->assertEquals(
430 LegacyRouter::$PAGE_IMPORT,
431 LegacyRouter::findPage('do=import&stuff', array(), true)
432 );
433 }
434
435 /**
436 * Test findPage: import page output.
437 * Invalid: page shouldn't be return.
438 *
439 * @return void
440 */
441 public function testFindPageImportInvalid()
442 {
443 $this->assertNotEquals(
444 LegacyRouter::$PAGE_IMPORT,
445 LegacyRouter::findPage('do=import', array(), 1)
446 );
447
448 $this->assertNotEquals(
449 LegacyRouter::$PAGE_IMPORT,
450 LegacyRouter::findPage('do=import', array(), false)
451 );
452
453 $this->assertNotEquals(
454 LegacyRouter::$PAGE_IMPORT,
455 LegacyRouter::findPage('do=other', array(), true)
456 );
457 }
458
459 /**
460 * Test findPage: editlink page output.
461 * Valid: page should be return.
462 *
463 * @return void
464 */
465 public function testFindPageEditlinkValid()
466 {
467 $this->assertEquals(
468 LegacyRouter::$PAGE_EDITLINK,
469 LegacyRouter::findPage('whatever', array('edit_link' => 1), true)
470 );
471
472 $this->assertEquals(
473 LegacyRouter::$PAGE_EDITLINK,
474 LegacyRouter::findPage('', array('edit_link' => 1), true)
475 );
476
477
478 $this->assertEquals(
479 LegacyRouter::$PAGE_EDITLINK,
480 LegacyRouter::findPage('whatever', array('post' => 1), true)
481 );
482
483 $this->assertEquals(
484 LegacyRouter::$PAGE_EDITLINK,
485 LegacyRouter::findPage('whatever', array('post' => 1, 'edit_link' => 1), true)
486 );
487 }
488
489 /**
490 * Test findPage: editlink page output.
491 * Invalid: page shouldn't be return.
492 *
493 * @return void
494 */
495 public function testFindPageEditlinkInvalid()
496 {
497 $this->assertNotEquals(
498 LegacyRouter::$PAGE_EDITLINK,
499 LegacyRouter::findPage('whatever', array('edit_link' => 1), false)
500 );
501
502 $this->assertNotEquals(
503 LegacyRouter::$PAGE_EDITLINK,
504 LegacyRouter::findPage('whatever', array('edit_link' => 1), 1)
505 );
506
507 $this->assertNotEquals(
508 LegacyRouter::$PAGE_EDITLINK,
509 LegacyRouter::findPage('whatever', array(), true)
510 );
511 }
512}
diff --git a/tests/legacy/LegacyUpdaterTest.php b/tests/legacy/LegacyUpdaterTest.php
index 7c429811..f7391b86 100644
--- a/tests/legacy/LegacyUpdaterTest.php
+++ b/tests/legacy/LegacyUpdaterTest.php
@@ -20,7 +20,7 @@ require_once 'inc/rain.tpl.class.php';
20 * Class UpdaterTest. 20 * Class UpdaterTest.
21 * Runs unit tests against the updater class. 21 * Runs unit tests against the updater class.
22 */ 22 */
23class LegacyUpdaterTest extends \PHPUnit\Framework\TestCase 23class LegacyUpdaterTest extends \Shaarli\TestCase
24{ 24{
25 /** 25 /**
26 * @var string Path to test datastore. 26 * @var string Path to test datastore.
@@ -40,7 +40,7 @@ class LegacyUpdaterTest extends \PHPUnit\Framework\TestCase
40 /** 40 /**
41 * Executed before each test. 41 * Executed before each test.
42 */ 42 */
43 public function setUp() 43 protected function setUp(): void
44 { 44 {
45 copy('tests/utils/config/configJson.json.php', self::$configFile .'.json.php'); 45 copy('tests/utils/config/configJson.json.php', self::$configFile .'.json.php');
46 $this->conf = new ConfigManager(self::$configFile); 46 $this->conf = new ConfigManager(self::$configFile);
@@ -80,23 +80,23 @@ class LegacyUpdaterTest extends \PHPUnit\Framework\TestCase
80 80
81 /** 81 /**
82 * Test errors in UpdaterUtils::write_updates_file(): empty updates file. 82 * Test errors in UpdaterUtils::write_updates_file(): empty updates file.
83 *
84 * @expectedException Exception
85 * @expectedExceptionMessageRegExp /Updates file path is not set(.*)/
86 */ 83 */
87 public function testWriteEmptyUpdatesFile() 84 public function testWriteEmptyUpdatesFile()
88 { 85 {
86 $this->expectException(\Exception::class);
87 $this->expectExceptionMessageRegExp('/Updates file path is not set(.*)/');
88
89 UpdaterUtils::write_updates_file('', array('test')); 89 UpdaterUtils::write_updates_file('', array('test'));
90 } 90 }
91 91
92 /** 92 /**
93 * Test errors in UpdaterUtils::write_updates_file(): not writable updates file. 93 * Test errors in UpdaterUtils::write_updates_file(): not writable updates file.
94 *
95 * @expectedException Exception
96 * @expectedExceptionMessageRegExp /Unable to write(.*)/
97 */ 94 */
98 public function testWriteUpdatesFileNotWritable() 95 public function testWriteUpdatesFileNotWritable()
99 { 96 {
97 $this->expectException(\Exception::class);
98 $this->expectExceptionMessageRegExp('/Unable to write(.*)/');
99
100 $updatesFile = $this->conf->get('resource.data_dir') . '/updates.txt'; 100 $updatesFile = $this->conf->get('resource.data_dir') . '/updates.txt';
101 touch($updatesFile); 101 touch($updatesFile);
102 chmod($updatesFile, 0444); 102 chmod($updatesFile, 0444);
@@ -161,11 +161,11 @@ class LegacyUpdaterTest extends \PHPUnit\Framework\TestCase
161 161
162 /** 162 /**
163 * Test Update failed. 163 * Test Update failed.
164 *
165 * @expectedException \Exception
166 */ 164 */
167 public function testUpdateFailed() 165 public function testUpdateFailed()
168 { 166 {
167 $this->expectException(\Exception::class);
168
169 $updates = array( 169 $updates = array(
170 'updateMethodDummy1', 170 'updateMethodDummy1',
171 'updateMethodDummy2', 171 'updateMethodDummy2',
@@ -723,7 +723,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
723 $this->assertEquals(\Shaarli\Thumbnailer::MODE_ALL, $this->conf->get('thumbnails.mode')); 723 $this->assertEquals(\Shaarli\Thumbnailer::MODE_ALL, $this->conf->get('thumbnails.mode'));
724 $this->assertEquals(125, $this->conf->get('thumbnails.width')); 724 $this->assertEquals(125, $this->conf->get('thumbnails.width'));
725 $this->assertEquals(90, $this->conf->get('thumbnails.height')); 725 $this->assertEquals(90, $this->conf->get('thumbnails.height'));
726 $this->assertContains('You have enabled or changed thumbnails', $_SESSION['warnings'][0]); 726 $this->assertContainsPolyfill('You have enabled or changed thumbnails', $_SESSION['warnings'][0]);
727 } 727 }
728 728
729 /** 729 /**
@@ -754,7 +754,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
754 if (isset($_SESSION['warnings'])) { 754 if (isset($_SESSION['warnings'])) {
755 unset($_SESSION['warnings']); 755 unset($_SESSION['warnings']);
756 } 756 }
757 757
758 $updater = new LegacyUpdater([], [], $this->conf, true, $_SESSION); 758 $updater = new LegacyUpdater([], [], $this->conf, true, $_SESSION);
759 $this->assertTrue($updater->updateMethodWebThumbnailer()); 759 $this->assertTrue($updater->updateMethodWebThumbnailer());
760 $this->assertFalse($this->conf->exists('thumbnail')); 760 $this->assertFalse($this->conf->exists('thumbnail'));
diff --git a/tests/netscape/BookmarkExportTest.php b/tests/netscape/BookmarkExportTest.php
index 509da51d..9b95ccc9 100644
--- a/tests/netscape/BookmarkExportTest.php
+++ b/tests/netscape/BookmarkExportTest.php
@@ -2,12 +2,12 @@
2 2
3namespace Shaarli\Netscape; 3namespace Shaarli\Netscape;
4 4
5use PHPUnit\Framework\TestCase;
6use Shaarli\Bookmark\BookmarkFileService; 5use Shaarli\Bookmark\BookmarkFileService;
7use Shaarli\Config\ConfigManager; 6use Shaarli\Config\ConfigManager;
8use Shaarli\Formatter\BookmarkFormatter; 7use Shaarli\Formatter\BookmarkFormatter;
9use Shaarli\Formatter\FormatterFactory; 8use Shaarli\Formatter\FormatterFactory;
10use Shaarli\History; 9use Shaarli\History;
10use Shaarli\TestCase;
11 11
12require_once 'tests/utils/ReferenceLinkDB.php'; 12require_once 'tests/utils/ReferenceLinkDB.php';
13 13
@@ -54,7 +54,7 @@ class BookmarkExportTest extends TestCase
54 /** 54 /**
55 * Instantiate reference data 55 * Instantiate reference data
56 */ 56 */
57 public static function setUpBeforeClass() 57 public static function setUpBeforeClass(): void
58 { 58 {
59 static::$conf = new ConfigManager('tests/utils/config/configJson'); 59 static::$conf = new ConfigManager('tests/utils/config/configJson');
60 static::$conf->set('resource.datastore', static::$testDatastore); 60 static::$conf->set('resource.datastore', static::$testDatastore);
@@ -77,11 +77,12 @@ class BookmarkExportTest extends TestCase
77 77
78 /** 78 /**
79 * Attempt to export an invalid link selection 79 * Attempt to export an invalid link selection
80 * @expectedException Exception
81 * @expectedExceptionMessageRegExp /Invalid export selection/
82 */ 80 */
83 public function testFilterAndFormatInvalid() 81 public function testFilterAndFormatInvalid()
84 { 82 {
83 $this->expectException(\Exception::class);
84 $this->expectExceptionMessageRegExp('/Invalid export selection/');
85
85 $this->netscapeBookmarkUtils->filterAndFormat( 86 $this->netscapeBookmarkUtils->filterAndFormat(
86 self::$formatter, 87 self::$formatter,
87 'derp', 88 'derp',
diff --git a/tests/netscape/BookmarkImportTest.php b/tests/netscape/BookmarkImportTest.php
index f678e26b..c1e49b5f 100644
--- a/tests/netscape/BookmarkImportTest.php
+++ b/tests/netscape/BookmarkImportTest.php
@@ -3,13 +3,13 @@
3namespace Shaarli\Netscape; 3namespace Shaarli\Netscape;
4 4
5use DateTime; 5use DateTime;
6use PHPUnit\Framework\TestCase;
7use Psr\Http\Message\UploadedFileInterface; 6use Psr\Http\Message\UploadedFileInterface;
8use Shaarli\Bookmark\Bookmark; 7use Shaarli\Bookmark\Bookmark;
9use Shaarli\Bookmark\BookmarkFileService; 8use Shaarli\Bookmark\BookmarkFileService;
10use Shaarli\Bookmark\BookmarkFilter; 9use Shaarli\Bookmark\BookmarkFilter;
11use Shaarli\Config\ConfigManager; 10use Shaarli\Config\ConfigManager;
12use Shaarli\History; 11use Shaarli\History;
12use Shaarli\TestCase;
13use Slim\Http\UploadedFile; 13use Slim\Http\UploadedFile;
14 14
15/** 15/**
@@ -75,7 +75,7 @@ class BookmarkImportTest extends TestCase
75 */ 75 */
76 protected static $defaultTimeZone; 76 protected static $defaultTimeZone;
77 77
78 public static function setUpBeforeClass() 78 public static function setUpBeforeClass(): void
79 { 79 {
80 self::$defaultTimeZone = date_default_timezone_get(); 80 self::$defaultTimeZone = date_default_timezone_get();
81 // Timezone without DST for test consistency 81 // Timezone without DST for test consistency
@@ -85,7 +85,7 @@ class BookmarkImportTest extends TestCase
85 /** 85 /**
86 * Resets test data before each test 86 * Resets test data before each test
87 */ 87 */
88 protected function setUp() 88 protected function setUp(): void
89 { 89 {
90 if (file_exists(self::$testDatastore)) { 90 if (file_exists(self::$testDatastore)) {
91 unlink(self::$testDatastore); 91 unlink(self::$testDatastore);
@@ -104,12 +104,12 @@ class BookmarkImportTest extends TestCase
104 /** 104 /**
105 * Delete history file. 105 * Delete history file.
106 */ 106 */
107 public function tearDown() 107 protected function tearDown(): void
108 { 108 {
109 @unlink(self::$historyFilePath); 109 @unlink(self::$historyFilePath);
110 } 110 }
111 111
112 public static function tearDownAfterClass() 112 public static function tearDownAfterClass(): void
113 { 113 {
114 date_default_timezone_set(self::$defaultTimeZone); 114 date_default_timezone_set(self::$defaultTimeZone);
115 } 115 }
diff --git a/tests/plugins/PluginAddlinkTest.php b/tests/plugins/PluginAddlinkTest.php
index aa5c6988..a3ec9fc9 100644
--- a/tests/plugins/PluginAddlinkTest.php
+++ b/tests/plugins/PluginAddlinkTest.php
@@ -9,12 +9,12 @@ require_once 'plugins/addlink_toolbar/addlink_toolbar.php';
9/** 9/**
10 * Unit test for the Addlink toolbar plugin 10 * Unit test for the Addlink toolbar plugin
11 */ 11 */
12class PluginAddlinkTest extends \PHPUnit\Framework\TestCase 12class PluginAddlinkTest extends \Shaarli\TestCase
13{ 13{
14 /** 14 /**
15 * Reset plugin path. 15 * Reset plugin path.
16 */ 16 */
17 public function setUp() 17 protected function setUp(): void
18 { 18 {
19 PluginManager::$PLUGINS_PATH = 'plugins'; 19 PluginManager::$PLUGINS_PATH = 'plugins';
20 } 20 }
diff --git a/tests/plugins/PluginArchiveorgTest.php b/tests/plugins/PluginArchiveorgTest.php
index b9a67adb..467dc3d0 100644
--- a/tests/plugins/PluginArchiveorgTest.php
+++ b/tests/plugins/PluginArchiveorgTest.php
@@ -1,4 +1,5 @@
1<?php 1<?php
2
2namespace Shaarli\Plugin\Archiveorg; 3namespace Shaarli\Plugin\Archiveorg;
3 4
4/** 5/**
@@ -6,6 +7,7 @@ namespace Shaarli\Plugin\Archiveorg;
6 */ 7 */
7 8
8use Shaarli\Plugin\PluginManager; 9use Shaarli\Plugin\PluginManager;
10use Shaarli\TestCase;
9 11
10require_once 'plugins/archiveorg/archiveorg.php'; 12require_once 'plugins/archiveorg/archiveorg.php';
11 13
@@ -13,20 +15,35 @@ require_once 'plugins/archiveorg/archiveorg.php';
13 * Class PluginArchiveorgTest 15 * Class PluginArchiveorgTest
14 * Unit test for the archiveorg plugin 16 * Unit test for the archiveorg plugin
15 */ 17 */
16class PluginArchiveorgTest extends \PHPUnit\Framework\TestCase 18class PluginArchiveorgTest extends TestCase
17{ 19{
20 protected $savedScriptName;
21
18 /** 22 /**
19 * Reset plugin path 23 * Reset plugin path
20 */ 24 */
21 public function setUp() 25 public function setUp(): void
22 { 26 {
23 PluginManager::$PLUGINS_PATH = 'plugins'; 27 PluginManager::$PLUGINS_PATH = 'plugins';
28
29 // plugins manipulate global vars
30 $_SERVER['SERVER_PORT'] = '80';
31 $_SERVER['SERVER_NAME'] = 'shaarli.shaarli';
32 $this->savedScriptName = $_SERVER['SCRIPT_NAME'] ?? null;
33 $_SERVER['SCRIPT_NAME'] = '/index.php';
34 }
35
36 public function tearDown(): void
37 {
38 unset($_SERVER['SERVER_PORT']);
39 unset($_SERVER['SERVER_NAME']);
40 $_SERVER['SCRIPT_NAME'] = $this->savedScriptName;
24 } 41 }
25 42
26 /** 43 /**
27 * Test render_linklist hook on external bookmarks. 44 * Test render_linklist hook on external bookmarks.
28 */ 45 */
29 public function testArchiveorgLinklistOnExternalLinks() 46 public function testArchiveorgLinklistOnExternalLinks(): void
30 { 47 {
31 $str = 'http://randomstr.com/test'; 48 $str = 'http://randomstr.com/test';
32 49
@@ -56,16 +73,16 @@ class PluginArchiveorgTest extends \PHPUnit\Framework\TestCase
56 /** 73 /**
57 * Test render_linklist hook on internal bookmarks. 74 * Test render_linklist hook on internal bookmarks.
58 */ 75 */
59 public function testArchiveorgLinklistOnInternalLinks() 76 public function testArchiveorgLinklistOnInternalLinks(): void
60 { 77 {
61 $internalLink1 = 'http://shaarli.shaarli/?qvMAqg'; 78 $internalLink1 = 'http://shaarli.shaarli/shaare/qvMAqg';
62 $internalLinkRealURL1 = '?qvMAqg'; 79 $internalLinkRealURL1 = '/shaare/qvMAqg';
63 80
64 $internalLink2 = 'http://shaarli.shaarli/?2_7zww'; 81 $internalLink2 = 'http://shaarli.shaarli/shaare/2_7zww';
65 $internalLinkRealURL2 = '?2_7zww'; 82 $internalLinkRealURL2 = '/shaare/2_7zww';
66 83
67 $internalLink3 = 'http://shaarli.shaarli/?z7u-_Q'; 84 $internalLink3 = 'http://shaarli.shaarli/shaare/z7u-_Q';
68 $internalLinkRealURL3 = '?z7u-_Q'; 85 $internalLinkRealURL3 = '/shaare/z7u-_Q';
69 86
70 $data = array( 87 $data = array(
71 'title' => $internalLink1, 88 'title' => $internalLink1,
diff --git a/tests/plugins/PluginDefaultColorsTest.php b/tests/plugins/PluginDefaultColorsTest.php
index b9951cca..cc844c60 100644
--- a/tests/plugins/PluginDefaultColorsTest.php
+++ b/tests/plugins/PluginDefaultColorsTest.php
@@ -2,11 +2,10 @@
2 2
3namespace Shaarli\Plugin\DefaultColors; 3namespace Shaarli\Plugin\DefaultColors;
4 4
5use DateTime;
6use PHPUnit\Framework\TestCase;
7use Shaarli\Bookmark\LinkDB; 5use Shaarli\Bookmark\LinkDB;
8use Shaarli\Config\ConfigManager; 6use Shaarli\Config\ConfigManager;
9use Shaarli\Plugin\PluginManager; 7use Shaarli\Plugin\PluginManager;
8use Shaarli\TestCase;
10 9
11require_once 'plugins/default_colors/default_colors.php'; 10require_once 'plugins/default_colors/default_colors.php';
12 11
@@ -20,7 +19,7 @@ class PluginDefaultColorsTest extends TestCase
20 /** 19 /**
21 * Reset plugin path 20 * Reset plugin path
22 */ 21 */
23 public function setUp() 22 protected function setUp(): void
24 { 23 {
25 PluginManager::$PLUGINS_PATH = 'sandbox'; 24 PluginManager::$PLUGINS_PATH = 'sandbox';
26 mkdir(PluginManager::$PLUGINS_PATH . '/default_colors/'); 25 mkdir(PluginManager::$PLUGINS_PATH . '/default_colors/');
@@ -33,7 +32,7 @@ class PluginDefaultColorsTest extends TestCase
33 /** 32 /**
34 * Remove sandbox files and folder 33 * Remove sandbox files and folder
35 */ 34 */
36 public function tearDown() 35 protected function tearDown(): void
37 { 36 {
38 if (file_exists('sandbox/default_colors/default_colors.css.template')) { 37 if (file_exists('sandbox/default_colors/default_colors.css.template')) {
39 unlink('sandbox/default_colors/default_colors.css.template'); 38 unlink('sandbox/default_colors/default_colors.css.template');
@@ -57,6 +56,8 @@ class PluginDefaultColorsTest extends TestCase
57 $conf->set('plugins.DEFAULT_COLORS_BACKGROUND', 'value'); 56 $conf->set('plugins.DEFAULT_COLORS_BACKGROUND', 'value');
58 $errors = default_colors_init($conf); 57 $errors = default_colors_init($conf);
59 $this->assertEmpty($errors); 58 $this->assertEmpty($errors);
59
60 $this->assertFileExists($file = 'sandbox/default_colors/default_colors.css');
60 } 61 }
61 62
62 /** 63 /**
@@ -72,9 +73,9 @@ class PluginDefaultColorsTest extends TestCase
72 /** 73 /**
73 * Test the save plugin parameters hook with all colors specified. 74 * Test the save plugin parameters hook with all colors specified.
74 */ 75 */
75 public function testSavePluginParametersAll() 76 public function testGenerateCssFile()
76 { 77 {
77 $post = [ 78 $params = [
78 'other1' => true, 79 'other1' => true,
79 'DEFAULT_COLORS_MAIN' => 'blue', 80 'DEFAULT_COLORS_MAIN' => 'blue',
80 'DEFAULT_COLORS_BACKGROUND' => 'pink', 81 'DEFAULT_COLORS_BACKGROUND' => 'pink',
@@ -82,7 +83,7 @@ class PluginDefaultColorsTest extends TestCase
82 'DEFAULT_COLORS_DARK_MAIN' => 'green', 83 'DEFAULT_COLORS_DARK_MAIN' => 'green',
83 ]; 84 ];
84 85
85 hook_default_colors_save_plugin_parameters($post); 86 default_colors_generate_css_file($params);
86 $this->assertFileExists($file = 'sandbox/default_colors/default_colors.css'); 87 $this->assertFileExists($file = 'sandbox/default_colors/default_colors.css');
87 $content = file_get_contents($file); 88 $content = file_get_contents($file);
88 $expected = ':root { 89 $expected = ':root {
@@ -98,16 +99,16 @@ class PluginDefaultColorsTest extends TestCase
98 /** 99 /**
99 * Test the save plugin parameters hook with only one color specified. 100 * Test the save plugin parameters hook with only one color specified.
100 */ 101 */
101 public function testSavePluginParametersSingle() 102 public function testGenerateCssFileSingle()
102 { 103 {
103 $post = [ 104 $params = [
104 'other1' => true, 105 'other1' => true,
105 'DEFAULT_COLORS_BACKGROUND' => 'pink', 106 'DEFAULT_COLORS_BACKGROUND' => 'pink',
106 'other2' => ['yep'], 107 'other2' => ['yep'],
107 'DEFAULT_COLORS_DARK_MAIN' => '', 108 'DEFAULT_COLORS_DARK_MAIN' => '',
108 ]; 109 ];
109 110
110 hook_default_colors_save_plugin_parameters($post); 111 default_colors_generate_css_file($params);
111 $this->assertFileExists($file = 'sandbox/default_colors/default_colors.css'); 112 $this->assertFileExists($file = 'sandbox/default_colors/default_colors.css');
112 $content = file_get_contents($file); 113 $content = file_get_contents($file);
113 $expected = ':root { 114 $expected = ':root {
@@ -121,9 +122,9 @@ class PluginDefaultColorsTest extends TestCase
121 /** 122 /**
122 * Test the save plugin parameters hook with no color specified. 123 * Test the save plugin parameters hook with no color specified.
123 */ 124 */
124 public function testSavePluginParametersNone() 125 public function testGenerateCssFileNone()
125 { 126 {
126 hook_default_colors_save_plugin_parameters([]); 127 default_colors_generate_css_file([]);
127 $this->assertFileNotExists($file = 'sandbox/default_colors/default_colors.css'); 128 $this->assertFileNotExists($file = 'sandbox/default_colors/default_colors.css');
128 } 129 }
129 130
diff --git a/tests/plugins/PluginIssoTest.php b/tests/plugins/PluginIssoTest.php
index 99477205..16ecf357 100644
--- a/tests/plugins/PluginIssoTest.php
+++ b/tests/plugins/PluginIssoTest.php
@@ -5,6 +5,7 @@ use DateTime;
5use Shaarli\Bookmark\Bookmark; 5use Shaarli\Bookmark\Bookmark;
6use Shaarli\Config\ConfigManager; 6use Shaarli\Config\ConfigManager;
7use Shaarli\Plugin\PluginManager; 7use Shaarli\Plugin\PluginManager;
8use Shaarli\TestCase;
8 9
9require_once 'plugins/isso/isso.php'; 10require_once 'plugins/isso/isso.php';
10 11
@@ -13,12 +14,12 @@ require_once 'plugins/isso/isso.php';
13 * 14 *
14 * Test the Isso plugin (comment system). 15 * Test the Isso plugin (comment system).
15 */ 16 */
16class PluginIssoTest extends \PHPUnit\Framework\TestCase 17class PluginIssoTest extends TestCase
17{ 18{
18 /** 19 /**
19 * Reset plugin path 20 * Reset plugin path
20 */ 21 */
21 public function setUp() 22 public function setUp(): void
22 { 23 {
23 PluginManager::$PLUGINS_PATH = 'plugins'; 24 PluginManager::$PLUGINS_PATH = 'plugins';
24 } 25 }
@@ -26,7 +27,7 @@ class PluginIssoTest extends \PHPUnit\Framework\TestCase
26 /** 27 /**
27 * Test Isso init without errors. 28 * Test Isso init without errors.
28 */ 29 */
29 public function testIssoInitNoError() 30 public function testIssoInitNoError(): void
30 { 31 {
31 $conf = new ConfigManager(''); 32 $conf = new ConfigManager('');
32 $conf->set('plugins.ISSO_SERVER', 'value'); 33 $conf->set('plugins.ISSO_SERVER', 'value');
@@ -37,7 +38,7 @@ class PluginIssoTest extends \PHPUnit\Framework\TestCase
37 /** 38 /**
38 * Test Isso init with errors. 39 * Test Isso init with errors.
39 */ 40 */
40 public function testIssoInitError() 41 public function testIssoInitError(): void
41 { 42 {
42 $conf = new ConfigManager(''); 43 $conf = new ConfigManager('');
43 $errors = isso_init($conf); 44 $errors = isso_init($conf);
@@ -47,7 +48,7 @@ class PluginIssoTest extends \PHPUnit\Framework\TestCase
47 /** 48 /**
48 * Test render_linklist hook with valid settings to display the comment form. 49 * Test render_linklist hook with valid settings to display the comment form.
49 */ 50 */
50 public function testIssoDisplayed() 51 public function testIssoDisplayed(): void
51 { 52 {
52 $conf = new ConfigManager(''); 53 $conf = new ConfigManager('');
53 $conf->set('plugins.ISSO_SERVER', 'value'); 54 $conf->set('plugins.ISSO_SERVER', 'value');
@@ -87,7 +88,7 @@ class PluginIssoTest extends \PHPUnit\Framework\TestCase
87 /** 88 /**
88 * Test isso plugin when multiple bookmarks are displayed (shouldn't be displayed). 89 * Test isso plugin when multiple bookmarks are displayed (shouldn't be displayed).
89 */ 90 */
90 public function testIssoMultipleLinks() 91 public function testIssoMultipleLinks(): void
91 { 92 {
92 $conf = new ConfigManager(''); 93 $conf = new ConfigManager('');
93 $conf->set('plugins.ISSO_SERVER', 'value'); 94 $conf->set('plugins.ISSO_SERVER', 'value');
@@ -115,14 +116,14 @@ class PluginIssoTest extends \PHPUnit\Framework\TestCase
115 116
116 $processed = hook_isso_render_linklist($data, $conf); 117 $processed = hook_isso_render_linklist($data, $conf);
117 // link_plugin should be added for the icon 118 // link_plugin should be added for the icon
118 $this->assertContains('<a href="?'. $short1 .'#isso-thread">', $processed['links'][0]['link_plugin'][0]); 119 $this->assertContainsPolyfill('<a href="/shaare/'. $short1 .'#isso-thread">', $processed['links'][0]['link_plugin'][0]);
119 $this->assertContains('<a href="?'. $short2 .'#isso-thread">', $processed['links'][1]['link_plugin'][0]); 120 $this->assertContainsPolyfill('<a href="/shaare/'. $short2 .'#isso-thread">', $processed['links'][1]['link_plugin'][0]);
120 } 121 }
121 122
122 /** 123 /**
123 * Test isso plugin when using search (shouldn't be displayed). 124 * Test isso plugin when using search (shouldn't be displayed).
124 */ 125 */
125 public function testIssoNotDisplayedWhenSearch() 126 public function testIssoNotDisplayedWhenSearch(): void
126 { 127 {
127 $conf = new ConfigManager(''); 128 $conf = new ConfigManager('');
128 $conf->set('plugins.ISSO_SERVER', 'value'); 129 $conf->set('plugins.ISSO_SERVER', 'value');
@@ -145,13 +146,13 @@ class PluginIssoTest extends \PHPUnit\Framework\TestCase
145 $processed = hook_isso_render_linklist($data, $conf); 146 $processed = hook_isso_render_linklist($data, $conf);
146 147
147 // link_plugin should be added for the icon 148 // link_plugin should be added for the icon
148 $this->assertContains('<a href="?'. $short1 .'#isso-thread">', $processed['links'][0]['link_plugin'][0]); 149 $this->assertContainsPolyfill('<a href="/shaare/'. $short1 .'#isso-thread">', $processed['links'][0]['link_plugin'][0]);
149 } 150 }
150 151
151 /** 152 /**
152 * Test isso plugin without server configuration (shouldn't be displayed). 153 * Test isso plugin without server configuration (shouldn't be displayed).
153 */ 154 */
154 public function testIssoWithoutConf() 155 public function testIssoWithoutConf(): void
155 { 156 {
156 $data = 'abc'; 157 $data = 'abc';
157 $conf = new ConfigManager(''); 158 $conf = new ConfigManager('');
diff --git a/tests/plugins/PluginPlayvideosTest.php b/tests/plugins/PluginPlayvideosTest.php
index b7b6ce53..338d2e35 100644
--- a/tests/plugins/PluginPlayvideosTest.php
+++ b/tests/plugins/PluginPlayvideosTest.php
@@ -14,12 +14,12 @@ require_once 'plugins/playvideos/playvideos.php';
14 * Class PluginPlayvideosTest 14 * Class PluginPlayvideosTest
15 * Unit test for the PlayVideos plugin 15 * Unit test for the PlayVideos plugin
16 */ 16 */
17class PluginPlayvideosTest extends \PHPUnit\Framework\TestCase 17class PluginPlayvideosTest extends \Shaarli\TestCase
18{ 18{
19 /** 19 /**
20 * Reset plugin path 20 * Reset plugin path
21 */ 21 */
22 public function setUp() 22 protected function setUp(): void
23 { 23 {
24 PluginManager::$PLUGINS_PATH = 'plugins'; 24 PluginManager::$PLUGINS_PATH = 'plugins';
25 } 25 }
diff --git a/tests/plugins/PluginPubsubhubbubTest.php b/tests/plugins/PluginPubsubhubbubTest.php
index e66f484e..d3f7b439 100644
--- a/tests/plugins/PluginPubsubhubbubTest.php
+++ b/tests/plugins/PluginPubsubhubbubTest.php
@@ -11,7 +11,7 @@ require_once 'plugins/pubsubhubbub/pubsubhubbub.php';
11 * Class PluginPubsubhubbubTest 11 * Class PluginPubsubhubbubTest
12 * Unit test for the pubsubhubbub plugin 12 * Unit test for the pubsubhubbub plugin
13 */ 13 */
14class PluginPubsubhubbubTest extends \PHPUnit\Framework\TestCase 14class PluginPubsubhubbubTest extends \Shaarli\TestCase
15{ 15{
16 /** 16 /**
17 * @var string Config file path (without extension). 17 * @var string Config file path (without extension).
@@ -21,7 +21,7 @@ class PluginPubsubhubbubTest extends \PHPUnit\Framework\TestCase
21 /** 21 /**
22 * Reset plugin path 22 * Reset plugin path
23 */ 23 */
24 public function setUp() 24 protected function setUp(): void
25 { 25 {
26 PluginManager::$PLUGINS_PATH = 'plugins'; 26 PluginManager::$PLUGINS_PATH = 'plugins';
27 } 27 }
diff --git a/tests/plugins/PluginQrcodeTest.php b/tests/plugins/PluginQrcodeTest.php
index c9f8c733..1d85fba6 100644
--- a/tests/plugins/PluginQrcodeTest.php
+++ b/tests/plugins/PluginQrcodeTest.php
@@ -14,12 +14,12 @@ require_once 'plugins/qrcode/qrcode.php';
14 * Class PluginQrcodeTest 14 * Class PluginQrcodeTest
15 * Unit test for the QR-Code plugin 15 * Unit test for the QR-Code plugin
16 */ 16 */
17class PluginQrcodeTest extends \PHPUnit\Framework\TestCase 17class PluginQrcodeTest extends \Shaarli\TestCase
18{ 18{
19 /** 19 /**
20 * Reset plugin path 20 * Reset plugin path
21 */ 21 */
22 public function setUp() 22 protected function setUp(): void
23 { 23 {
24 PluginManager::$PLUGINS_PATH = 'plugins'; 24 PluginManager::$PLUGINS_PATH = 'plugins';
25 } 25 }
diff --git a/tests/plugins/PluginWallabagTest.php b/tests/plugins/PluginWallabagTest.php
index 79751921..36317215 100644
--- a/tests/plugins/PluginWallabagTest.php
+++ b/tests/plugins/PluginWallabagTest.php
@@ -10,12 +10,12 @@ require_once 'plugins/wallabag/wallabag.php';
10 * Class PluginWallabagTest 10 * Class PluginWallabagTest
11 * Unit test for the Wallabag plugin 11 * Unit test for the Wallabag plugin
12 */ 12 */
13class PluginWallabagTest extends \PHPUnit\Framework\TestCase 13class PluginWallabagTest extends \Shaarli\TestCase
14{ 14{
15 /** 15 /**
16 * Reset plugin path 16 * Reset plugin path
17 */ 17 */
18 public function setUp() 18 protected function setUp(): void
19 { 19 {
20 PluginManager::$PLUGINS_PATH = 'plugins'; 20 PluginManager::$PLUGINS_PATH = 'plugins';
21 } 21 }
diff --git a/tests/plugins/WallabagInstanceTest.php b/tests/plugins/WallabagInstanceTest.php
index a3cd9076..5ef3de1a 100644
--- a/tests/plugins/WallabagInstanceTest.php
+++ b/tests/plugins/WallabagInstanceTest.php
@@ -4,7 +4,7 @@ namespace Shaarli\Plugin\Wallabag;
4/** 4/**
5 * Class WallabagInstanceTest 5 * Class WallabagInstanceTest
6 */ 6 */
7class WallabagInstanceTest extends \PHPUnit\Framework\TestCase 7class WallabagInstanceTest extends \Shaarli\TestCase
8{ 8{
9 /** 9 /**
10 * @var string wallabag url. 10 * @var string wallabag url.
@@ -14,7 +14,7 @@ class WallabagInstanceTest extends \PHPUnit\Framework\TestCase
14 /** 14 /**
15 * Reset plugin path 15 * Reset plugin path
16 */ 16 */
17 public function setUp() 17 protected function setUp(): void
18 { 18 {
19 $this->instance = 'http://some.url'; 19 $this->instance = 'http://some.url';
20 } 20 }
diff --git a/tests/plugins/test/test.php b/tests/plugins/test/test.php
index ae5032dd..03be4f4e 100644
--- a/tests/plugins/test/test.php
+++ b/tests/plugins/test/test.php
@@ -13,6 +13,9 @@ function hook_test_random($data)
13 $data[1] = 'page test'; 13 $data[1] = 'page test';
14 } elseif (isset($data['_LOGGEDIN_']) && $data['_LOGGEDIN_'] === true) { 14 } elseif (isset($data['_LOGGEDIN_']) && $data['_LOGGEDIN_'] === true) {
15 $data[1] = 'loggedin'; 15 $data[1] = 'loggedin';
16 } elseif (array_key_exists('_LOGGEDIN_', $data)) {
17 $data[1] = 'loggedin';
18 $data[2] = $data['_LOGGEDIN_'];
16 } else { 19 } else {
17 $data[1] = $data[0]; 20 $data[1] = $data[0];
18 } 21 }
diff --git a/tests/render/PageCacheManagerTest.php b/tests/render/PageCacheManagerTest.php
index c258f45f..08d4e5ea 100644
--- a/tests/render/PageCacheManagerTest.php
+++ b/tests/render/PageCacheManagerTest.php
@@ -6,8 +6,8 @@
6 6
7namespace Shaarli\Render; 7namespace Shaarli\Render;
8 8
9use PHPUnit\Framework\TestCase;
10use Shaarli\Security\SessionManager; 9use Shaarli\Security\SessionManager;
10use Shaarli\TestCase;
11 11
12/** 12/**
13 * Unitary tests for cached pages 13 * Unitary tests for cached pages
@@ -29,7 +29,7 @@ class PageCacheManagerTest extends TestCase
29 /** 29 /**
30 * Populate the cache with dummy files 30 * Populate the cache with dummy files
31 */ 31 */
32 public function setUp() 32 protected function setUp(): void
33 { 33 {
34 $this->cacheManager = new PageCacheManager(static::$testCacheDir, true); 34 $this->cacheManager = new PageCacheManager(static::$testCacheDir, true);
35 35
@@ -48,7 +48,7 @@ class PageCacheManagerTest extends TestCase
48 /** 48 /**
49 * Remove dummycache folder after each tests. 49 * Remove dummycache folder after each tests.
50 */ 50 */
51 public function tearDown() 51 protected function tearDown(): void
52 { 52 {
53 array_map('unlink', glob(self::$testCacheDir . '/*')); 53 array_map('unlink', glob(self::$testCacheDir . '/*'));
54 rmdir(self::$testCacheDir); 54 rmdir(self::$testCacheDir);
diff --git a/tests/render/ThemeUtilsTest.php b/tests/render/ThemeUtilsTest.php
index 58e3426b..7d841e4d 100644
--- a/tests/render/ThemeUtilsTest.php
+++ b/tests/render/ThemeUtilsTest.php
@@ -7,7 +7,7 @@ namespace Shaarli\Render;
7 * 7 *
8 * @package Shaarli 8 * @package Shaarli
9 */ 9 */
10class ThemeUtilsTest extends \PHPUnit\Framework\TestCase 10class ThemeUtilsTest extends \Shaarli\TestCase
11{ 11{
12 /** 12 /**
13 * Test getThemes() with existing theme directories. 13 * Test getThemes() with existing theme directories.
diff --git a/tests/security/BanManagerTest.php b/tests/security/BanManagerTest.php
index bba7c8ad..698d3d10 100644
--- a/tests/security/BanManagerTest.php
+++ b/tests/security/BanManagerTest.php
@@ -3,8 +3,8 @@
3 3
4namespace Shaarli\Security; 4namespace Shaarli\Security;
5 5
6use PHPUnit\Framework\TestCase;
7use Shaarli\FileUtils; 6use Shaarli\FileUtils;
7use Shaarli\TestCase;
8 8
9/** 9/**
10 * Test coverage for BanManager 10 * Test coverage for BanManager
@@ -32,7 +32,7 @@ class BanManagerTest extends TestCase
32 /** 32 /**
33 * Prepare or reset test resources 33 * Prepare or reset test resources
34 */ 34 */
35 public function setUp() 35 protected function setUp(): void
36 { 36 {
37 if (file_exists($this->banFile)) { 37 if (file_exists($this->banFile)) {
38 unlink($this->banFile); 38 unlink($this->banFile);
diff --git a/tests/security/LoginManagerTest.php b/tests/security/LoginManagerTest.php
index f242be09..d302983d 100644
--- a/tests/security/LoginManagerTest.php
+++ b/tests/security/LoginManagerTest.php
@@ -2,7 +2,7 @@
2 2
3namespace Shaarli\Security; 3namespace Shaarli\Security;
4 4
5use PHPUnit\Framework\TestCase; 5use Shaarli\TestCase;
6 6
7/** 7/**
8 * Test coverage for LoginManager 8 * Test coverage for LoginManager
@@ -63,7 +63,7 @@ class LoginManagerTest extends TestCase
63 /** 63 /**
64 * Prepare or reset test resources 64 * Prepare or reset test resources
65 */ 65 */
66 public function setUp() 66 protected function setUp(): void
67 { 67 {
68 if (file_exists($this->banFile)) { 68 if (file_exists($this->banFile)) {
69 unlink($this->banFile); 69 unlink($this->banFile);
diff --git a/tests/security/SessionManagerTest.php b/tests/security/SessionManagerTest.php
index 60695dcf..3f9c3ef5 100644
--- a/tests/security/SessionManagerTest.php
+++ b/tests/security/SessionManagerTest.php
@@ -2,7 +2,7 @@
2 2
3namespace Shaarli\Security; 3namespace Shaarli\Security;
4 4
5use PHPUnit\Framework\TestCase; 5use Shaarli\TestCase;
6 6
7/** 7/**
8 * Test coverage for SessionManager 8 * Test coverage for SessionManager
@@ -24,7 +24,7 @@ class SessionManagerTest extends TestCase
24 /** 24 /**
25 * Assign reference data 25 * Assign reference data
26 */ 26 */
27 public static function setUpBeforeClass() 27 public static function setUpBeforeClass(): void
28 { 28 {
29 self::$sidHashes = \ReferenceSessionIdHashes::getHashes(); 29 self::$sidHashes = \ReferenceSessionIdHashes::getHashes();
30 } 30 }
@@ -32,7 +32,7 @@ class SessionManagerTest extends TestCase
32 /** 32 /**
33 * Initialize or reset test resources 33 * Initialize or reset test resources
34 */ 34 */
35 public function setUp() 35 protected function setUp(): void
36 { 36 {
37 $this->conf = new \FakeConfigManager([ 37 $this->conf = new \FakeConfigManager([
38 'credentials.login' => 'johndoe', 38 'credentials.login' => 'johndoe',
@@ -207,15 +207,16 @@ class SessionManagerTest extends TestCase
207 'expires_on' => time() + 1000, 207 'expires_on' => time() + 1000,
208 'username' => 'johndoe', 208 'username' => 'johndoe',
209 'visibility' => 'public', 209 'visibility' => 'public',
210 'untaggedonly' => false, 210 'untaggedonly' => true,
211 ]; 211 ];
212 $this->sessionManager->logout(); 212 $this->sessionManager->logout();
213 213
214 $this->assertFalse(isset($this->session['ip'])); 214 $this->assertArrayNotHasKey('ip', $this->session);
215 $this->assertFalse(isset($this->session['expires_on'])); 215 $this->assertArrayNotHasKey('expires_on', $this->session);
216 $this->assertFalse(isset($this->session['username'])); 216 $this->assertArrayNotHasKey('username', $this->session);
217 $this->assertFalse(isset($this->session['visibility'])); 217 $this->assertArrayNotHasKey('visibility', $this->session);
218 $this->assertFalse(isset($this->session['untaggedonly'])); 218 $this->assertArrayHasKey('untaggedonly', $this->session);
219 $this->assertTrue($this->session['untaggedonly']);
219 } 220 }
220 221
221 /** 222 /**
diff --git a/tests/updater/DummyUpdater.php b/tests/updater/DummyUpdater.php
index 07c7f5c4..3403233f 100644
--- a/tests/updater/DummyUpdater.php
+++ b/tests/updater/DummyUpdater.php
@@ -37,7 +37,7 @@ class DummyUpdater extends Updater
37 * 37 *
38 * @return bool true. 38 * @return bool true.
39 */ 39 */
40 final private function updateMethodDummy1() 40 final protected function updateMethodDummy1()
41 { 41 {
42 return true; 42 return true;
43 } 43 }
@@ -47,7 +47,7 @@ class DummyUpdater extends Updater
47 * 47 *
48 * @return bool true. 48 * @return bool true.
49 */ 49 */
50 final private function updateMethodDummy2() 50 final protected function updateMethodDummy2()
51 { 51 {
52 return true; 52 return true;
53 } 53 }
@@ -57,7 +57,7 @@ class DummyUpdater extends Updater
57 * 57 *
58 * @return bool true. 58 * @return bool true.
59 */ 59 */
60 final private function updateMethodDummy3() 60 final protected function updateMethodDummy3()
61 { 61 {
62 return true; 62 return true;
63 } 63 }
@@ -67,7 +67,7 @@ class DummyUpdater extends Updater
67 * 67 *
68 * @throws Exception error. 68 * @throws Exception error.
69 */ 69 */
70 final private function updateMethodException() 70 final protected function updateMethodException()
71 { 71 {
72 throw new Exception('whatever'); 72 throw new Exception('whatever');
73 } 73 }
diff --git a/tests/updater/UpdaterTest.php b/tests/updater/UpdaterTest.php
index a7dd70bf..a6280b8c 100644
--- a/tests/updater/UpdaterTest.php
+++ b/tests/updater/UpdaterTest.php
@@ -2,11 +2,11 @@
2namespace Shaarli\Updater; 2namespace Shaarli\Updater;
3 3
4use Exception; 4use Exception;
5use PHPUnit\Framework\TestCase;
6use Shaarli\Bookmark\BookmarkFileService; 5use Shaarli\Bookmark\BookmarkFileService;
7use Shaarli\Bookmark\BookmarkServiceInterface; 6use Shaarli\Bookmark\BookmarkServiceInterface;
8use Shaarli\Config\ConfigManager; 7use Shaarli\Config\ConfigManager;
9use Shaarli\History; 8use Shaarli\History;
9use Shaarli\TestCase;
10 10
11 11
12/** 12/**
@@ -42,7 +42,7 @@ class UpdaterTest extends TestCase
42 /** 42 /**
43 * Executed before each test. 43 * Executed before each test.
44 */ 44 */
45 public function setUp() 45 protected function setUp(): void
46 { 46 {
47 $this->refDB = new \ReferenceLinkDB(); 47 $this->refDB = new \ReferenceLinkDB();
48 $this->refDB->write(self::$testDatastore); 48 $this->refDB->write(self::$testDatastore);
@@ -87,23 +87,23 @@ class UpdaterTest extends TestCase
87 87
88 /** 88 /**
89 * Test errors in UpdaterUtils::write_updates_file(): empty updates file. 89 * Test errors in UpdaterUtils::write_updates_file(): empty updates file.
90 *
91 * @expectedException Exception
92 * @expectedExceptionMessageRegExp /Updates file path is not set(.*)/
93 */ 90 */
94 public function testWriteEmptyUpdatesFile() 91 public function testWriteEmptyUpdatesFile()
95 { 92 {
93 $this->expectException(\Exception::class);
94 $this->expectExceptionMessageRegExp('/Updates file path is not set(.*)/');
95
96 UpdaterUtils::write_updates_file('', array('test')); 96 UpdaterUtils::write_updates_file('', array('test'));
97 } 97 }
98 98
99 /** 99 /**
100 * Test errors in UpdaterUtils::write_updates_file(): not writable updates file. 100 * Test errors in UpdaterUtils::write_updates_file(): not writable updates file.
101 *
102 * @expectedException Exception
103 * @expectedExceptionMessageRegExp /Unable to write(.*)/
104 */ 101 */
105 public function testWriteUpdatesFileNotWritable() 102 public function testWriteUpdatesFileNotWritable()
106 { 103 {
104 $this->expectException(\Exception::class);
105 $this->expectExceptionMessageRegExp('/Unable to write(.*)/');
106
107 $updatesFile = $this->conf->get('resource.data_dir') . '/updates.txt'; 107 $updatesFile = $this->conf->get('resource.data_dir') . '/updates.txt';
108 touch($updatesFile); 108 touch($updatesFile);
109 chmod($updatesFile, 0444); 109 chmod($updatesFile, 0444);
@@ -168,11 +168,11 @@ class UpdaterTest extends TestCase
168 168
169 /** 169 /**
170 * Test Update failed. 170 * Test Update failed.
171 *
172 * @expectedException \Exception
173 */ 171 */
174 public function testUpdateFailed() 172 public function testUpdateFailed()
175 { 173 {
174 $this->expectException(\Exception::class);
175
176 $updates = array( 176 $updates = array(
177 'updateMethodDummy1', 177 'updateMethodDummy1',
178 'updateMethodDummy2', 178 'updateMethodDummy2',