aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/bookmark/BookmarkFilterTest.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2021-02-04 11:11:33 +0100
committerGitHub <noreply@github.com>2021-02-04 11:11:33 +0100
commit9db1ccdf2ce8381e1f3acb581d3c6a6def095d8c (patch)
tree97a618b77d327a5f963c91522988e24db5a9e158 /tests/bookmark/BookmarkFilterTest.php
parent8997ae6c8e24286f7d47981eaf905e80d2481c10 (diff)
parentbcba6bd353161fab456b423e93571ab027d5423c (diff)
downloadShaarli-master.tar.gz
Shaarli-master.tar.zst
Shaarli-master.zip
Merge pull request #1698 from ArthurHoaro/feature/plugins-search-filterHEADmaster
New plugin hook: ability to add custom filters to Shaarli search engine
Diffstat (limited to 'tests/bookmark/BookmarkFilterTest.php')
-rw-r--r--tests/bookmark/BookmarkFilterTest.php65
1 files changed, 8 insertions, 57 deletions
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()