aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/bookmark
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-10-12 12:23:57 +0200
committerArthurHoaro <arthur@hoa.ro>2020-10-16 20:31:49 +0200
commitf1a148ab92c061ac129b5b2976de02d45b6a71e7 (patch)
tree89b085ac6c4cd7608526f855f452d1a797dbb333 /tests/bookmark
parent4e3875c0ce7f3b17e3d358dc5ecb1f8bed64546b (diff)
downloadShaarli-f1a148ab92c061ac129b5b2976de02d45b6a71e7.tar.gz
Shaarli-f1a148ab92c061ac129b5b2976de02d45b6a71e7.tar.zst
Shaarli-f1a148ab92c061ac129b5b2976de02d45b6a71e7.zip
add search highlight unit tests
Diffstat (limited to 'tests/bookmark')
-rw-r--r--tests/bookmark/BookmarkFileServiceTest.php16
-rw-r--r--tests/bookmark/BookmarkFilterTest.php40
2 files changed, 55 insertions, 1 deletions
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
748 // They need to be grouped with the first case found - order by date DESC: `sTuff`. 748 // They need to be grouped with the first case found - order by date DESC: `sTuff`.
749 'sTuff' => 2, 749 'sTuff' => 2,
750 'ut' => 1, 750 'ut' => 1,
751 'assurance' => 1,
752 'coding-style' => 1,
753 'quality' => 1,
754 'standards' => 1,
751 ], 755 ],
752 $this->publicLinkDB->bookmarksCountPerTag() 756 $this->publicLinkDB->bookmarksCountPerTag()
753 ); 757 );
@@ -776,6 +780,10 @@ class BookmarkFileServiceTest extends TestCase
776 'tag3' => 1, 780 'tag3' => 1,
777 'tag4' => 1, 781 'tag4' => 1,
778 'ut' => 1, 782 'ut' => 1,
783 'assurance' => 1,
784 'coding-style' => 1,
785 'quality' => 1,
786 'standards' => 1,
779 ], 787 ],
780 $this->privateLinkDB->bookmarksCountPerTag() 788 $this->privateLinkDB->bookmarksCountPerTag()
781 ); 789 );
@@ -918,6 +926,10 @@ class BookmarkFileServiceTest extends TestCase
918 'tag4' => 1, 926 'tag4' => 1,
919 'ut' => 1, 927 'ut' => 1,
920 'w3c' => 1, 928 'w3c' => 1,
929 'assurance' => 1,
930 'coding-style' => 1,
931 'quality' => 1,
932 'standards' => 1,
921 ]; 933 ];
922 $tags = $this->privateLinkDB->bookmarksCountPerTag(); 934 $tags = $this->privateLinkDB->bookmarksCountPerTag();
923 935
@@ -1016,6 +1028,10 @@ class BookmarkFileServiceTest extends TestCase
1016 'stallman' => 1, 1028 'stallman' => 1,
1017 'ut' => 1, 1029 'ut' => 1,
1018 'w3c' => 1, 1030 'w3c' => 1,
1031 'assurance' => 1,
1032 'coding-style' => 1,
1033 'quality' => 1,
1034 'standards' => 1,
1019 ]; 1035 ];
1020 $bookmark = new Bookmark(); 1036 $bookmark = new Bookmark();
1021 $bookmark->setTags(['newTagToCount', BookmarkMarkdownFormatter::NO_MD_TAG]); 1037 $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 @@
2 2
3namespace Shaarli\Bookmark; 3namespace Shaarli\Bookmark;
4 4
5use Exception;
6use malkusch\lock\mutex\NoMutex; 5use malkusch\lock\mutex\NoMutex;
7use ReferenceLinkDB; 6use ReferenceLinkDB;
8use Shaarli\Config\ConfigManager; 7use Shaarli\Config\ConfigManager;
@@ -525,4 +524,43 @@ class BookmarkFilterTest extends TestCase
525 )) 524 ))
526 ); 525 );
527 } 526 }
527
528 /**
529 * Test search result highlights in every field of bookmark reference #9.
530 */
531 public function testFullTextSearchHighlight(): void
532 {
533 $bookmarks = self::$linkFilter->filter(
534 BookmarkFilter::$FILTER_TEXT,
535 '"psr-2" coding guide http fig "psr-2/" "This guide" basic standard. coding-style quality assurance'
536 );
537
538 static::assertCount(1, $bookmarks);
539 static::assertArrayHasKey(9, $bookmarks);
540
541 $bookmark = $bookmarks[9];
542 $expectedHighlights = [
543 'title' => [
544 ['start' => 0, 'end' => 5], // "psr-2"
545 ['start' => 7, 'end' => 13], // coding
546 ['start' => 20, 'end' => 25], // guide
547 ],
548 'description' => [
549 ['start' => 0, 'end' => 10], // "This guide"
550 ['start' => 45, 'end' => 50], // basic
551 ['start' => 58, 'end' => 67], // standard.
552 ],
553 'url' => [
554 ['start' => 0, 'end' => 4], // http
555 ['start' => 15, 'end' => 18], // fig
556 ['start' => 27, 'end' => 33], // "psr-2/"
557 ],
558 'tags' => [
559 ['start' => 0, 'end' => 12], // coding-style
560 ['start' => 23, 'end' => 30], // quality
561 ['start' => 31, 'end' => 40], // assurance
562 ],
563 ];
564 static::assertSame($expectedHighlights, $bookmark->getAdditionalContentEntry('search_highlight'));
565 }
528} 566}