X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2Fbookmark%2FBookmarkFilterTest.php;h=79be807dc625767badc6752ac971b85e0652d8a2;hb=bcba6bd353161fab456b423e93571ab027d5423c;hp=91e139c20e283ad59982001ce04064fcfcccaa41;hpb=e2dff28b44fafcf11a1db7985c50cd40e6945821;p=github%2Fshaarli%2FShaarli.git diff --git a/tests/bookmark/BookmarkFilterTest.php b/tests/bookmark/BookmarkFilterTest.php index 91e139c2..79be807d 100644 --- a/tests/bookmark/BookmarkFilterTest.php +++ b/tests/bookmark/BookmarkFilterTest.php @@ -2,11 +2,12 @@ namespace Shaarli\Bookmark; -use Exception; -use PHPUnit\Framework\TestCase; +use malkusch\lock\mutex\NoMutex; use ReferenceLinkDB; use Shaarli\Config\ConfigManager; use Shaarli\History; +use Shaarli\Plugin\PluginManager; +use Shaarli\TestCase; /** * Class BookmarkFilterTest. @@ -32,18 +33,24 @@ class BookmarkFilterTest extends TestCase */ protected static $bookmarkService; + /** @var PluginManager */ + protected static $pluginManager; + /** * Instantiate linkFilter with ReferenceLinkDB data. */ public static function setUpBeforeClass(): void { + + $mutex = new NoMutex(); $conf = new ConfigManager('tests/utils/config/configJson'); $conf->set('resource.datastore', self::$testDatastore); + static::$pluginManager = new PluginManager($conf); 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, static::$pluginManager, $history, $mutex, true); + self::$linkFilter = new BookmarkFilter(self::$bookmarkService->getBookmarks(), $conf, static::$pluginManager); } /** @@ -177,59 +184,6 @@ class BookmarkFilterTest extends TestCase ); } - /** - * Return bookmarks for a given day - */ - public function testFilterDay() - { - $this->assertEquals( - 4, - count(self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, '20121206')) - ); - } - - /** - * Return bookmarks for a given day - */ - public function testFilterDayRestrictedVisibility(): void - { - $this->assertEquals( - 3, - count(self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, '20121206', false, BookmarkFilter::$PUBLIC)) - ); - } - - /** - * 404 - day not found - */ - public function testFilterUnknownDay() - { - $this->assertEquals( - 0, - count(self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, '19700101')) - ); - } - - /** - * Use an invalid date format - * @expectedException Exception - * @expectedExceptionMessageRegExp /Invalid date format/ - */ - public function testFilterInvalidDayWithChars() - { - self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, 'Rainy day, dream away'); - } - - /** - * Use an invalid date format - * @expectedException Exception - * @expectedExceptionMessageRegExp /Invalid date format/ - */ - public function testFilterInvalidDayDigits() - { - self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, '20'); - } - /** * Retrieve a link entry with its hash */ @@ -250,11 +204,11 @@ class BookmarkFilterTest extends TestCase /** * No link for this hash - * - * @expectedException \Shaarli\Bookmark\Exception\BookmarkNotFoundException */ public function testFilterUnknownSmallHash() { + $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class); + self::$linkFilter->filter(BookmarkFilter::$FILTER_HASH, 'Iblaah'); } @@ -521,4 +475,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')); + } }