6 namespace Shaarli\Bookmark
;
9 use PHPUnit\Framework\TestCase
;
13 use Shaarli\Bookmark\Exception\BookmarkNotFoundException
;
14 use Shaarli\Config\ConfigManager
;
18 * Unitary tests for LegacyLinkDBTest
20 class BookmarkFileServiceTest
extends TestCase
22 // datastore to test write operations
23 protected static $testDatastore = 'sandbox/datastore.php';
25 protected static $testConf = 'sandbox/config';
27 protected static $testUpdates = 'sandbox/updates.txt';
30 * @var ConfigManager instance.
35 * @var History instance.
40 * @var ReferenceLinkDB instance.
42 protected $refDB = null;
45 * @var BookmarkFileService public LinkDB instance.
47 protected $publicLinkDB = null;
50 * @var BookmarkFileService private LinkDB instance.
52 protected $privateLinkDB = null;
55 * Instantiates public and private LinkDBs with test data
57 * The reference datastore contains public and private bookmarks that
58 * will be used to test LinkDB's methods:
59 * - access filtering (public/private),
66 * Resets test data for each test
68 protected function setUp()
70 if (file_exists(self
::$testDatastore)) {
71 unlink(self
::$testDatastore);
74 if (file_exists(self
::$testConf .'.json.php')) {
75 unlink(self
::$testConf .'.json.php');
78 if (file_exists(self
::$testUpdates)) {
79 unlink(self
::$testUpdates);
82 copy('tests/utils/config/configJson.json.php', self
::$testConf .'.json.php');
83 $this->conf
= new ConfigManager(self
::$testConf);
84 $this->conf
->set('resource.datastore', self
::$testDatastore);
85 $this->conf
->set('resource.updates', self
::$testUpdates);
86 $this->refDB
= new \
ReferenceLinkDB();
87 $this->refDB
->write(self
::$testDatastore);
88 $this->history
= new History('sandbox/history.php');
89 $this->publicLinkDB
= new BookmarkFileService($this->conf
, $this->history
, false);
90 $this->privateLinkDB
= new BookmarkFileService($this->conf
, $this->history
, true);
94 * Test migrate() method with a legacy datastore.
96 public function testDatabaseMigration()
98 if (!defined('SHAARLI_VERSION')) {
99 define('SHAARLI_VERSION', 'dev');
102 $this->refDB
= new \
ReferenceLinkDB(true);
103 $this->refDB
->write(self
::$testDatastore);
104 $db = self
::getMethod('migrate');
105 $db->invokeArgs($this->privateLinkDB
, []);
107 $db = new \
FakeBookmarkService($this->conf
, $this->history
, true);
108 $this->assertInstanceOf(BookmarkArray
::class, $db->getBookmarks());
109 $this->assertEquals($this->refDB
->countLinks(), $db->count());
113 * Test get() method for a defined and saved bookmark
115 public function testGetDefinedSaved()
117 $bookmark = $this->privateLinkDB
->get(42);
118 $this->assertEquals(42, $bookmark->getId());
119 $this->assertEquals('Note: I have a big ID but an old date', $bookmark->getTitle());
123 * Test get() method for a defined and not saved bookmark
125 public function testGetDefinedNotSaved()
127 $bookmark = new Bookmark();
128 $this->privateLinkDB
->add($bookmark);
129 $createdBookmark = $this->privateLinkDB
->get(43);
130 $this->assertEquals(43, $createdBookmark->getId());
131 $this->assertEmpty($createdBookmark->getDescription());
135 * Test get() method for an undefined bookmark
137 * @expectedException Shaarli\Bookmark\Exception\BookmarkNotFoundException
139 public function testGetUndefined()
141 $this->privateLinkDB
->get(666);
145 * Test add() method for a bookmark fully built
147 public function testAddFull()
149 $bookmark = new Bookmark();
150 $bookmark->setUrl($url = 'https://domain.tld/index.php');
151 $bookmark->setShortUrl('abc');
152 $bookmark->setTitle($title = 'This a brand new bookmark');
153 $bookmark->setDescription($desc = 'It should be created and written');
154 $bookmark->setTags($tags = ['tag1', 'tagssss']);
155 $bookmark->setThumbnail($thumb = 'http://thumb.tld/dle.png');
156 $bookmark->setPrivate(true);
157 $bookmark->setSticky(true);
158 $bookmark->setCreated($created = DateTime
::createFromFormat('Ymd_His', '20190518_140354'));
159 $bookmark->setUpdated($updated = DateTime
::createFromFormat('Ymd_His', '20190518_150354'));
161 $this->privateLinkDB
->add($bookmark);
162 $bookmark = $this->privateLinkDB
->get(43);
163 $this->assertEquals(43, $bookmark->getId());
164 $this->assertEquals($url, $bookmark->getUrl());
165 $this->assertEquals('abc', $bookmark->getShortUrl());
166 $this->assertEquals($title, $bookmark->getTitle());
167 $this->assertEquals($desc, $bookmark->getDescription());
168 $this->assertEquals($tags, $bookmark->getTags());
169 $this->assertEquals($thumb, $bookmark->getThumbnail());
170 $this->assertTrue($bookmark->isPrivate());
171 $this->assertTrue($bookmark->isSticky());
172 $this->assertEquals($created, $bookmark->getCreated());
173 $this->assertEquals($updated, $bookmark->getUpdated());
176 $this->privateLinkDB
= new BookmarkFileService($this->conf
, $this->history
, true);
178 $bookmark = $this->privateLinkDB
->get(43);
179 $this->assertEquals(43, $bookmark->getId());
180 $this->assertEquals($url, $bookmark->getUrl());
181 $this->assertEquals('abc', $bookmark->getShortUrl());
182 $this->assertEquals($title, $bookmark->getTitle());
183 $this->assertEquals($desc, $bookmark->getDescription());
184 $this->assertEquals($tags, $bookmark->getTags());
185 $this->assertEquals($thumb, $bookmark->getThumbnail());
186 $this->assertTrue($bookmark->isPrivate());
187 $this->assertTrue($bookmark->isSticky());
188 $this->assertEquals($created, $bookmark->getCreated());
189 $this->assertEquals($updated, $bookmark->getUpdated());
193 * Test add() method for a bookmark without any field set
195 public function testAddMinimal()
197 $bookmark = new Bookmark();
198 $this->privateLinkDB
->add($bookmark);
200 $bookmark = $this->privateLinkDB
->get(43);
201 $this->assertEquals(43, $bookmark->getId());
202 $this->assertRegExp('/\?[\w\-]{6}/', $bookmark->getUrl());
203 $this->assertRegExp('/[\w\-]{6}/', $bookmark->getShortUrl());
204 $this->assertEquals($bookmark->getUrl(), $bookmark->getTitle());
205 $this->assertEmpty($bookmark->getDescription());
206 $this->assertEmpty($bookmark->getTags());
207 $this->assertEmpty($bookmark->getThumbnail());
208 $this->assertFalse($bookmark->isPrivate());
209 $this->assertFalse($bookmark->isSticky());
210 $this->assertTrue(new \
DateTime('5 seconds ago') < $bookmark->getCreated());
211 $this->assertNull($bookmark->getUpdated());
214 $this->privateLinkDB
= new BookmarkFileService($this->conf
, $this->history
, true);
216 $bookmark = $this->privateLinkDB
->get(43);
217 $this->assertEquals(43, $bookmark->getId());
218 $this->assertRegExp('/\?[\w\-]{6}/', $bookmark->getUrl());
219 $this->assertRegExp('/[\w\-]{6}/', $bookmark->getShortUrl());
220 $this->assertEquals($bookmark->getUrl(), $bookmark->getTitle());
221 $this->assertEmpty($bookmark->getDescription());
222 $this->assertEmpty($bookmark->getTags());
223 $this->assertEmpty($bookmark->getThumbnail());
224 $this->assertFalse($bookmark->isPrivate());
225 $this->assertFalse($bookmark->isSticky());
226 $this->assertTrue(new \
DateTime('5 seconds ago') < $bookmark->getCreated());
227 $this->assertNull($bookmark->getUpdated());
231 * Test add() method for a bookmark without any field set and without writing the data store
233 * @expectedExceptionMessage Shaarli\Bookmark\Exception\BookmarkNotFoundException
235 public function testAddMinimalNoWrite()
237 $bookmark = new Bookmark();
238 $this->privateLinkDB
->add($bookmark);
240 $bookmark = $this->privateLinkDB
->get(43);
241 $this->assertEquals(43, $bookmark->getId());
244 $this->privateLinkDB
= new BookmarkFileService($this->conf
, $this->history
, true);
246 $this->privateLinkDB
->get(43);
250 * Test add() method while logged out
252 * @expectedException \Exception
253 * @expectedExceptionMessage You're not authorized to alter the datastore
255 public function testAddLoggedOut()
257 $this->publicLinkDB
->add(new Bookmark());
261 * Test add() method with an entry which is not a bookmark instance
263 * @expectedException \Exception
264 * @expectedExceptionMessage Provided data is invalid
266 public function testAddNotABookmark()
268 $this->privateLinkDB
->add(['title' => 'hi!']);
272 * Test add() method with a Bookmark already containing an ID
274 * @expectedException \Exception
275 * @expectedExceptionMessage This bookmarks already exists
277 public function testAddWithId()
279 $bookmark = new Bookmark();
280 $bookmark->setId(43);
281 $this->privateLinkDB
->add($bookmark);
285 * Test set() method for a bookmark fully built
287 public function testSetFull()
289 $bookmark = $this->privateLinkDB
->get(42);
290 $bookmark->setUrl($url = 'https://domain.tld/index.php');
291 $bookmark->setShortUrl('abc');
292 $bookmark->setTitle($title = 'This a brand new bookmark');
293 $bookmark->setDescription($desc = 'It should be created and written');
294 $bookmark->setTags($tags = ['tag1', 'tagssss']);
295 $bookmark->setThumbnail($thumb = 'http://thumb.tld/dle.png');
296 $bookmark->setPrivate(true);
297 $bookmark->setSticky(true);
298 $bookmark->setCreated($created = DateTime
::createFromFormat('Ymd_His', '20190518_140354'));
299 $bookmark->setUpdated($updated = DateTime
::createFromFormat('Ymd_His', '20190518_150354'));
301 $this->privateLinkDB
->set($bookmark);
302 $bookmark = $this->privateLinkDB
->get(42);
303 $this->assertEquals(42, $bookmark->getId());
304 $this->assertEquals($url, $bookmark->getUrl());
305 $this->assertEquals('abc', $bookmark->getShortUrl());
306 $this->assertEquals($title, $bookmark->getTitle());
307 $this->assertEquals($desc, $bookmark->getDescription());
308 $this->assertEquals($tags, $bookmark->getTags());
309 $this->assertEquals($thumb, $bookmark->getThumbnail());
310 $this->assertTrue($bookmark->isPrivate());
311 $this->assertTrue($bookmark->isSticky());
312 $this->assertEquals($created, $bookmark->getCreated());
313 $this->assertTrue(new \
DateTime('5 seconds ago') < $bookmark->getUpdated());
316 $this->privateLinkDB
= new BookmarkFileService($this->conf
, $this->history
, true);
318 $bookmark = $this->privateLinkDB
->get(42);
319 $this->assertEquals(42, $bookmark->getId());
320 $this->assertEquals($url, $bookmark->getUrl());
321 $this->assertEquals('abc', $bookmark->getShortUrl());
322 $this->assertEquals($title, $bookmark->getTitle());
323 $this->assertEquals($desc, $bookmark->getDescription());
324 $this->assertEquals($tags, $bookmark->getTags());
325 $this->assertEquals($thumb, $bookmark->getThumbnail());
326 $this->assertTrue($bookmark->isPrivate());
327 $this->assertTrue($bookmark->isSticky());
328 $this->assertEquals($created, $bookmark->getCreated());
329 $this->assertTrue(new \
DateTime('5 seconds ago') < $bookmark->getUpdated());
333 * Test set() method for a bookmark without any field set
335 public function testSetMinimal()
337 $bookmark = $this->privateLinkDB
->get(42);
338 $this->privateLinkDB
->set($bookmark);
340 $bookmark = $this->privateLinkDB
->get(42);
341 $this->assertEquals(42, $bookmark->getId());
342 $this->assertEquals('?WDWyig', $bookmark->getUrl());
343 $this->assertEquals('1eYJ1Q', $bookmark->getShortUrl());
344 $this->assertEquals('Note: I have a big ID but an old date', $bookmark->getTitle());
345 $this->assertEquals('Used to test bookmarks reordering.', $bookmark->getDescription());
346 $this->assertEquals(['ut'], $bookmark->getTags());
347 $this->assertFalse($bookmark->getThumbnail());
348 $this->assertFalse($bookmark->isPrivate());
349 $this->assertFalse($bookmark->isSticky());
351 DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, '20100310_101010'),
352 $bookmark->getCreated()
354 $this->assertTrue(new \
DateTime('5 seconds ago') < $bookmark->getUpdated());
357 $this->privateLinkDB
= new BookmarkFileService($this->conf
, $this->history
, true);
359 $bookmark = $this->privateLinkDB
->get(42);
360 $this->assertEquals(42, $bookmark->getId());
361 $this->assertEquals('?WDWyig', $bookmark->getUrl());
362 $this->assertEquals('1eYJ1Q', $bookmark->getShortUrl());
363 $this->assertEquals('Note: I have a big ID but an old date', $bookmark->getTitle());
364 $this->assertEquals('Used to test bookmarks reordering.', $bookmark->getDescription());
365 $this->assertEquals(['ut'], $bookmark->getTags());
366 $this->assertFalse($bookmark->getThumbnail());
367 $this->assertFalse($bookmark->isPrivate());
368 $this->assertFalse($bookmark->isSticky());
370 DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, '20100310_101010'),
371 $bookmark->getCreated()
373 $this->assertTrue(new \
DateTime('5 seconds ago') < $bookmark->getUpdated());
377 * Test set() method for a bookmark without any field set and without writing the data store
379 public function testSetMinimalNoWrite()
381 $bookmark = $this->privateLinkDB
->get(42);
382 $bookmark->setTitle($title = 'hi!');
383 $this->privateLinkDB
->set($bookmark, false);
385 $bookmark = $this->privateLinkDB
->get(42);
386 $this->assertEquals(42, $bookmark->getId());
387 $this->assertEquals($title, $bookmark->getTitle());
390 $this->privateLinkDB
= new BookmarkFileService($this->conf
, $this->history
, true);
392 $bookmark = $this->privateLinkDB
->get(42);
393 $this->assertEquals(42, $bookmark->getId());
394 $this->assertEquals('Note: I have a big ID but an old date', $bookmark->getTitle());
398 * Test set() method while logged out
400 * @expectedException \Exception
401 * @expectedExceptionMessage You're not authorized to alter the datastore
403 public function testSetLoggedOut()
405 $this->publicLinkDB
->set(new Bookmark());
409 * Test set() method with an entry which is not a bookmark instance
411 * @expectedException \Exception
412 * @expectedExceptionMessage Provided data is invalid
414 public function testSetNotABookmark()
416 $this->privateLinkDB
->set(['title' => 'hi!']);
420 * Test set() method with a Bookmark without an ID defined.
422 * @expectedException Shaarli\Bookmark\Exception\BookmarkNotFoundException
424 public function testSetWithoutId()
426 $bookmark = new Bookmark();
427 $this->privateLinkDB
->set($bookmark);
431 * Test set() method with a Bookmark with an unknow ID
433 * @expectedException Shaarli\Bookmark\Exception\BookmarkNotFoundException
435 public function testSetWithUnknownId()
437 $bookmark = new Bookmark();
438 $bookmark->setId(666);
439 $this->privateLinkDB
->set($bookmark);
443 * Test addOrSet() method with a new ID
445 public function testAddOrSetNew()
447 $bookmark = new Bookmark();
448 $this->privateLinkDB
->addOrSet($bookmark);
450 $bookmark = $this->privateLinkDB
->get(43);
451 $this->assertEquals(43, $bookmark->getId());
454 $this->privateLinkDB
= new BookmarkFileService($this->conf
, $this->history
, true);
456 $bookmark = $this->privateLinkDB
->get(43);
457 $this->assertEquals(43, $bookmark->getId());
461 * Test addOrSet() method with an existing ID
463 public function testAddOrSetExisting()
465 $bookmark = $this->privateLinkDB
->get(42);
466 $bookmark->setTitle($title = 'hi!');
467 $this->privateLinkDB
->addOrSet($bookmark);
469 $bookmark = $this->privateLinkDB
->get(42);
470 $this->assertEquals(42, $bookmark->getId());
471 $this->assertEquals($title, $bookmark->getTitle());
474 $this->privateLinkDB
= new BookmarkFileService($this->conf
, $this->history
, true);
476 $bookmark = $this->privateLinkDB
->get(42);
477 $this->assertEquals(42, $bookmark->getId());
478 $this->assertEquals($title, $bookmark->getTitle());
482 * Test addOrSet() method while logged out
484 * @expectedException \Exception
485 * @expectedExceptionMessage You're not authorized to alter the datastore
487 public function testAddOrSetLoggedOut()
489 $this->publicLinkDB
->addOrSet(new Bookmark());
493 * Test addOrSet() method with an entry which is not a bookmark instance
495 * @expectedException \Exception
496 * @expectedExceptionMessage Provided data is invalid
498 public function testAddOrSetNotABookmark()
500 $this->privateLinkDB
->addOrSet(['title' => 'hi!']);
504 * Test addOrSet() method for a bookmark without any field set and without writing the data store
506 public function testAddOrSetMinimalNoWrite()
508 $bookmark = $this->privateLinkDB
->get(42);
509 $bookmark->setTitle($title = 'hi!');
510 $this->privateLinkDB
->addOrSet($bookmark, false);
512 $bookmark = $this->privateLinkDB
->get(42);
513 $this->assertEquals(42, $bookmark->getId());
514 $this->assertEquals($title, $bookmark->getTitle());
517 $this->privateLinkDB
= new BookmarkFileService($this->conf
, $this->history
, true);
519 $bookmark = $this->privateLinkDB
->get(42);
520 $this->assertEquals(42, $bookmark->getId());
521 $this->assertEquals('Note: I have a big ID but an old date', $bookmark->getTitle());
525 * Test remove() method with an existing Bookmark
527 * @expectedException Shaarli\Bookmark\Exception\BookmarkNotFoundException
529 public function testRemoveExisting()
531 $bookmark = $this->privateLinkDB
->get(42);
532 $this->privateLinkDB
->remove($bookmark);
536 $this->privateLinkDB
->get(42);
537 } catch (BookmarkNotFoundException
$e) {
540 $this->assertInstanceOf(BookmarkNotFoundException
::class, $exception);
543 $this->privateLinkDB
= new BookmarkFileService($this->conf
, $this->history
, true);
545 $this->privateLinkDB
->get(42);
549 * Test remove() method while logged out
551 * @expectedException \Exception
552 * @expectedExceptionMessage You're not authorized to alter the datastore
554 public function testRemoveLoggedOut()
556 $bookmark = $this->privateLinkDB
->get(42);
557 $this->publicLinkDB
->remove($bookmark);
561 * Test remove() method with an entry which is not a bookmark instance
563 * @expectedException \Exception
564 * @expectedExceptionMessage Provided data is invalid
566 public function testRemoveNotABookmark()
568 $this->privateLinkDB
->remove(['title' => 'hi!']);
572 * Test remove() method with a Bookmark with an unknown ID
574 * @expectedException Shaarli\Bookmark\Exception\BookmarkNotFoundException
576 public function testRemoveWithUnknownId()
578 $bookmark = new Bookmark();
579 $bookmark->setId(666);
580 $this->privateLinkDB
->remove($bookmark);
584 * Test exists() method
586 public function testExists()
588 $this->assertTrue($this->privateLinkDB
->exists(42)); // public
589 $this->assertTrue($this->privateLinkDB
->exists(6)); // private
591 $this->assertTrue($this->privateLinkDB
->exists(42, BookmarkFilter
::$ALL));
592 $this->assertTrue($this->privateLinkDB
->exists(6, BookmarkFilter
::$ALL));
594 $this->assertTrue($this->privateLinkDB
->exists(42, BookmarkFilter
::$PUBLIC));
595 $this->assertFalse($this->privateLinkDB
->exists(6, BookmarkFilter
::$PUBLIC));
597 $this->assertFalse($this->privateLinkDB
->exists(42, BookmarkFilter
::$PRIVATE));
598 $this->assertTrue($this->privateLinkDB
->exists(6, BookmarkFilter
::$PRIVATE));
600 $this->assertTrue($this->publicLinkDB
->exists(42));
601 $this->assertFalse($this->publicLinkDB
->exists(6));
603 $this->assertTrue($this->publicLinkDB
->exists(42, BookmarkFilter
::$PUBLIC));
604 $this->assertFalse($this->publicLinkDB
->exists(6, BookmarkFilter
::$PUBLIC));
606 $this->assertFalse($this->publicLinkDB
->exists(42, BookmarkFilter
::$PRIVATE));
607 $this->assertTrue($this->publicLinkDB
->exists(6, BookmarkFilter
::$PRIVATE));
611 * Test initialize() method
613 public function testInitialize()
615 $dbSize = $this->privateLinkDB
->count();
616 $this->privateLinkDB
->initialize();
617 $this->assertEquals($dbSize +
2, $this->privateLinkDB
->count());
619 'My secret stuff... - Pastebin.com',
620 $this->privateLinkDB
->get(43)->getTitle()
623 'The personal, minimalist, super-fast, database free, bookmarking service',
624 $this->privateLinkDB
->get(44)->getTitle()
629 * The following tests have been taken from the legacy LinkDB test and adapted
630 * to make sure that nothing have been broken in the migration process.
631 * They mostly cover search/filters. Some of them might be redundant with the previous ones.
635 * Attempt to instantiate a LinkDB whereas the datastore is not writable
637 * @expectedException Shaarli\Bookmark\Exception\NotWritableDataStoreException
638 * @expectedExceptionMessageRegExp #Couldn't load data from the data store file "null".*#
640 public function testConstructDatastoreNotWriteable()
642 $conf = new ConfigManager('tests/utils/config/configJson');
643 $conf->set('resource.datastore', 'null/store.db');
644 new BookmarkFileService($conf, $this->history
, true);
648 * The DB doesn't exist, ensure it is created with an empty datastore
650 public function testCheckDBNewLoggedIn()
652 unlink(self
::$testDatastore);
653 $this->assertFileNotExists(self
::$testDatastore);
654 new BookmarkFileService($this->conf
, $this->history
, true);
655 $this->assertFileExists(self
::$testDatastore);
657 // ensure the correct data has been written
658 $this->assertGreaterThan(0, filesize(self
::$testDatastore));
662 * The DB doesn't exist, but not logged in, ensure it initialized, but the file is not written
664 public function testCheckDBNewLoggedOut()
666 unlink(self
::$testDatastore);
667 $this->assertFileNotExists(self
::$testDatastore);
668 $db = new \
FakeBookmarkService($this->conf
, $this->history
, false);
669 $this->assertFileNotExists(self
::$testDatastore);
670 $this->assertInstanceOf(BookmarkArray
::class, $db->getBookmarks());
671 $this->assertCount(0, $db->getBookmarks());
675 * Load public bookmarks from the DB
677 public function testReadPublicDB()
680 $this->refDB
->countPublicLinks(),
681 $this->publicLinkDB
->count()
686 * Load public and private bookmarks from the DB
688 public function testReadPrivateDB()
691 $this->refDB
->countLinks(),
692 $this->privateLinkDB
->count()
697 * Save the bookmarks to the DB
699 public function testSave()
701 $testDB = new BookmarkFileService($this->conf
, $this->history
, true);
702 $dbSize = $testDB->count();
704 $bookmark = new Bookmark();
705 $testDB->add($bookmark);
707 $testDB = new BookmarkFileService($this->conf
, $this->history
, true);
708 $this->assertEquals($dbSize +
1, $testDB->count());
712 * Count existing bookmarks - public bookmarks hidden
714 public function testCountHiddenPublic()
716 $this->conf
->set('privacy.hide_public_links', true);
717 $linkDB = new BookmarkFileService($this->conf
, $this->history
, false);
719 $this->assertEquals(0, $linkDB->count());
723 * List the days for which bookmarks have been posted
725 public function testDays()
728 ['20100309', '20100310', '20121206', '20121207', '20130614', '20150310'],
729 $this->publicLinkDB
->days()
733 ['20100309', '20100310', '20121206', '20121207', '20130614', '20141125', '20150310'],
734 $this->privateLinkDB
->days()
739 * The URL corresponds to an existing entry in the DB
741 public function testGetKnownLinkFromURL()
743 $link = $this->publicLinkDB
->findByUrl('http://mediagoblin.org/');
745 $this->assertNotEquals(false, $link);
746 $this->assertContains(
747 'A free software media publishing platform',
748 $link->getDescription()
753 * The URL is not in the DB
755 public function testGetUnknownLinkFromURL()
759 $this->publicLinkDB
->findByUrl('http://dev.null')
766 public function testAllTags()
781 // The DB contains a link with `sTuff` and another one with `stuff` tag.
782 // They need to be grouped with the first case found - order by date DESC: `sTuff`.
786 $this->publicLinkDB
->bookmarksCountPerTag()
814 $this->privateLinkDB
->bookmarksCountPerTag()
831 $this->privateLinkDB
->bookmarksCountPerTag(['web'])
841 $this->privateLinkDB
->bookmarksCountPerTag(['web'], 'private')
846 * Test filter with string.
848 public function testFilterString()
850 $tags = 'dev cartoon';
851 $request = ['searchtags' => $tags];
854 count($this->privateLinkDB
->search($request, null, true))
859 * Test filter with array.
861 public function testFilterArray()
863 $tags = ['dev', 'cartoon'];
864 $request = ['searchtags' => $tags];
867 count($this->privateLinkDB
->search($request, null, true))
872 * Test hidden tags feature:
873 * tags starting with a dot '.' are only visible when logged in.
875 public function testHiddenTags()
878 $request = ['searchtags' => $tags];
881 count($this->privateLinkDB
->search($request, 'all', true))
886 count($this->publicLinkDB
->search($request, 'public', true))
891 * Test filterHash() with a valid smallhash.
893 public function testFilterHashValid()
895 $request = smallHash('20150310_114651');
898 count($this->publicLinkDB
->findByHash($request))
900 $request = smallHash('20150310_114633' . 8);
903 count($this->publicLinkDB
->findByHash($request))
908 * Test filterHash() with an invalid smallhash.
910 * @expectedException \Shaarli\Bookmark\Exception\BookmarkNotFoundException
912 public function testFilterHashInValid1()
915 $this->publicLinkDB
->findByHash($request);
919 * Test filterHash() with an empty smallhash.
921 * @expectedException \Shaarli\Bookmark\Exception\BookmarkNotFoundException
923 public function testFilterHashInValid()
925 $this->publicLinkDB
->findByHash('');
929 * Test linksCountPerTag all tags without filter.
930 * Equal occurrences should be sorted alphabetically.
932 public function testCountLinkPerTagAllNoFilter()
958 $tags = $this->privateLinkDB
->bookmarksCountPerTag();
960 $this->assertEquals($expected, $tags, var_export($tags, true));
964 * Test linksCountPerTag all tags with filter.
965 * Equal occurrences should be sorted alphabetically.
967 public function testCountLinkPerTagAllWithFilter()
981 $tags = $this->privateLinkDB
->bookmarksCountPerTag(['gnu']);
983 $this->assertEquals($expected, $tags, var_export($tags, true));
987 * Test linksCountPerTag public tags with filter.
988 * Equal occurrences should be sorted alphabetically.
990 public function testCountLinkPerTagPublicWithFilter()
1004 $tags = $this->privateLinkDB
->bookmarksCountPerTag(['gnu'], 'public');
1006 $this->assertEquals($expected, $tags, var_export($tags, true));
1010 * Test linksCountPerTag public tags with filter.
1011 * Equal occurrences should be sorted alphabetically.
1013 public function testCountLinkPerTagPrivateWithFilter()
1023 $tags = $this->privateLinkDB
->bookmarksCountPerTag(['dev'], 'private');
1025 $this->assertEquals($expected, $tags, var_export($tags, true));
1029 * Allows to test LinkDB's private methods
1032 * https://sebastian-bergmann.de/archives/881-Testing-Your-Privates.html
1033 * http://stackoverflow.com/a/2798203
1035 protected static function getMethod($name)
1037 $class = new ReflectionClass('Shaarli\Bookmark\BookmarkFileService');
1038 $method = $class->getMethod($name);
1039 $method->setAccessible(true);