aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2021-01-20 15:59:00 +0100
committerArthurHoaro <arthur@hoa.ro>2021-02-04 11:02:50 +0100
commitbcba6bd353161fab456b423e93571ab027d5423c (patch)
tree97a618b77d327a5f963c91522988e24db5a9e158 /tests
parent8997ae6c8e24286f7d47981eaf905e80d2481c10 (diff)
downloadShaarli-bcba6bd353161fab456b423e93571ab027d5423c.tar.gz
Shaarli-bcba6bd353161fab456b423e93571ab027d5423c.tar.zst
Shaarli-bcba6bd353161fab456b423e93571ab027d5423c.zip
New plugin hook: ability to add custom filters to Shaarli search engine
A new plugin hook has been added: hook_test_filter_search_entry This hook allows to filter out bookmark with custom plugin code when a search is performed. Related to #143
Diffstat (limited to 'tests')
-rw-r--r--tests/PluginManagerTest.php16
-rw-r--r--tests/api/ApiMiddlewareTest.php2
-rw-r--r--tests/api/controllers/info/InfoTest.php11
-rw-r--r--tests/api/controllers/links/DeleteLinkTest.php21
-rw-r--r--tests/api/controllers/links/GetLinkIdTest.php10
-rw-r--r--tests/api/controllers/links/GetLinksTest.php10
-rw-r--r--tests/api/controllers/links/PostLinkTest.php11
-rw-r--r--tests/api/controllers/links/PutLinkTest.php11
-rw-r--r--tests/api/controllers/tags/DeleteTagTest.php29
-rw-r--r--tests/api/controllers/tags/GetTagNameTest.php13
-rw-r--r--tests/api/controllers/tags/GetTagsTest.php15
-rw-r--r--tests/api/controllers/tags/PutTagTest.php13
-rw-r--r--tests/bookmark/BookmarkFileServiceTest.php137
-rw-r--r--tests/bookmark/BookmarkFilterTest.php65
-rw-r--r--tests/bookmark/BookmarkInitializerTest.php37
-rw-r--r--tests/feed/FeedBuilderTest.php10
-rw-r--r--tests/netscape/BookmarkExportTest.php13
-rw-r--r--tests/netscape/BookmarkImportTest.php13
-rw-r--r--tests/plugins/test/test.php7
-rw-r--r--tests/updater/UpdaterTest.php9
20 files changed, 349 insertions, 104 deletions
diff --git a/tests/PluginManagerTest.php b/tests/PluginManagerTest.php
index 8947f679..75b3ae00 100644
--- a/tests/PluginManagerTest.php
+++ b/tests/PluginManagerTest.php
@@ -2,6 +2,7 @@
2 2
3namespace Shaarli\Plugin; 3namespace Shaarli\Plugin;
4 4
5use Shaarli\Bookmark\Bookmark;
5use Shaarli\Config\ConfigManager; 6use Shaarli\Config\ConfigManager;
6 7
7/** 8/**
@@ -159,4 +160,19 @@ class PluginManagerTest extends \Shaarli\TestCase
159 $errors = $this->pluginManager->getErrors(); 160 $errors = $this->pluginManager->getErrors();
160 static::assertSame(['test_route_invalid [plugin incompatibility]: trying to register invalid route.'], $errors); 161 static::assertSame(['test_route_invalid [plugin incompatibility]: trying to register invalid route.'], $errors);
161 } 162 }
163
164 public function testSearchFilterPlugin(): void
165 {
166 PluginManager::$PLUGINS_PATH = self::$pluginPath;
167 $this->pluginManager->load([self::$pluginName]);
168
169 static::assertNull($this->pluginManager->getFilterSearchEntryHooks());
170
171 static::assertTrue($this->pluginManager->filterSearchEntry(new Bookmark(), ['_result' => true]));
172
173 static::assertCount(1, $this->pluginManager->getFilterSearchEntryHooks());
174 static::assertSame('hook_test_filter_search_entry', $this->pluginManager->getFilterSearchEntryHooks()[0]);
175
176 static::assertFalse($this->pluginManager->filterSearchEntry(new Bookmark(), ['_result' => false]));
177 }
162} 178}
diff --git a/tests/api/ApiMiddlewareTest.php b/tests/api/ApiMiddlewareTest.php
index 86700840..2afac28b 100644
--- a/tests/api/ApiMiddlewareTest.php
+++ b/tests/api/ApiMiddlewareTest.php
@@ -3,6 +3,7 @@ namespace Shaarli\Api;
3 3
4use Shaarli\Config\ConfigManager; 4use Shaarli\Config\ConfigManager;
5use Shaarli\History; 5use Shaarli\History;
6use Shaarli\Plugin\PluginManager;
6use Slim\Container; 7use Slim\Container;
7use Slim\Http\Environment; 8use Slim\Http\Environment;
8use Slim\Http\Request; 9use Slim\Http\Request;
@@ -56,6 +57,7 @@ class ApiMiddlewareTest extends \Shaarli\TestCase
56 $this->container = new Container(); 57 $this->container = new Container();
57 $this->container['conf'] = $this->conf; 58 $this->container['conf'] = $this->conf;
58 $this->container['history'] = $history; 59 $this->container['history'] = $history;
60 $this->container['pluginManager'] = new PluginManager($this->conf);
59 } 61 }
60 62
61 /** 63 /**
diff --git a/tests/api/controllers/info/InfoTest.php b/tests/api/controllers/info/InfoTest.php
index 10b29ab2..2428ca43 100644
--- a/tests/api/controllers/info/InfoTest.php
+++ b/tests/api/controllers/info/InfoTest.php
@@ -5,6 +5,7 @@ use malkusch\lock\mutex\NoMutex;
5use Shaarli\Bookmark\BookmarkFileService; 5use Shaarli\Bookmark\BookmarkFileService;
6use Shaarli\Config\ConfigManager; 6use Shaarli\Config\ConfigManager;
7use Shaarli\History; 7use Shaarli\History;
8use Shaarli\Plugin\PluginManager;
8use Shaarli\TestCase; 9use Shaarli\TestCase;
9use Slim\Container; 10use Slim\Container;
10use Slim\Http\Environment; 11use Slim\Http\Environment;
@@ -55,12 +56,18 @@ class InfoTest extends TestCase
55 $this->conf->set('resource.datastore', self::$testDatastore); 56 $this->conf->set('resource.datastore', self::$testDatastore);
56 $this->refDB = new \ReferenceLinkDB(); 57 $this->refDB = new \ReferenceLinkDB();
57 $this->refDB->write(self::$testDatastore); 58 $this->refDB->write(self::$testDatastore);
58 59 $this->pluginManager = new PluginManager($this->conf);
59 $history = new History('sandbox/history.php'); 60 $history = new History('sandbox/history.php');
60 61
61 $this->container = new Container(); 62 $this->container = new Container();
62 $this->container['conf'] = $this->conf; 63 $this->container['conf'] = $this->conf;
63 $this->container['db'] = new BookmarkFileService($this->conf, $history, $mutex, true); 64 $this->container['db'] = new BookmarkFileService(
65 $this->conf,
66 $this->pluginManager,
67 $history,
68 $mutex,
69 true
70 );
64 $this->container['history'] = null; 71 $this->container['history'] = null;
65 72
66 $this->controller = new Info($this->container); 73 $this->controller = new Info($this->container);
diff --git a/tests/api/controllers/links/DeleteLinkTest.php b/tests/api/controllers/links/DeleteLinkTest.php
index 805c9be3..dc2cf917 100644
--- a/tests/api/controllers/links/DeleteLinkTest.php
+++ b/tests/api/controllers/links/DeleteLinkTest.php
@@ -7,6 +7,7 @@ use malkusch\lock\mutex\NoMutex;
7use Shaarli\Bookmark\BookmarkFileService; 7use Shaarli\Bookmark\BookmarkFileService;
8use Shaarli\Config\ConfigManager; 8use Shaarli\Config\ConfigManager;
9use Shaarli\History; 9use Shaarli\History;
10use Shaarli\Plugin\PluginManager;
10use Slim\Container; 11use Slim\Container;
11use Slim\Http\Environment; 12use Slim\Http\Environment;
12use Slim\Http\Request; 13use Slim\Http\Request;
@@ -57,6 +58,9 @@ class DeleteLinkTest extends \Shaarli\TestCase
57 /** @var NoMutex */ 58 /** @var NoMutex */
58 protected $mutex; 59 protected $mutex;
59 60
61 /** @var PluginManager */
62 protected $pluginManager;
63
60 /** 64 /**
61 * Before each test, instantiate a new Api with its config, plugins and bookmarks. 65 * Before each test, instantiate a new Api with its config, plugins and bookmarks.
62 */ 66 */
@@ -70,7 +74,14 @@ class DeleteLinkTest extends \Shaarli\TestCase
70 $refHistory = new \ReferenceHistory(); 74 $refHistory = new \ReferenceHistory();
71 $refHistory->write(self::$testHistory); 75 $refHistory->write(self::$testHistory);
72 $this->history = new History(self::$testHistory); 76 $this->history = new History(self::$testHistory);
73 $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); 77 $this->pluginManager = new PluginManager($this->conf);
78 $this->bookmarkService = new BookmarkFileService(
79 $this->conf,
80 $this->pluginManager,
81 $this->history,
82 $this->mutex,
83 true
84 );
74 85
75 $this->container = new Container(); 86 $this->container = new Container();
76 $this->container['conf'] = $this->conf; 87 $this->container['conf'] = $this->conf;
@@ -105,7 +116,13 @@ class DeleteLinkTest extends \Shaarli\TestCase
105 $this->assertEquals(204, $response->getStatusCode()); 116 $this->assertEquals(204, $response->getStatusCode());
106 $this->assertEmpty((string) $response->getBody()); 117 $this->assertEmpty((string) $response->getBody());
107 118
108 $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); 119 $this->bookmarkService = new BookmarkFileService(
120 $this->conf,
121 $this->pluginManager,
122 $this->history,
123 $this->mutex,
124 true
125 );
109 $this->assertFalse($this->bookmarkService->exists($id)); 126 $this->assertFalse($this->bookmarkService->exists($id));
110 127
111 $historyEntry = $this->history->getHistory()[0]; 128 $historyEntry = $this->history->getHistory()[0];
diff --git a/tests/api/controllers/links/GetLinkIdTest.php b/tests/api/controllers/links/GetLinkIdTest.php
index 1ec56ef3..c93a3b4b 100644
--- a/tests/api/controllers/links/GetLinkIdTest.php
+++ b/tests/api/controllers/links/GetLinkIdTest.php
@@ -7,6 +7,7 @@ use Shaarli\Bookmark\Bookmark;
7use Shaarli\Bookmark\BookmarkFileService; 7use Shaarli\Bookmark\BookmarkFileService;
8use Shaarli\Config\ConfigManager; 8use Shaarli\Config\ConfigManager;
9use Shaarli\History; 9use Shaarli\History;
10use Shaarli\Plugin\PluginManager;
10use Slim\Container; 11use Slim\Container;
11use Slim\Http\Environment; 12use Slim\Http\Environment;
12use Slim\Http\Request; 13use Slim\Http\Request;
@@ -67,7 +68,14 @@ class GetLinkIdTest extends \Shaarli\TestCase
67 68
68 $this->container = new Container(); 69 $this->container = new Container();
69 $this->container['conf'] = $this->conf; 70 $this->container['conf'] = $this->conf;
70 $this->container['db'] = new BookmarkFileService($this->conf, $history, $mutex, true); 71 $pluginManager = new PluginManager($this->conf);
72 $this->container['db'] = new BookmarkFileService(
73 $this->conf,
74 $pluginManager,
75 $history,
76 $mutex,
77 true
78 );
71 $this->container['history'] = null; 79 $this->container['history'] = null;
72 80
73 $this->controller = new Links($this->container); 81 $this->controller = new Links($this->container);
diff --git a/tests/api/controllers/links/GetLinksTest.php b/tests/api/controllers/links/GetLinksTest.php
index b1c46ee2..3c966732 100644
--- a/tests/api/controllers/links/GetLinksTest.php
+++ b/tests/api/controllers/links/GetLinksTest.php
@@ -7,6 +7,7 @@ use Shaarli\Bookmark\BookmarkFileService;
7use Shaarli\Bookmark\LinkDB; 7use Shaarli\Bookmark\LinkDB;
8use Shaarli\Config\ConfigManager; 8use Shaarli\Config\ConfigManager;
9use Shaarli\History; 9use Shaarli\History;
10use Shaarli\Plugin\PluginManager;
10use Slim\Container; 11use Slim\Container;
11use Slim\Http\Environment; 12use Slim\Http\Environment;
12use Slim\Http\Request; 13use Slim\Http\Request;
@@ -67,7 +68,14 @@ class GetLinksTest extends \Shaarli\TestCase
67 68
68 $this->container = new Container(); 69 $this->container = new Container();
69 $this->container['conf'] = $this->conf; 70 $this->container['conf'] = $this->conf;
70 $this->container['db'] = new BookmarkFileService($this->conf, $history, $mutex, true); 71 $pluginManager = new PluginManager($this->conf);
72 $this->container['db'] = new BookmarkFileService(
73 $this->conf,
74 $pluginManager,
75 $history,
76 $mutex,
77 true
78 );
71 $this->container['history'] = null; 79 $this->container['history'] = null;
72 80
73 $this->controller = new Links($this->container); 81 $this->controller = new Links($this->container);
diff --git a/tests/api/controllers/links/PostLinkTest.php b/tests/api/controllers/links/PostLinkTest.php
index f755e2d2..a54e4a16 100644
--- a/tests/api/controllers/links/PostLinkTest.php
+++ b/tests/api/controllers/links/PostLinkTest.php
@@ -7,6 +7,7 @@ use Shaarli\Bookmark\Bookmark;
7use Shaarli\Bookmark\BookmarkFileService; 7use Shaarli\Bookmark\BookmarkFileService;
8use Shaarli\Config\ConfigManager; 8use Shaarli\Config\ConfigManager;
9use Shaarli\History; 9use Shaarli\History;
10use Shaarli\Plugin\PluginManager;
10use Shaarli\TestCase; 11use Shaarli\TestCase;
11use Slim\Container; 12use Slim\Container;
12use Slim\Http\Environment; 13use Slim\Http\Environment;
@@ -81,8 +82,14 @@ class PostLinkTest extends TestCase
81 $refHistory = new \ReferenceHistory(); 82 $refHistory = new \ReferenceHistory();
82 $refHistory->write(self::$testHistory); 83 $refHistory->write(self::$testHistory);
83 $this->history = new History(self::$testHistory); 84 $this->history = new History(self::$testHistory);
84 $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $mutex, true); 85 $pluginManager = new PluginManager($this->conf);
85 86 $this->bookmarkService = new BookmarkFileService(
87 $this->conf,
88 $pluginManager,
89 $this->history,
90 $mutex,
91 true
92 );
86 $this->container = new Container(); 93 $this->container = new Container();
87 $this->container['conf'] = $this->conf; 94 $this->container['conf'] = $this->conf;
88 $this->container['db'] = $this->bookmarkService; 95 $this->container['db'] = $this->bookmarkService;
diff --git a/tests/api/controllers/links/PutLinkTest.php b/tests/api/controllers/links/PutLinkTest.php
index fe24f2eb..ed14d5f8 100644
--- a/tests/api/controllers/links/PutLinkTest.php
+++ b/tests/api/controllers/links/PutLinkTest.php
@@ -8,6 +8,7 @@ use Shaarli\Bookmark\Bookmark;
8use Shaarli\Bookmark\BookmarkFileService; 8use Shaarli\Bookmark\BookmarkFileService;
9use Shaarli\Config\ConfigManager; 9use Shaarli\Config\ConfigManager;
10use Shaarli\History; 10use Shaarli\History;
11use Shaarli\Plugin\PluginManager;
11use Slim\Container; 12use Slim\Container;
12use Slim\Http\Environment; 13use Slim\Http\Environment;
13use Slim\Http\Request; 14use Slim\Http\Request;
@@ -73,8 +74,14 @@ class PutLinkTest extends \Shaarli\TestCase
73 $refHistory = new \ReferenceHistory(); 74 $refHistory = new \ReferenceHistory();
74 $refHistory->write(self::$testHistory); 75 $refHistory->write(self::$testHistory);
75 $this->history = new History(self::$testHistory); 76 $this->history = new History(self::$testHistory);
76 $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $mutex, true); 77 $pluginManager = new PluginManager($this->conf);
77 78 $this->bookmarkService = new BookmarkFileService(
79 $this->conf,
80 $pluginManager,
81 $this->history,
82 $mutex,
83 true
84 );
78 $this->container = new Container(); 85 $this->container = new Container();
79 $this->container['conf'] = $this->conf; 86 $this->container['conf'] = $this->conf;
80 $this->container['db'] = $this->bookmarkService; 87 $this->container['db'] = $this->bookmarkService;
diff --git a/tests/api/controllers/tags/DeleteTagTest.php b/tests/api/controllers/tags/DeleteTagTest.php
index 37f07229..c0f8a6a9 100644
--- a/tests/api/controllers/tags/DeleteTagTest.php
+++ b/tests/api/controllers/tags/DeleteTagTest.php
@@ -8,6 +8,7 @@ use Shaarli\Bookmark\BookmarkFileService;
8use Shaarli\Bookmark\LinkDB; 8use Shaarli\Bookmark\LinkDB;
9use Shaarli\Config\ConfigManager; 9use Shaarli\Config\ConfigManager;
10use Shaarli\History; 10use Shaarli\History;
11use Shaarli\Plugin\PluginManager;
11use Slim\Container; 12use Slim\Container;
12use Slim\Http\Environment; 13use Slim\Http\Environment;
13use Slim\Http\Request; 14use Slim\Http\Request;
@@ -55,6 +56,9 @@ class DeleteTagTest extends \Shaarli\TestCase
55 */ 56 */
56 protected $controller; 57 protected $controller;
57 58
59 /** @var PluginManager */
60 protected $pluginManager;
61
58 /** @var NoMutex */ 62 /** @var NoMutex */
59 protected $mutex; 63 protected $mutex;
60 64
@@ -71,7 +75,14 @@ class DeleteTagTest extends \Shaarli\TestCase
71 $refHistory = new \ReferenceHistory(); 75 $refHistory = new \ReferenceHistory();
72 $refHistory->write(self::$testHistory); 76 $refHistory->write(self::$testHistory);
73 $this->history = new History(self::$testHistory); 77 $this->history = new History(self::$testHistory);
74 $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); 78 $this->pluginManager = new PluginManager($this->conf);
79 $this->bookmarkService = new BookmarkFileService(
80 $this->conf,
81 $this->pluginManager,
82 $this->history,
83 $this->mutex,
84 true
85 );
75 86
76 $this->container = new Container(); 87 $this->container = new Container();
77 $this->container['conf'] = $this->conf; 88 $this->container['conf'] = $this->conf;
@@ -107,7 +118,13 @@ class DeleteTagTest extends \Shaarli\TestCase
107 $this->assertEquals(204, $response->getStatusCode()); 118 $this->assertEquals(204, $response->getStatusCode());
108 $this->assertEmpty((string) $response->getBody()); 119 $this->assertEmpty((string) $response->getBody());
109 120
110 $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); 121 $this->bookmarkService = new BookmarkFileService(
122 $this->conf,
123 $this->pluginManager,
124 $this->history,
125 $this->mutex,
126 true
127 );
111 $tags = $this->bookmarkService->bookmarksCountPerTag(); 128 $tags = $this->bookmarkService->bookmarksCountPerTag();
112 $this->assertFalse(isset($tags[$tagName])); 129 $this->assertFalse(isset($tags[$tagName]));
113 130
@@ -141,7 +158,13 @@ class DeleteTagTest extends \Shaarli\TestCase
141 $this->assertEquals(204, $response->getStatusCode()); 158 $this->assertEquals(204, $response->getStatusCode());
142 $this->assertEmpty((string) $response->getBody()); 159 $this->assertEmpty((string) $response->getBody());
143 160
144 $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); 161 $this->bookmarkService = new BookmarkFileService(
162 $this->conf,
163 $this->pluginManager,
164 $this->history,
165 $this->mutex,
166 true
167 );
145 $tags = $this->bookmarkService->bookmarksCountPerTag(); 168 $tags = $this->bookmarkService->bookmarksCountPerTag();
146 $this->assertFalse(isset($tags[$tagName])); 169 $this->assertFalse(isset($tags[$tagName]));
147 $this->assertTrue($tags[strtolower($tagName)] > 0); 170 $this->assertTrue($tags[strtolower($tagName)] > 0);
diff --git a/tests/api/controllers/tags/GetTagNameTest.php b/tests/api/controllers/tags/GetTagNameTest.php
index 878de5a4..0ad71495 100644
--- a/tests/api/controllers/tags/GetTagNameTest.php
+++ b/tests/api/controllers/tags/GetTagNameTest.php
@@ -7,6 +7,7 @@ use Shaarli\Bookmark\BookmarkFileService;
7use Shaarli\Bookmark\LinkDB; 7use Shaarli\Bookmark\LinkDB;
8use Shaarli\Config\ConfigManager; 8use Shaarli\Config\ConfigManager;
9use Shaarli\History; 9use Shaarli\History;
10use Shaarli\Plugin\PluginManager;
10use Slim\Container; 11use Slim\Container;
11use Slim\Http\Environment; 12use Slim\Http\Environment;
12use Slim\Http\Request; 13use Slim\Http\Request;
@@ -46,6 +47,9 @@ class GetTagNameTest extends \Shaarli\TestCase
46 */ 47 */
47 protected $controller; 48 protected $controller;
48 49
50 /** @var PluginManager */
51 protected $pluginManager;
52
49 /** 53 /**
50 * Number of JSON fields per link. 54 * Number of JSON fields per link.
51 */ 55 */
@@ -65,7 +69,14 @@ class GetTagNameTest extends \Shaarli\TestCase
65 69
66 $this->container = new Container(); 70 $this->container = new Container();
67 $this->container['conf'] = $this->conf; 71 $this->container['conf'] = $this->conf;
68 $this->container['db'] = new BookmarkFileService($this->conf, $history, $mutex, true); 72 $this->pluginManager = new PluginManager($this->conf);
73 $this->container['db'] = new BookmarkFileService(
74 $this->conf,
75 $this->pluginManager,
76 $history,
77 $mutex,
78 true
79 );
69 $this->container['history'] = null; 80 $this->container['history'] = null;
70 81
71 $this->controller = new Tags($this->container); 82 $this->controller = new Tags($this->container);
diff --git a/tests/api/controllers/tags/GetTagsTest.php b/tests/api/controllers/tags/GetTagsTest.php
index b565a8c4..a4b62c51 100644
--- a/tests/api/controllers/tags/GetTagsTest.php
+++ b/tests/api/controllers/tags/GetTagsTest.php
@@ -6,6 +6,7 @@ use Shaarli\Bookmark\BookmarkFileService;
6use Shaarli\Bookmark\LinkDB; 6use Shaarli\Bookmark\LinkDB;
7use Shaarli\Config\ConfigManager; 7use Shaarli\Config\ConfigManager;
8use Shaarli\History; 8use Shaarli\History;
9use Shaarli\Plugin\PluginManager;
9use Slim\Container; 10use Slim\Container;
10use Slim\Http\Environment; 11use Slim\Http\Environment;
11use Slim\Http\Request; 12use Slim\Http\Request;
@@ -50,6 +51,9 @@ class GetTagsTest extends \Shaarli\TestCase
50 */ 51 */
51 protected $controller; 52 protected $controller;
52 53
54 /** @var PluginManager */
55 protected $pluginManager;
56
53 /** 57 /**
54 * Number of JSON field per link. 58 * Number of JSON field per link.
55 */ 59 */
@@ -66,9 +70,14 @@ class GetTagsTest extends \Shaarli\TestCase
66 $this->refDB = new \ReferenceLinkDB(); 70 $this->refDB = new \ReferenceLinkDB();
67 $this->refDB->write(self::$testDatastore); 71 $this->refDB->write(self::$testDatastore);
68 $history = new History('sandbox/history.php'); 72 $history = new History('sandbox/history.php');
69 73 $this->pluginManager = new PluginManager($this->conf);
70 $this->bookmarkService = new BookmarkFileService($this->conf, $history, $mutex, true); 74 $this->bookmarkService = new BookmarkFileService(
71 75 $this->conf,
76 $this->pluginManager,
77 $history,
78 $mutex,
79 true
80 );
72 $this->container = new Container(); 81 $this->container = new Container();
73 $this->container['conf'] = $this->conf; 82 $this->container['conf'] = $this->conf;
74 $this->container['db'] = $this->bookmarkService; 83 $this->container['db'] = $this->bookmarkService;
diff --git a/tests/api/controllers/tags/PutTagTest.php b/tests/api/controllers/tags/PutTagTest.php
index c73f6d3b..045473e6 100644
--- a/tests/api/controllers/tags/PutTagTest.php
+++ b/tests/api/controllers/tags/PutTagTest.php
@@ -8,6 +8,7 @@ use Shaarli\Bookmark\BookmarkFileService;
8use Shaarli\Bookmark\LinkDB; 8use Shaarli\Bookmark\LinkDB;
9use Shaarli\Config\ConfigManager; 9use Shaarli\Config\ConfigManager;
10use Shaarli\History; 10use Shaarli\History;
11use Shaarli\Plugin\PluginManager;
11use Slim\Container; 12use Slim\Container;
12use Slim\Http\Environment; 13use Slim\Http\Environment;
13use Slim\Http\Request; 14use Slim\Http\Request;
@@ -55,6 +56,9 @@ class PutTagTest extends \Shaarli\TestCase
55 */ 56 */
56 protected $controller; 57 protected $controller;
57 58
59 /** @var PluginManager */
60 protected $pluginManager;
61
58 /** 62 /**
59 * Number of JSON field per link. 63 * Number of JSON field per link.
60 */ 64 */
@@ -73,7 +77,14 @@ class PutTagTest extends \Shaarli\TestCase
73 $refHistory = new \ReferenceHistory(); 77 $refHistory = new \ReferenceHistory();
74 $refHistory->write(self::$testHistory); 78 $refHistory->write(self::$testHistory);
75 $this->history = new History(self::$testHistory); 79 $this->history = new History(self::$testHistory);
76 $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $mutex, true); 80 $this->pluginManager = new PluginManager($this->conf);
81 $this->bookmarkService = new BookmarkFileService(
82 $this->conf,
83 $this->pluginManager,
84 $this->history,
85 $mutex,
86 true
87 );
77 88
78 $this->container = new Container(); 89 $this->container = new Container();
79 $this->container['conf'] = $this->conf; 90 $this->container['conf'] = $this->conf;
diff --git a/tests/bookmark/BookmarkFileServiceTest.php b/tests/bookmark/BookmarkFileServiceTest.php
index d1af3fb0..1d250719 100644
--- a/tests/bookmark/BookmarkFileServiceTest.php
+++ b/tests/bookmark/BookmarkFileServiceTest.php
@@ -14,6 +14,7 @@ use Shaarli\Bookmark\Exception\BookmarkNotFoundException;
14use Shaarli\Config\ConfigManager; 14use Shaarli\Config\ConfigManager;
15use Shaarli\Formatter\BookmarkMarkdownFormatter; 15use Shaarli\Formatter\BookmarkMarkdownFormatter;
16use Shaarli\History; 16use Shaarli\History;
17use Shaarli\Plugin\PluginManager;
17use Shaarli\TestCase; 18use Shaarli\TestCase;
18 19
19/** 20/**
@@ -56,6 +57,9 @@ class BookmarkFileServiceTest extends TestCase
56 /** @var NoMutex */ 57 /** @var NoMutex */
57 protected $mutex; 58 protected $mutex;
58 59
60 /** @var PluginManager */
61 protected $pluginManager;
62
59 /** 63 /**
60 * Instantiates public and private LinkDBs with test data 64 * Instantiates public and private LinkDBs with test data
61 * 65 *
@@ -93,8 +97,21 @@ class BookmarkFileServiceTest extends TestCase
93 $this->refDB = new \ReferenceLinkDB(); 97 $this->refDB = new \ReferenceLinkDB();
94 $this->refDB->write(self::$testDatastore); 98 $this->refDB->write(self::$testDatastore);
95 $this->history = new History('sandbox/history.php'); 99 $this->history = new History('sandbox/history.php');
96 $this->publicLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, false); 100 $this->pluginManager = new PluginManager($this->conf);
97 $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); 101 $this->publicLinkDB = new BookmarkFileService(
102 $this->conf,
103 $this->pluginManager,
104 $this->history,
105 $this->mutex,
106 false
107 );
108 $this->privateLinkDB = new BookmarkFileService(
109 $this->conf,
110 $this->pluginManager,
111 $this->history,
112 $this->mutex,
113 true
114 );
98 } 115 }
99 116
100 /** 117 /**
@@ -111,7 +128,13 @@ class BookmarkFileServiceTest extends TestCase
111 $db = self::getMethod('migrate'); 128 $db = self::getMethod('migrate');
112 $db->invokeArgs($this->privateLinkDB, []); 129 $db->invokeArgs($this->privateLinkDB, []);
113 130
114 $db = new \FakeBookmarkService($this->conf, $this->history, $this->mutex, true); 131 $db = new \FakeBookmarkService(
132 $this->conf,
133 $this->pluginManager,
134 $this->history,
135 $this->mutex,
136 true
137 );
115 $this->assertInstanceOf(BookmarkArray::class, $db->getBookmarks()); 138 $this->assertInstanceOf(BookmarkArray::class, $db->getBookmarks());
116 $this->assertEquals($this->refDB->countLinks(), $db->count()); 139 $this->assertEquals($this->refDB->countLinks(), $db->count());
117 } 140 }
@@ -180,7 +203,13 @@ class BookmarkFileServiceTest extends TestCase
180 $this->assertEquals($updated, $bookmark->getUpdated()); 203 $this->assertEquals($updated, $bookmark->getUpdated());
181 204
182 // reload from file 205 // reload from file
183 $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); 206 $this->privateLinkDB = new \FakeBookmarkService(
207 $this->conf,
208 $this->pluginManager,
209 $this->history,
210 $this->mutex,
211 true
212 );
184 213
185 $bookmark = $this->privateLinkDB->get(43); 214 $bookmark = $this->privateLinkDB->get(43);
186 $this->assertEquals(43, $bookmark->getId()); 215 $this->assertEquals(43, $bookmark->getId());
@@ -218,7 +247,13 @@ class BookmarkFileServiceTest extends TestCase
218 $this->assertNull($bookmark->getUpdated()); 247 $this->assertNull($bookmark->getUpdated());
219 248
220 // reload from file 249 // reload from file
221 $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); 250 $this->privateLinkDB = new BookmarkFileService(
251 $this->conf,
252 $this->pluginManager,
253 $this->history,
254 $this->mutex,
255 true
256 );
222 257
223 $bookmark = $this->privateLinkDB->get(43); 258 $bookmark = $this->privateLinkDB->get(43);
224 $this->assertEquals(43, $bookmark->getId()); 259 $this->assertEquals(43, $bookmark->getId());
@@ -248,7 +283,13 @@ class BookmarkFileServiceTest extends TestCase
248 $this->assertEquals(43, $bookmark->getId()); 283 $this->assertEquals(43, $bookmark->getId());
249 284
250 // reload from file 285 // reload from file
251 $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); 286 $this->privateLinkDB = new BookmarkFileService(
287 $this->conf,
288 $this->pluginManager,
289 $this->history,
290 $this->mutex,
291 true
292 );
252 293
253 $this->privateLinkDB->get(43); 294 $this->privateLinkDB->get(43);
254 } 295 }
@@ -309,7 +350,13 @@ class BookmarkFileServiceTest extends TestCase
309 $this->assertTrue(new \DateTime('5 seconds ago') < $bookmark->getUpdated()); 350 $this->assertTrue(new \DateTime('5 seconds ago') < $bookmark->getUpdated());
310 351
311 // reload from file 352 // reload from file
312 $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); 353 $this->privateLinkDB = new BookmarkFileService(
354 $this->conf,
355 $this->pluginManager,
356 $this->history,
357 $this->mutex,
358 true
359 );
313 360
314 $bookmark = $this->privateLinkDB->get(42); 361 $bookmark = $this->privateLinkDB->get(42);
315 $this->assertEquals(42, $bookmark->getId()); 362 $this->assertEquals(42, $bookmark->getId());
@@ -350,7 +397,13 @@ class BookmarkFileServiceTest extends TestCase
350 $this->assertTrue(new \DateTime('5 seconds ago') < $bookmark->getUpdated()); 397 $this->assertTrue(new \DateTime('5 seconds ago') < $bookmark->getUpdated());
351 398
352 // reload from file 399 // reload from file
353 $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); 400 $this->privateLinkDB = new BookmarkFileService(
401 $this->conf,
402 $this->pluginManager,
403 $this->history,
404 $this->mutex,
405 true
406 );
354 407
355 $bookmark = $this->privateLinkDB->get(42); 408 $bookmark = $this->privateLinkDB->get(42);
356 $this->assertEquals(42, $bookmark->getId()); 409 $this->assertEquals(42, $bookmark->getId());
@@ -383,7 +436,13 @@ class BookmarkFileServiceTest extends TestCase
383 $this->assertEquals($title, $bookmark->getTitle()); 436 $this->assertEquals($title, $bookmark->getTitle());
384 437
385 // reload from file 438 // reload from file
386 $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); 439 $this->privateLinkDB = new BookmarkFileService(
440 $this->conf,
441 $this->pluginManager,
442 $this->history,
443 $this->mutex,
444 true
445 );
387 446
388 $bookmark = $this->privateLinkDB->get(42); 447 $bookmark = $this->privateLinkDB->get(42);
389 $this->assertEquals(42, $bookmark->getId()); 448 $this->assertEquals(42, $bookmark->getId());
@@ -436,7 +495,13 @@ class BookmarkFileServiceTest extends TestCase
436 $this->assertEquals(43, $bookmark->getId()); 495 $this->assertEquals(43, $bookmark->getId());
437 496
438 // reload from file 497 // reload from file
439 $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); 498 $this->privateLinkDB = new BookmarkFileService(
499 $this->conf,
500 $this->pluginManager,
501 $this->history,
502 $this->mutex,
503 true
504 );
440 505
441 $bookmark = $this->privateLinkDB->get(43); 506 $bookmark = $this->privateLinkDB->get(43);
442 $this->assertEquals(43, $bookmark->getId()); 507 $this->assertEquals(43, $bookmark->getId());
@@ -456,7 +521,13 @@ class BookmarkFileServiceTest extends TestCase
456 $this->assertEquals($title, $bookmark->getTitle()); 521 $this->assertEquals($title, $bookmark->getTitle());
457 522
458 // reload from file 523 // reload from file
459 $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); 524 $this->privateLinkDB = new BookmarkFileService(
525 $this->conf,
526 $this->pluginManager,
527 $this->history,
528 $this->mutex,
529 true
530 );
460 531
461 $bookmark = $this->privateLinkDB->get(42); 532 $bookmark = $this->privateLinkDB->get(42);
462 $this->assertEquals(42, $bookmark->getId()); 533 $this->assertEquals(42, $bookmark->getId());
@@ -488,7 +559,13 @@ class BookmarkFileServiceTest extends TestCase
488 $this->assertEquals($title, $bookmark->getTitle()); 559 $this->assertEquals($title, $bookmark->getTitle());
489 560
490 // reload from file 561 // reload from file
491 $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); 562 $this->privateLinkDB = new BookmarkFileService(
563 $this->conf,
564 $this->pluginManager,
565 $this->history,
566 $this->mutex,
567 true
568 );
492 569
493 $bookmark = $this->privateLinkDB->get(42); 570 $bookmark = $this->privateLinkDB->get(42);
494 $this->assertEquals(42, $bookmark->getId()); 571 $this->assertEquals(42, $bookmark->getId());
@@ -514,7 +591,13 @@ class BookmarkFileServiceTest extends TestCase
514 $this->assertInstanceOf(BookmarkNotFoundException::class, $exception); 591 $this->assertInstanceOf(BookmarkNotFoundException::class, $exception);
515 592
516 // reload from file 593 // reload from file
517 $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); 594 $this->privateLinkDB = new BookmarkFileService(
595 $this->conf,
596 $this->pluginManager,
597 $this->history,
598 $this->mutex,
599 true
600 );
518 601
519 $this->privateLinkDB->get(42); 602 $this->privateLinkDB->get(42);
520 } 603 }
@@ -607,7 +690,7 @@ class BookmarkFileServiceTest extends TestCase
607 690
608 $conf = new ConfigManager('tests/utils/config/configJson'); 691 $conf = new ConfigManager('tests/utils/config/configJson');
609 $conf->set('resource.datastore', 'null/store.db'); 692 $conf->set('resource.datastore', 'null/store.db');
610 new BookmarkFileService($conf, $this->history, $this->mutex, true); 693 new BookmarkFileService($conf, $this->pluginManager, $this->history, $this->mutex, true);
611 } 694 }
612 695
613 /** 696 /**
@@ -617,7 +700,7 @@ class BookmarkFileServiceTest extends TestCase
617 { 700 {
618 unlink(self::$testDatastore); 701 unlink(self::$testDatastore);
619 $this->assertFileNotExists(self::$testDatastore); 702 $this->assertFileNotExists(self::$testDatastore);
620 new BookmarkFileService($this->conf, $this->history, $this->mutex, true); 703 new BookmarkFileService($this->conf, $this->pluginManager, $this->history, $this->mutex, true);
621 $this->assertFileExists(self::$testDatastore); 704 $this->assertFileExists(self::$testDatastore);
622 705
623 // ensure the correct data has been written 706 // ensure the correct data has been written
@@ -631,7 +714,7 @@ class BookmarkFileServiceTest extends TestCase
631 { 714 {
632 unlink(self::$testDatastore); 715 unlink(self::$testDatastore);
633 $this->assertFileNotExists(self::$testDatastore); 716 $this->assertFileNotExists(self::$testDatastore);
634 $db = new \FakeBookmarkService($this->conf, $this->history, $this->mutex, false); 717 $db = new \FakeBookmarkService($this->conf, $this->pluginManager, $this->history, $this->mutex, false);
635 $this->assertFileNotExists(self::$testDatastore); 718 $this->assertFileNotExists(self::$testDatastore);
636 $this->assertInstanceOf(BookmarkArray::class, $db->getBookmarks()); 719 $this->assertInstanceOf(BookmarkArray::class, $db->getBookmarks());
637 $this->assertCount(0, $db->getBookmarks()); 720 $this->assertCount(0, $db->getBookmarks());
@@ -664,13 +747,13 @@ class BookmarkFileServiceTest extends TestCase
664 */ 747 */
665 public function testSave() 748 public function testSave()
666 { 749 {
667 $testDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); 750 $testDB = new BookmarkFileService($this->conf, $this->pluginManager, $this->history, $this->mutex, true);
668 $dbSize = $testDB->count(); 751 $dbSize = $testDB->count();
669 752
670 $bookmark = new Bookmark(); 753 $bookmark = new Bookmark();
671 $testDB->add($bookmark); 754 $testDB->add($bookmark);
672 755
673 $testDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); 756 $testDB = new BookmarkFileService($this->conf, $this->pluginManager, $this->history, $this->mutex, true);
674 $this->assertEquals($dbSize + 1, $testDB->count()); 757 $this->assertEquals($dbSize + 1, $testDB->count());
675 } 758 }
676 759
@@ -680,7 +763,7 @@ class BookmarkFileServiceTest extends TestCase
680 public function testCountHiddenPublic() 763 public function testCountHiddenPublic()
681 { 764 {
682 $this->conf->set('privacy.hide_public_links', true); 765 $this->conf->set('privacy.hide_public_links', true);
683 $linkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, false); 766 $linkDB = new BookmarkFileService($this->conf, $this->pluginManager, $this->history, $this->mutex, false);
684 767
685 $this->assertEquals(0, $linkDB->count()); 768 $this->assertEquals(0, $linkDB->count());
686 } 769 }
@@ -906,7 +989,13 @@ class BookmarkFileServiceTest extends TestCase
906 $bookmark->addAdditionalContentEntry('private_key', $privateKey); 989 $bookmark->addAdditionalContentEntry('private_key', $privateKey);
907 $this->privateLinkDB->save(); 990 $this->privateLinkDB->save();
908 991
909 $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, false); 992 $this->privateLinkDB = new BookmarkFileService(
993 $this->conf,
994 $this->pluginManager,
995 $this->history,
996 $this->mutex,
997 false
998 );
910 $bookmark = $this->privateLinkDB->findByHash($hash, $privateKey); 999 $bookmark = $this->privateLinkDB->findByHash($hash, $privateKey);
911 1000
912 static::assertSame(6, $bookmark->getId()); 1001 static::assertSame(6, $bookmark->getId());
@@ -1152,7 +1241,13 @@ class BookmarkFileServiceTest extends TestCase
1152 public function testGetLatestEmptyDatastore(): void 1241 public function testGetLatestEmptyDatastore(): void
1153 { 1242 {
1154 unlink($this->conf->get('resource.datastore')); 1243 unlink($this->conf->get('resource.datastore'));
1155 $this->publicLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, false); 1244 $this->publicLinkDB = new BookmarkFileService(
1245 $this->conf,
1246 $this->pluginManager,
1247 $this->history,
1248 $this->mutex,
1249 false
1250 );
1156 1251
1157 $bookmark = $this->publicLinkDB->getLatest(); 1252 $bookmark = $this->publicLinkDB->getLatest();
1158 1253
diff --git a/tests/bookmark/BookmarkFilterTest.php b/tests/bookmark/BookmarkFilterTest.php
index 835674f2..79be807d 100644
--- a/tests/bookmark/BookmarkFilterTest.php
+++ b/tests/bookmark/BookmarkFilterTest.php
@@ -6,6 +6,7 @@ use malkusch\lock\mutex\NoMutex;
6use ReferenceLinkDB; 6use ReferenceLinkDB;
7use Shaarli\Config\ConfigManager; 7use Shaarli\Config\ConfigManager;
8use Shaarli\History; 8use Shaarli\History;
9use Shaarli\Plugin\PluginManager;
9use Shaarli\TestCase; 10use Shaarli\TestCase;
10 11
11/** 12/**
@@ -32,19 +33,24 @@ class BookmarkFilterTest extends TestCase
32 */ 33 */
33 protected static $bookmarkService; 34 protected static $bookmarkService;
34 35
36 /** @var PluginManager */
37 protected static $pluginManager;
38
35 /** 39 /**
36 * Instantiate linkFilter with ReferenceLinkDB data. 40 * Instantiate linkFilter with ReferenceLinkDB data.
37 */ 41 */
38 public static function setUpBeforeClass(): void 42 public static function setUpBeforeClass(): void
39 { 43 {
44
40 $mutex = new NoMutex(); 45 $mutex = new NoMutex();
41 $conf = new ConfigManager('tests/utils/config/configJson'); 46 $conf = new ConfigManager('tests/utils/config/configJson');
42 $conf->set('resource.datastore', self::$testDatastore); 47 $conf->set('resource.datastore', self::$testDatastore);
48 static::$pluginManager = new PluginManager($conf);
43 self::$refDB = new \ReferenceLinkDB(); 49 self::$refDB = new \ReferenceLinkDB();
44 self::$refDB->write(self::$testDatastore); 50 self::$refDB->write(self::$testDatastore);
45 $history = new History('sandbox/history.php'); 51 $history = new History('sandbox/history.php');
46 self::$bookmarkService = new \FakeBookmarkService($conf, $history, $mutex, true); 52 self::$bookmarkService = new \FakeBookmarkService($conf, static::$pluginManager, $history, $mutex, true);
47 self::$linkFilter = new BookmarkFilter(self::$bookmarkService->getBookmarks(), $conf); 53 self::$linkFilter = new BookmarkFilter(self::$bookmarkService->getBookmarks(), $conf, static::$pluginManager);
48 } 54 }
49 55
50 /** 56 /**
@@ -179,61 +185,6 @@ class BookmarkFilterTest extends TestCase
179 } 185 }
180 186
181 /** 187 /**
182 * Return bookmarks for a given day
183 */
184 public function testFilterDay()
185 {
186 $this->assertEquals(
187 4,
188 count(self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, '20121206'))
189 );
190 }
191
192 /**
193 * Return bookmarks for a given day
194 */
195 public function testFilterDayRestrictedVisibility(): void
196 {
197 $this->assertEquals(
198 3,
199 count(self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, '20121206', false, BookmarkFilter::$PUBLIC))
200 );
201 }
202
203 /**
204 * 404 - day not found
205 */
206 public function testFilterUnknownDay()
207 {
208 $this->assertEquals(
209 0,
210 count(self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, '19700101'))
211 );
212 }
213
214 /**
215 * Use an invalid date format
216 */
217 public function testFilterInvalidDayWithChars()
218 {
219 $this->expectException(\Exception::class);
220 $this->expectExceptionMessageRegExp('/Invalid date format/');
221
222 self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, 'Rainy day, dream away');
223 }
224
225 /**
226 * Use an invalid date format
227 */
228 public function testFilterInvalidDayDigits()
229 {
230 $this->expectException(\Exception::class);
231 $this->expectExceptionMessageRegExp('/Invalid date format/');
232
233 self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, '20');
234 }
235
236 /**
237 * Retrieve a link entry with its hash 188 * Retrieve a link entry with its hash
238 */ 189 */
239 public function testFilterSmallHash() 190 public function testFilterSmallHash()
diff --git a/tests/bookmark/BookmarkInitializerTest.php b/tests/bookmark/BookmarkInitializerTest.php
index 0c8420ce..351807c1 100644
--- a/tests/bookmark/BookmarkInitializerTest.php
+++ b/tests/bookmark/BookmarkInitializerTest.php
@@ -5,6 +5,7 @@ namespace Shaarli\Bookmark;
5use malkusch\lock\mutex\NoMutex; 5use malkusch\lock\mutex\NoMutex;
6use Shaarli\Config\ConfigManager; 6use Shaarli\Config\ConfigManager;
7use Shaarli\History; 7use Shaarli\History;
8use Shaarli\Plugin\PluginManager;
8use Shaarli\TestCase; 9use Shaarli\TestCase;
9 10
10/** 11/**
@@ -38,6 +39,9 @@ class BookmarkInitializerTest extends TestCase
38 /** @var NoMutex */ 39 /** @var NoMutex */
39 protected $mutex; 40 protected $mutex;
40 41
42 /** @var PluginManager */
43 protected $pluginManager;
44
41 /** 45 /**
42 * Initialize an empty BookmarkFileService 46 * Initialize an empty BookmarkFileService
43 */ 47 */
@@ -51,8 +55,15 @@ class BookmarkInitializerTest extends TestCase
51 copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php'); 55 copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php');
52 $this->conf = new ConfigManager(self::$testConf); 56 $this->conf = new ConfigManager(self::$testConf);
53 $this->conf->set('resource.datastore', self::$testDatastore); 57 $this->conf->set('resource.datastore', self::$testDatastore);
58 $this->pluginManager = new PluginManager($this->conf);
54 $this->history = new History('sandbox/history.php'); 59 $this->history = new History('sandbox/history.php');
55 $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); 60 $this->bookmarkService = new BookmarkFileService(
61 $this->conf,
62 $this->pluginManager,
63 $this->history,
64 $this->mutex,
65 true
66 );
56 67
57 $this->initializer = new BookmarkInitializer($this->bookmarkService); 68 $this->initializer = new BookmarkInitializer($this->bookmarkService);
58 } 69 }
@@ -64,7 +75,13 @@ class BookmarkInitializerTest extends TestCase
64 { 75 {
65 $refDB = new \ReferenceLinkDB(); 76 $refDB = new \ReferenceLinkDB();
66 $refDB->write(self::$testDatastore); 77 $refDB->write(self::$testDatastore);
67 $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); 78 $this->bookmarkService = new BookmarkFileService(
79 $this->conf,
80 $this->pluginManager,
81 $this->history,
82 $this->mutex,
83 true
84 );
68 $this->initializer = new BookmarkInitializer($this->bookmarkService); 85 $this->initializer = new BookmarkInitializer($this->bookmarkService);
69 86
70 $this->initializer->initialize(); 87 $this->initializer->initialize();
@@ -95,7 +112,13 @@ class BookmarkInitializerTest extends TestCase
95 $this->bookmarkService->save(); 112 $this->bookmarkService->save();
96 113
97 // Reload from file 114 // Reload from file
98 $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); 115 $this->bookmarkService = new BookmarkFileService(
116 $this->conf,
117 $this->pluginManager,
118 $this->history,
119 $this->mutex,
120 true
121 );
99 $this->assertEquals($refDB->countLinks() + 3, $this->bookmarkService->count()); 122 $this->assertEquals($refDB->countLinks() + 3, $this->bookmarkService->count());
100 123
101 $bookmark = $this->bookmarkService->get(43); 124 $bookmark = $this->bookmarkService->get(43);
@@ -126,7 +149,13 @@ class BookmarkInitializerTest extends TestCase
126 public function testInitializeNonExistentDataStore(): void 149 public function testInitializeNonExistentDataStore(): void
127 { 150 {
128 $this->conf->set('resource.datastore', static::$testDatastore . '_empty'); 151 $this->conf->set('resource.datastore', static::$testDatastore . '_empty');
129 $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); 152 $this->bookmarkService = new BookmarkFileService(
153 $this->conf,
154 $this->pluginManager,
155 $this->history,
156 $this->mutex,
157 true
158 );
130 159
131 $this->initializer->initialize(); 160 $this->initializer->initialize();
132 161
diff --git a/tests/feed/FeedBuilderTest.php b/tests/feed/FeedBuilderTest.php
index 6b9204eb..fe092f78 100644
--- a/tests/feed/FeedBuilderTest.php
+++ b/tests/feed/FeedBuilderTest.php
@@ -11,6 +11,7 @@ use Shaarli\Bookmark\LinkDB;
11use Shaarli\Config\ConfigManager; 11use Shaarli\Config\ConfigManager;
12use Shaarli\Formatter\FormatterFactory; 12use Shaarli\Formatter\FormatterFactory;
13use Shaarli\History; 13use Shaarli\History;
14use Shaarli\Plugin\PluginManager;
14use Shaarli\TestCase; 15use Shaarli\TestCase;
15 16
16/** 17/**
@@ -55,8 +56,15 @@ class FeedBuilderTest extends TestCase
55 $refLinkDB->write(self::$testDatastore); 56 $refLinkDB->write(self::$testDatastore);
56 $history = new History('sandbox/history.php'); 57 $history = new History('sandbox/history.php');
57 $factory = new FormatterFactory($conf, true); 58 $factory = new FormatterFactory($conf, true);
59 $pluginManager = new PluginManager($conf);
58 self::$formatter = $factory->getFormatter(); 60 self::$formatter = $factory->getFormatter();
59 self::$bookmarkService = new BookmarkFileService($conf, $history, $mutex, true); 61 self::$bookmarkService = new BookmarkFileService(
62 $conf,
63 $pluginManager,
64 $history,
65 $mutex,
66 true
67 );
60 68
61 self::$serverInfo = array( 69 self::$serverInfo = array(
62 'HTTPS' => 'Off', 70 'HTTPS' => 'Off',
diff --git a/tests/netscape/BookmarkExportTest.php b/tests/netscape/BookmarkExportTest.php
index ad288f78..b8a88cd8 100644
--- a/tests/netscape/BookmarkExportTest.php
+++ b/tests/netscape/BookmarkExportTest.php
@@ -8,6 +8,7 @@ use Shaarli\Config\ConfigManager;
8use Shaarli\Formatter\BookmarkFormatter; 8use Shaarli\Formatter\BookmarkFormatter;
9use Shaarli\Formatter\FormatterFactory; 9use Shaarli\Formatter\FormatterFactory;
10use Shaarli\History; 10use Shaarli\History;
11use Shaarli\Plugin\PluginManager;
11use Shaarli\TestCase; 12use Shaarli\TestCase;
12 13
13require_once 'tests/utils/ReferenceLinkDB.php'; 14require_once 'tests/utils/ReferenceLinkDB.php';
@@ -47,6 +48,9 @@ class BookmarkExportTest extends TestCase
47 */ 48 */
48 protected static $history; 49 protected static $history;
49 50
51 /** @var PluginManager */
52 protected static $pluginManager;
53
50 /** 54 /**
51 * @var NetscapeBookmarkUtils 55 * @var NetscapeBookmarkUtils
52 */ 56 */
@@ -63,7 +67,14 @@ class BookmarkExportTest extends TestCase
63 static::$refDb = new \ReferenceLinkDB(); 67 static::$refDb = new \ReferenceLinkDB();
64 static::$refDb->write(static::$testDatastore); 68 static::$refDb->write(static::$testDatastore);
65 static::$history = new History('sandbox/history.php'); 69 static::$history = new History('sandbox/history.php');
66 static::$bookmarkService = new BookmarkFileService(static::$conf, static::$history, $mutex, true); 70 static::$pluginManager = new PluginManager(static::$conf);
71 static::$bookmarkService = new BookmarkFileService(
72 static::$conf,
73 static::$pluginManager,
74 static::$history,
75 $mutex,
76 true
77 );
67 $factory = new FormatterFactory(static::$conf, true); 78 $factory = new FormatterFactory(static::$conf, true);
68 static::$formatter = $factory->getFormatter('raw'); 79 static::$formatter = $factory->getFormatter('raw');
69 } 80 }
diff --git a/tests/netscape/BookmarkImportTest.php b/tests/netscape/BookmarkImportTest.php
index 6856ebca..ecd33ea1 100644
--- a/tests/netscape/BookmarkImportTest.php
+++ b/tests/netscape/BookmarkImportTest.php
@@ -10,6 +10,7 @@ use Shaarli\Bookmark\BookmarkFileService;
10use Shaarli\Bookmark\BookmarkFilter; 10use Shaarli\Bookmark\BookmarkFilter;
11use Shaarli\Config\ConfigManager; 11use Shaarli\Config\ConfigManager;
12use Shaarli\History; 12use Shaarli\History;
13use Shaarli\Plugin\PluginManager;
13use Shaarli\TestCase; 14use Shaarli\TestCase;
14use Slim\Http\UploadedFile; 15use Slim\Http\UploadedFile;
15 16
@@ -71,6 +72,9 @@ class BookmarkImportTest extends TestCase
71 */ 72 */
72 protected $netscapeBookmarkUtils; 73 protected $netscapeBookmarkUtils;
73 74
75 /** @var PluginManager */
76 protected $pluginManager;
77
74 /** 78 /**
75 * @var string Save the current timezone. 79 * @var string Save the current timezone.
76 */ 80 */
@@ -99,7 +103,14 @@ class BookmarkImportTest extends TestCase
99 $this->conf->set('resource.page_cache', $this->pagecache); 103 $this->conf->set('resource.page_cache', $this->pagecache);
100 $this->conf->set('resource.datastore', self::$testDatastore); 104 $this->conf->set('resource.datastore', self::$testDatastore);
101 $this->history = new History(self::$historyFilePath); 105 $this->history = new History(self::$historyFilePath);
102 $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $mutex, true); 106 $this->pluginManager = new PluginManager($this->conf);
107 $this->bookmarkService = new BookmarkFileService(
108 $this->conf,
109 $this->pluginManager,
110 $this->history,
111 $mutex,
112 true
113 );
103 $this->netscapeBookmarkUtils = new NetscapeBookmarkUtils($this->bookmarkService, $this->conf, $this->history); 114 $this->netscapeBookmarkUtils = new NetscapeBookmarkUtils($this->bookmarkService, $this->conf, $this->history);
104 } 115 }
105 116
diff --git a/tests/plugins/test/test.php b/tests/plugins/test/test.php
index 34cd339e..8dbb3f94 100644
--- a/tests/plugins/test/test.php
+++ b/tests/plugins/test/test.php
@@ -1,5 +1,7 @@
1<?php 1<?php
2 2
3use Shaarli\Bookmark\Bookmark;
4
3/** 5/**
4 * Hook for test. 6 * Hook for test.
5 * 7 *
@@ -43,3 +45,8 @@ function test_register_routes(): array
43 ], 45 ],
44 ]; 46 ];
45} 47}
48
49function hook_test_filter_search_entry(Bookmark $bookmark, array $context): bool
50{
51 return $context['_result'];
52}
diff --git a/tests/updater/UpdaterTest.php b/tests/updater/UpdaterTest.php
index cadd8265..a8539d63 100644
--- a/tests/updater/UpdaterTest.php
+++ b/tests/updater/UpdaterTest.php
@@ -7,6 +7,7 @@ use Shaarli\Bookmark\BookmarkFileService;
7use Shaarli\Bookmark\BookmarkServiceInterface; 7use Shaarli\Bookmark\BookmarkServiceInterface;
8use Shaarli\Config\ConfigManager; 8use Shaarli\Config\ConfigManager;
9use Shaarli\History; 9use Shaarli\History;
10use Shaarli\Plugin\PluginManager;
10use Shaarli\TestCase; 11use Shaarli\TestCase;
11 12
12 13
@@ -51,7 +52,13 @@ class UpdaterTest extends TestCase
51 52
52 copy('tests/utils/config/configJson.json.php', self::$configFile .'.json.php'); 53 copy('tests/utils/config/configJson.json.php', self::$configFile .'.json.php');
53 $this->conf = new ConfigManager(self::$configFile); 54 $this->conf = new ConfigManager(self::$configFile);
54 $this->bookmarkService = new BookmarkFileService($this->conf, $this->createMock(History::class), $mutex, true); 55 $this->bookmarkService = new BookmarkFileService(
56 $this->conf,
57 $this->createMock(PluginManager::class),
58 $this->createMock(History::class),
59 $mutex,
60 true
61 );
55 $this->updater = new Updater([], $this->bookmarkService, $this->conf, true); 62 $this->updater = new Updater([], $this->bookmarkService, $this->conf, true);
56 } 63 }
57 64