X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2Fbookmark%2FBookmarkFilterTest.php;fp=tests%2Fbookmark%2FBookmarkFilterTest.php;h=835674f2d6df2900efeba0c4d8a1022fae2a95b9;hb=1409f1c89a7ca01456ae2dcd6357d296e2b99f5a;hp=48c7f8247bc02ca32900886e7f7d86aac90027c8;hpb=054e03f37fa29da8066f1a637919f13c7e7dc5d2;p=github%2Fshaarli%2FShaarli.git diff --git a/tests/bookmark/BookmarkFilterTest.php b/tests/bookmark/BookmarkFilterTest.php index 48c7f824..835674f2 100644 --- a/tests/bookmark/BookmarkFilterTest.php +++ b/tests/bookmark/BookmarkFilterTest.php @@ -2,7 +2,7 @@ namespace Shaarli\Bookmark; -use Exception; +use malkusch\lock\mutex\NoMutex; use ReferenceLinkDB; use Shaarli\Config\ConfigManager; use Shaarli\History; @@ -37,13 +37,14 @@ class BookmarkFilterTest extends TestCase */ public static function setUpBeforeClass(): void { + $mutex = new NoMutex(); $conf = new ConfigManager('tests/utils/config/configJson'); $conf->set('resource.datastore', self::$testDatastore); self::$refDB = new \ReferenceLinkDB(); self::$refDB->write(self::$testDatastore); $history = new History('sandbox/history.php'); - self::$bookmarkService = new \FakeBookmarkService($conf, $history, true); - self::$linkFilter = new BookmarkFilter(self::$bookmarkService->getBookmarks()); + self::$bookmarkService = new \FakeBookmarkService($conf, $history, $mutex, true); + self::$linkFilter = new BookmarkFilter(self::$bookmarkService->getBookmarks(), $conf); } /** @@ -523,4 +524,43 @@ class BookmarkFilterTest extends TestCase )) ); } + + /** + * Test search result highlights in every field of bookmark reference #9. + */ + public function testFullTextSearchHighlight(): void + { + $bookmarks = self::$linkFilter->filter( + BookmarkFilter::$FILTER_TEXT, + '"psr-2" coding guide http fig "psr-2/" "This guide" basic standard. coding-style quality assurance' + ); + + static::assertCount(1, $bookmarks); + static::assertArrayHasKey(9, $bookmarks); + + $bookmark = $bookmarks[9]; + $expectedHighlights = [ + 'title' => [ + ['start' => 0, 'end' => 5], // "psr-2" + ['start' => 7, 'end' => 13], // coding + ['start' => 20, 'end' => 25], // guide + ], + 'description' => [ + ['start' => 0, 'end' => 10], // "This guide" + ['start' => 45, 'end' => 50], // basic + ['start' => 58, 'end' => 67], // standard. + ], + 'url' => [ + ['start' => 0, 'end' => 4], // http + ['start' => 15, 'end' => 18], // fig + ['start' => 27, 'end' => 33], // "psr-2/" + ], + 'tags' => [ + ['start' => 0, 'end' => 12], // coding-style + ['start' => 23, 'end' => 30], // quality + ['start' => 31, 'end' => 40], // assurance + ], + ]; + static::assertSame($expectedHighlights, $bookmark->getAdditionalContentEntry('search_highlight')); + } }