2015-12-27 10:08:20 +01:00
|
|
|
<?php
|
|
|
|
|
2018-12-03 01:22:45 +01:00
|
|
|
namespace Shaarli\Bookmark;
|
2018-12-03 01:10:39 +01:00
|
|
|
|
2020-09-26 14:18:01 +02:00
|
|
|
use malkusch\lock\mutex\NoMutex;
|
2018-12-03 01:22:45 +01:00
|
|
|
use ReferenceLinkDB;
|
2020-01-17 21:34:12 +01:00
|
|
|
use Shaarli\Config\ConfigManager;
|
|
|
|
use Shaarli\History;
|
2021-01-20 15:59:00 +01:00
|
|
|
use Shaarli\Plugin\PluginManager;
|
2020-09-29 14:41:40 +02:00
|
|
|
use Shaarli\TestCase;
|
2015-12-27 10:08:20 +01:00
|
|
|
|
|
|
|
/**
|
2020-01-17 21:34:12 +01:00
|
|
|
* Class BookmarkFilterTest.
|
2015-12-27 10:08:20 +01:00
|
|
|
*/
|
2020-01-17 21:34:12 +01:00
|
|
|
class BookmarkFilterTest extends TestCase
|
2015-12-27 10:08:20 +01:00
|
|
|
{
|
2017-09-02 15:10:44 +02:00
|
|
|
/**
|
|
|
|
* @var string Test datastore path.
|
|
|
|
*/
|
|
|
|
protected static $testDatastore = 'sandbox/datastore.php';
|
2015-12-27 10:08:20 +01:00
|
|
|
/**
|
2020-01-17 21:34:12 +01:00
|
|
|
* @var BookmarkFilter instance.
|
2015-12-27 10:08:20 +01:00
|
|
|
*/
|
|
|
|
protected static $linkFilter;
|
|
|
|
|
2017-01-16 13:57:11 +01:00
|
|
|
/**
|
|
|
|
* @var ReferenceLinkDB instance
|
|
|
|
*/
|
|
|
|
protected static $refDB;
|
|
|
|
|
2017-09-02 15:10:44 +02:00
|
|
|
/**
|
2020-01-17 21:34:12 +01:00
|
|
|
* @var BookmarkFileService instance
|
2017-09-02 15:10:44 +02:00
|
|
|
*/
|
2020-01-17 21:34:12 +01:00
|
|
|
protected static $bookmarkService;
|
2017-09-02 15:10:44 +02:00
|
|
|
|
2021-01-20 15:59:00 +01:00
|
|
|
/** @var PluginManager */
|
|
|
|
protected static $pluginManager;
|
|
|
|
|
2015-12-27 10:08:20 +01:00
|
|
|
/**
|
2018-12-03 01:22:45 +01:00
|
|
|
* Instantiate linkFilter with ReferenceLinkDB data.
|
2015-12-27 10:08:20 +01:00
|
|
|
*/
|
2020-09-06 14:11:02 +02:00
|
|
|
public static function setUpBeforeClass(): void
|
2015-12-27 10:08:20 +01:00
|
|
|
{
|
2021-01-20 15:59:00 +01:00
|
|
|
|
2020-09-26 14:18:01 +02:00
|
|
|
$mutex = new NoMutex();
|
2020-01-17 21:34:12 +01:00
|
|
|
$conf = new ConfigManager('tests/utils/config/configJson');
|
|
|
|
$conf->set('resource.datastore', self::$testDatastore);
|
2021-01-20 15:59:00 +01:00
|
|
|
static::$pluginManager = new PluginManager($conf);
|
2020-01-17 21:34:12 +01:00
|
|
|
self::$refDB = new \ReferenceLinkDB();
|
2017-09-02 15:10:44 +02:00
|
|
|
self::$refDB->write(self::$testDatastore);
|
2020-01-17 21:34:12 +01:00
|
|
|
$history = new History('sandbox/history.php');
|
2021-01-20 15:59:00 +01:00
|
|
|
self::$bookmarkService = new \FakeBookmarkService($conf, static::$pluginManager, $history, $mutex, true);
|
|
|
|
self::$linkFilter = new BookmarkFilter(self::$bookmarkService->getBookmarks(), $conf, static::$pluginManager);
|
2015-12-27 10:08:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Blank filter.
|
|
|
|
*/
|
|
|
|
public function testFilter()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
2017-01-16 13:57:11 +01:00
|
|
|
self::$refDB->countLinks(),
|
2015-12-27 10:08:20 +01:00
|
|
|
count(self::$linkFilter->filter('', ''))
|
|
|
|
);
|
|
|
|
|
2017-01-16 13:57:11 +01:00
|
|
|
$this->assertEquals(
|
|
|
|
self::$refDB->countLinks(),
|
|
|
|
count(self::$linkFilter->filter('', '', 'all'))
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
self::$refDB->countLinks(),
|
|
|
|
count(self::$linkFilter->filter('', '', 'randomstr'))
|
|
|
|
);
|
|
|
|
|
2015-12-27 10:08:20 +01:00
|
|
|
// Private only.
|
|
|
|
$this->assertEquals(
|
2017-01-16 13:57:11 +01:00
|
|
|
self::$refDB->countPrivateLinks(),
|
|
|
|
count(self::$linkFilter->filter('', '', false, 'private'))
|
|
|
|
);
|
|
|
|
|
|
|
|
// Public only.
|
|
|
|
$this->assertEquals(
|
|
|
|
self::$refDB->countPublicLinks(),
|
|
|
|
count(self::$linkFilter->filter('', '', false, 'public'))
|
2015-12-27 10:08:20 +01:00
|
|
|
);
|
2016-02-23 19:21:14 +01:00
|
|
|
|
|
|
|
$this->assertEquals(
|
2016-03-12 17:54:56 +01:00
|
|
|
ReferenceLinkDB::$NB_LINKS_TOTAL,
|
2020-01-17 21:34:12 +01:00
|
|
|
count(self::$linkFilter->filter(BookmarkFilter::$FILTER_TAG, ''))
|
2016-02-23 19:21:14 +01:00
|
|
|
);
|
|
|
|
|
2017-04-01 12:17:37 +02:00
|
|
|
$this->assertEquals(
|
|
|
|
self::$refDB->countUntaggedLinks(),
|
2018-10-13 01:40:04 +02:00
|
|
|
count(
|
|
|
|
self::$linkFilter->filter(
|
2020-01-17 21:34:12 +01:00
|
|
|
BookmarkFilter::$FILTER_TAG,
|
2018-12-03 01:22:45 +01:00
|
|
|
/*$request=*/
|
|
|
|
'',
|
|
|
|
/*$casesensitive=*/
|
|
|
|
false,
|
|
|
|
/*$visibility=*/
|
|
|
|
'all',
|
|
|
|
/*$untaggedonly=*/
|
|
|
|
true
|
2018-10-13 01:40:04 +02:00
|
|
|
)
|
|
|
|
)
|
2017-04-01 12:17:37 +02:00
|
|
|
);
|
|
|
|
|
2016-02-23 19:21:14 +01:00
|
|
|
$this->assertEquals(
|
2016-03-12 17:54:56 +01:00
|
|
|
ReferenceLinkDB::$NB_LINKS_TOTAL,
|
2020-01-17 21:34:12 +01:00
|
|
|
count(self::$linkFilter->filter(BookmarkFilter::$FILTER_TEXT, ''))
|
2016-02-23 19:21:14 +01:00
|
|
|
);
|
2015-12-27 10:08:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-01-17 21:34:12 +01:00
|
|
|
* Filter bookmarks using a tag
|
2015-12-27 10:08:20 +01:00
|
|
|
*/
|
|
|
|
public function testFilterOneTag()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
4,
|
2020-01-17 21:34:12 +01:00
|
|
|
count(self::$linkFilter->filter(BookmarkFilter::$FILTER_TAG, 'web', false))
|
2015-12-27 10:08:20 +01:00
|
|
|
);
|
|
|
|
|
2017-01-16 13:57:11 +01:00
|
|
|
$this->assertEquals(
|
|
|
|
4,
|
2020-01-17 21:34:12 +01:00
|
|
|
count(self::$linkFilter->filter(BookmarkFilter::$FILTER_TAG, 'web', false, 'all'))
|
2017-01-16 13:57:11 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
4,
|
2020-01-17 21:34:12 +01:00
|
|
|
count(self::$linkFilter->filter(BookmarkFilter::$FILTER_TAG, 'web', false, 'default-blabla'))
|
2017-01-16 13:57:11 +01:00
|
|
|
);
|
|
|
|
|
2015-12-27 10:08:20 +01:00
|
|
|
// Private only.
|
|
|
|
$this->assertEquals(
|
|
|
|
1,
|
2020-01-17 21:34:12 +01:00
|
|
|
count(self::$linkFilter->filter(BookmarkFilter::$FILTER_TAG, 'web', false, 'private'))
|
2017-01-16 13:57:11 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
// Public only.
|
|
|
|
$this->assertEquals(
|
|
|
|
3,
|
2020-01-17 21:34:12 +01:00
|
|
|
count(self::$linkFilter->filter(BookmarkFilter::$FILTER_TAG, 'web', false, 'public'))
|
2015-12-27 10:08:20 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-01-17 21:34:12 +01:00
|
|
|
* Filter bookmarks using a tag - case-sensitive
|
2015-12-27 10:08:20 +01:00
|
|
|
*/
|
|
|
|
public function testFilterCaseSensitiveTag()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
0,
|
2020-01-17 21:34:12 +01:00
|
|
|
count(self::$linkFilter->filter(BookmarkFilter::$FILTER_TAG, 'mercurial', true))
|
2015-12-27 10:08:20 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
1,
|
2020-01-17 21:34:12 +01:00
|
|
|
count(self::$linkFilter->filter(BookmarkFilter::$FILTER_TAG, 'Mercurial', true))
|
2015-12-27 10:08:20 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-01-17 21:34:12 +01:00
|
|
|
* Filter bookmarks using a tag combination
|
2015-12-27 10:08:20 +01:00
|
|
|
*/
|
|
|
|
public function testFilterMultipleTags()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
2,
|
2020-01-17 21:34:12 +01:00
|
|
|
count(self::$linkFilter->filter(BookmarkFilter::$FILTER_TAG, 'dev cartoon', false))
|
2015-12-27 10:08:20 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-01-17 21:34:12 +01:00
|
|
|
* Filter bookmarks using a non-existent tag
|
2015-12-27 10:08:20 +01:00
|
|
|
*/
|
|
|
|
public function testFilterUnknownTag()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
0,
|
2020-01-17 21:34:12 +01:00
|
|
|
count(self::$linkFilter->filter(BookmarkFilter::$FILTER_TAG, 'null', false))
|
2015-12-27 10:08:20 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve a link entry with its hash
|
|
|
|
*/
|
|
|
|
public function testFilterSmallHash()
|
|
|
|
{
|
2020-01-17 21:34:12 +01:00
|
|
|
$links = self::$linkFilter->filter(BookmarkFilter::$FILTER_HASH, 'IuWvgA');
|
2015-12-27 10:08:20 +01:00
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
1,
|
|
|
|
count($links)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
'MediaGoblin',
|
2020-01-17 21:34:12 +01:00
|
|
|
$links[7]->getTitle()
|
2015-12-27 10:08:20 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* No link for this hash
|
|
|
|
*/
|
|
|
|
public function testFilterUnknownSmallHash()
|
|
|
|
{
|
2020-09-27 14:07:08 +02:00
|
|
|
$this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class);
|
|
|
|
|
2020-01-17 21:34:12 +01:00
|
|
|
self::$linkFilter->filter(BookmarkFilter::$FILTER_HASH, 'Iblaah');
|
2015-12-27 10:08:20 +01:00
|
|
|
}
|
|
|
|
|
2016-02-02 19:42:48 +01:00
|
|
|
/**
|
|
|
|
* Full-text search - no result found.
|
|
|
|
*/
|
|
|
|
public function testFilterFullTextNoResult()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
0,
|
2020-01-17 21:34:12 +01:00
|
|
|
count(self::$linkFilter->filter(BookmarkFilter::$FILTER_TEXT, 'azertyuiop'))
|
2016-02-02 19:42:48 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-12-27 10:08:20 +01:00
|
|
|
/**
|
|
|
|
* Full-text search - result from a link's URL
|
|
|
|
*/
|
|
|
|
public function testFilterFullTextURL()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
2,
|
2020-01-17 21:34:12 +01:00
|
|
|
count(self::$linkFilter->filter(BookmarkFilter::$FILTER_TEXT, 'ars.userfriendly.org'))
|
2015-12-27 10:08:20 +01:00
|
|
|
);
|
2018-10-13 01:40:04 +02:00
|
|
|
|
2016-01-24 07:13:11 +01:00
|
|
|
$this->assertEquals(
|
|
|
|
2,
|
2020-01-17 21:34:12 +01:00
|
|
|
count(self::$linkFilter->filter(BookmarkFilter::$FILTER_TEXT, 'ars org'))
|
2016-01-24 07:13:11 +01:00
|
|
|
);
|
2015-12-27 10:08:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Full-text search - result from a link's title only
|
|
|
|
*/
|
|
|
|
public function testFilterFullTextTitle()
|
|
|
|
{
|
|
|
|
// use miscellaneous cases
|
|
|
|
$this->assertEquals(
|
|
|
|
2,
|
2020-01-17 21:34:12 +01:00
|
|
|
count(self::$linkFilter->filter(BookmarkFilter::$FILTER_TEXT, 'userfriendly -'))
|
2015-12-27 10:08:20 +01:00
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
2,
|
2020-01-17 21:34:12 +01:00
|
|
|
count(self::$linkFilter->filter(BookmarkFilter::$FILTER_TEXT, 'UserFriendly -'))
|
2015-12-27 10:08:20 +01:00
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
2,
|
2020-01-17 21:34:12 +01:00
|
|
|
count(self::$linkFilter->filter(BookmarkFilter::$FILTER_TEXT, 'uSeRFrIendlY -'))
|
2015-12-27 10:08:20 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
// use miscellaneous case and offset
|
|
|
|
$this->assertEquals(
|
|
|
|
2,
|
2020-01-17 21:34:12 +01:00
|
|
|
count(self::$linkFilter->filter(BookmarkFilter::$FILTER_TEXT, 'RFrIendL'))
|
2015-12-27 10:08:20 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Full-text search - result from the link's description only
|
|
|
|
*/
|
|
|
|
public function testFilterFullTextDescription()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
1,
|
2020-01-17 21:34:12 +01:00
|
|
|
count(self::$linkFilter->filter(BookmarkFilter::$FILTER_TEXT, 'publishing media'))
|
2016-01-24 07:13:11 +01:00
|
|
|
);
|
2018-10-13 01:40:04 +02:00
|
|
|
|
2016-01-24 07:13:11 +01:00
|
|
|
$this->assertEquals(
|
|
|
|
1,
|
2020-01-17 21:34:12 +01:00
|
|
|
count(self::$linkFilter->filter(BookmarkFilter::$FILTER_TEXT, 'mercurial w3c'))
|
2015-12-27 10:08:20 +01:00
|
|
|
);
|
2018-10-13 01:40:04 +02:00
|
|
|
|
2016-01-24 07:13:11 +01:00
|
|
|
$this->assertEquals(
|
2016-02-01 20:33:58 +01:00
|
|
|
3,
|
2020-01-17 21:34:12 +01:00
|
|
|
count(self::$linkFilter->filter(BookmarkFilter::$FILTER_TEXT, '"free software"'))
|
2018-10-13 00:35:47 +02:00
|
|
|
);
|
2015-12-27 10:08:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Full-text search - result from the link's tags only
|
|
|
|
*/
|
|
|
|
public function testFilterFullTextTags()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
2017-01-16 13:57:11 +01:00
|
|
|
6,
|
2020-01-17 21:34:12 +01:00
|
|
|
count(self::$linkFilter->filter(BookmarkFilter::$FILTER_TEXT, 'web'))
|
2017-01-16 13:57:11 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
6,
|
2020-01-17 21:34:12 +01:00
|
|
|
count(self::$linkFilter->filter(BookmarkFilter::$FILTER_TEXT, 'web', 'all'))
|
2017-01-16 13:57:11 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
6,
|
2020-01-17 21:34:12 +01:00
|
|
|
count(self::$linkFilter->filter(BookmarkFilter::$FILTER_TEXT, 'web', 'bla'))
|
2015-12-27 10:08:20 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
// Private only.
|
|
|
|
$this->assertEquals(
|
|
|
|
1,
|
2020-01-17 21:34:12 +01:00
|
|
|
count(self::$linkFilter->filter(BookmarkFilter::$FILTER_TEXT, 'web', false, 'private'))
|
2017-01-16 13:57:11 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
// Public only.
|
|
|
|
$this->assertEquals(
|
|
|
|
5,
|
2020-01-17 21:34:12 +01:00
|
|
|
count(self::$linkFilter->filter(BookmarkFilter::$FILTER_TEXT, 'web', false, 'public'))
|
2015-12-27 10:08:20 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Full-text search - result set from mixed sources
|
|
|
|
*/
|
|
|
|
public function testFilterFullTextMixed()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
2016-02-01 20:33:58 +01:00
|
|
|
3,
|
2020-01-17 21:34:12 +01:00
|
|
|
count(self::$linkFilter->filter(BookmarkFilter::$FILTER_TEXT, 'free software'))
|
2015-12-27 10:08:20 +01:00
|
|
|
);
|
|
|
|
}
|
2016-01-20 23:34:33 +01:00
|
|
|
|
2016-02-01 20:33:58 +01:00
|
|
|
/**
|
|
|
|
* Full-text search - test exclusion with '-'.
|
|
|
|
*/
|
|
|
|
public function testExcludeSearch()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
1,
|
2020-01-17 21:34:12 +01:00
|
|
|
count(self::$linkFilter->filter(BookmarkFilter::$FILTER_TEXT, 'free -gnu'))
|
2016-02-01 20:33:58 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
2017-04-01 12:17:37 +02:00
|
|
|
ReferenceLinkDB::$NB_LINKS_TOTAL - 1,
|
2020-01-17 21:34:12 +01:00
|
|
|
count(self::$linkFilter->filter(BookmarkFilter::$FILTER_TEXT, '-revolution'))
|
2016-02-01 20:33:58 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-02-02 19:42:48 +01:00
|
|
|
* Full-text search - test AND, exact terms and exclusion combined, across fields.
|
2016-02-01 20:33:58 +01:00
|
|
|
*/
|
|
|
|
public function testMultiSearch()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
2,
|
2016-02-02 19:42:48 +01:00
|
|
|
count(self::$linkFilter->filter(
|
2020-01-17 21:34:12 +01:00
|
|
|
BookmarkFilter::$FILTER_TEXT,
|
2016-02-02 19:42:48 +01:00
|
|
|
'"Free Software " stallman "read this" @website stuff'
|
|
|
|
))
|
2016-02-01 20:33:58 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
1,
|
2016-02-02 19:42:48 +01:00
|
|
|
count(self::$linkFilter->filter(
|
2020-01-17 21:34:12 +01:00
|
|
|
BookmarkFilter::$FILTER_TEXT,
|
2016-02-02 19:42:48 +01:00
|
|
|
'"free software " stallman "read this" -beard @website stuff'
|
|
|
|
))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Full-text search - make sure that exact search won't work across fields.
|
|
|
|
*/
|
|
|
|
public function testSearchExactTermMultiFieldsKo()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
0,
|
|
|
|
count(self::$linkFilter->filter(
|
2020-01-17 21:34:12 +01:00
|
|
|
BookmarkFilter::$FILTER_TEXT,
|
2016-02-02 19:42:48 +01:00
|
|
|
'"designer naming"'
|
|
|
|
))
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
0,
|
|
|
|
count(self::$linkFilter->filter(
|
2020-01-17 21:34:12 +01:00
|
|
|
BookmarkFilter::$FILTER_TEXT,
|
2016-02-02 19:42:48 +01:00
|
|
|
'"designernaming"'
|
|
|
|
))
|
2016-02-01 20:33:58 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-01-20 23:34:33 +01:00
|
|
|
/**
|
|
|
|
* Tag search with exclusion.
|
|
|
|
*/
|
|
|
|
public function testTagFilterWithExclusion()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
1,
|
2020-01-17 21:34:12 +01:00
|
|
|
count(self::$linkFilter->filter(BookmarkFilter::$FILTER_TAG, 'gnu -free'))
|
2016-01-20 23:34:33 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
2017-04-01 12:17:37 +02:00
|
|
|
ReferenceLinkDB::$NB_LINKS_TOTAL - 1,
|
2020-01-17 21:34:12 +01:00
|
|
|
count(self::$linkFilter->filter(BookmarkFilter::$FILTER_TAG, '-free'))
|
2016-01-20 23:34:33 +01:00
|
|
|
);
|
|
|
|
}
|
2016-02-23 19:21:14 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test crossed search (terms + tags).
|
|
|
|
*/
|
|
|
|
public function testFilterCrossedSearch()
|
|
|
|
{
|
|
|
|
$terms = '"Free Software " stallman "read this" @website stuff';
|
|
|
|
$tags = 'free';
|
|
|
|
$this->assertEquals(
|
|
|
|
1,
|
|
|
|
count(self::$linkFilter->filter(
|
2020-01-17 21:34:12 +01:00
|
|
|
BookmarkFilter::$FILTER_TAG | BookmarkFilter::$FILTER_TEXT,
|
2021-04-05 09:39:34 +02:00
|
|
|
[$tags, $terms]
|
2016-02-23 19:21:14 +01:00
|
|
|
))
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
2,
|
|
|
|
count(self::$linkFilter->filter(
|
2020-01-17 21:34:12 +01:00
|
|
|
BookmarkFilter::$FILTER_TAG | BookmarkFilter::$FILTER_TEXT,
|
2021-04-05 09:39:34 +02:00
|
|
|
['', $terms]
|
2016-02-23 19:21:14 +01:00
|
|
|
))
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
2017-04-01 12:17:37 +02:00
|
|
|
1,
|
|
|
|
count(self::$linkFilter->filter(
|
2020-01-17 21:34:12 +01:00
|
|
|
BookmarkFilter::$FILTER_TAG | BookmarkFilter::$FILTER_TEXT,
|
2021-04-05 09:39:34 +02:00
|
|
|
[false, 'PSR-2']
|
2017-04-01 12:17:37 +02:00
|
|
|
))
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
2016-02-23 19:21:14 +01:00
|
|
|
1,
|
|
|
|
count(self::$linkFilter->filter(
|
2020-01-17 21:34:12 +01:00
|
|
|
BookmarkFilter::$FILTER_TAG | BookmarkFilter::$FILTER_TEXT,
|
2021-04-05 09:39:34 +02:00
|
|
|
[$tags, '']
|
2016-02-23 19:21:14 +01:00
|
|
|
))
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
2016-03-12 17:54:56 +01:00
|
|
|
ReferenceLinkDB::$NB_LINKS_TOTAL,
|
2016-02-23 19:21:14 +01:00
|
|
|
count(self::$linkFilter->filter(
|
2020-01-17 21:34:12 +01:00
|
|
|
BookmarkFilter::$FILTER_TAG | BookmarkFilter::$FILTER_TEXT,
|
2016-02-23 19:21:14 +01:00
|
|
|
''
|
|
|
|
))
|
|
|
|
);
|
|
|
|
}
|
2016-05-10 23:18:04 +02:00
|
|
|
|
|
|
|
/**
|
2020-01-17 21:34:12 +01:00
|
|
|
* Filter bookmarks by #hashtag.
|
2016-05-10 23:18:04 +02:00
|
|
|
*/
|
|
|
|
public function testFilterByHashtag()
|
|
|
|
{
|
|
|
|
$hashtag = 'hashtag';
|
|
|
|
$this->assertEquals(
|
|
|
|
3,
|
|
|
|
count(self::$linkFilter->filter(
|
2020-01-17 21:34:12 +01:00
|
|
|
BookmarkFilter::$FILTER_TAG,
|
2016-05-10 23:18:04 +02:00
|
|
|
$hashtag
|
|
|
|
))
|
|
|
|
);
|
|
|
|
|
|
|
|
$hashtag = 'private';
|
|
|
|
$this->assertEquals(
|
|
|
|
1,
|
|
|
|
count(self::$linkFilter->filter(
|
2020-01-17 21:34:12 +01:00
|
|
|
BookmarkFilter::$FILTER_TAG,
|
2016-05-10 23:18:04 +02:00
|
|
|
$hashtag,
|
|
|
|
false,
|
2017-01-16 13:57:11 +01:00
|
|
|
'private'
|
2016-05-10 23:18:04 +02:00
|
|
|
))
|
|
|
|
);
|
|
|
|
}
|
2020-10-12 12:23:57 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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'));
|
|
|
|
}
|
2015-12-27 10:08:20 +01:00
|
|
|
}
|