From f1a148ab92c061ac129b5b2976de02d45b6a71e7 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Mon, 12 Oct 2020 12:23:57 +0200 Subject: add search highlight unit tests --- tests/bookmark/BookmarkFileServiceTest.php | 16 ++++++++++++ tests/bookmark/BookmarkFilterTest.php | 40 +++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) (limited to 'tests/bookmark') diff --git a/tests/bookmark/BookmarkFileServiceTest.php b/tests/bookmark/BookmarkFileServiceTest.php index 42485c99..daafd250 100644 --- a/tests/bookmark/BookmarkFileServiceTest.php +++ b/tests/bookmark/BookmarkFileServiceTest.php @@ -748,6 +748,10 @@ class BookmarkFileServiceTest extends TestCase // They need to be grouped with the first case found - order by date DESC: `sTuff`. 'sTuff' => 2, 'ut' => 1, + 'assurance' => 1, + 'coding-style' => 1, + 'quality' => 1, + 'standards' => 1, ], $this->publicLinkDB->bookmarksCountPerTag() ); @@ -776,6 +780,10 @@ class BookmarkFileServiceTest extends TestCase 'tag3' => 1, 'tag4' => 1, 'ut' => 1, + 'assurance' => 1, + 'coding-style' => 1, + 'quality' => 1, + 'standards' => 1, ], $this->privateLinkDB->bookmarksCountPerTag() ); @@ -918,6 +926,10 @@ class BookmarkFileServiceTest extends TestCase 'tag4' => 1, 'ut' => 1, 'w3c' => 1, + 'assurance' => 1, + 'coding-style' => 1, + 'quality' => 1, + 'standards' => 1, ]; $tags = $this->privateLinkDB->bookmarksCountPerTag(); @@ -1016,6 +1028,10 @@ class BookmarkFileServiceTest extends TestCase 'stallman' => 1, 'ut' => 1, 'w3c' => 1, + 'assurance' => 1, + 'coding-style' => 1, + 'quality' => 1, + 'standards' => 1, ]; $bookmark = new Bookmark(); $bookmark->setTags(['newTagToCount', BookmarkMarkdownFormatter::NO_MD_TAG]); diff --git a/tests/bookmark/BookmarkFilterTest.php b/tests/bookmark/BookmarkFilterTest.php index 644abbc8..574d8e3f 100644 --- a/tests/bookmark/BookmarkFilterTest.php +++ b/tests/bookmark/BookmarkFilterTest.php @@ -2,7 +2,6 @@ namespace Shaarli\Bookmark; -use Exception; use malkusch\lock\mutex\NoMutex; use ReferenceLinkDB; use Shaarli\Config\ConfigManager; @@ -525,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')); + } } -- cgit v1.2.3