aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/bookmark/BookmarkFileServiceTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/bookmark/BookmarkFileServiceTest.php')
-rw-r--r--tests/bookmark/BookmarkFileServiceTest.php137
1 files changed, 116 insertions, 21 deletions
diff --git a/tests/bookmark/BookmarkFileServiceTest.php b/tests/bookmark/BookmarkFileServiceTest.php
index d1af3fb0..1d250719 100644
--- a/tests/bookmark/BookmarkFileServiceTest.php
+++ b/tests/bookmark/BookmarkFileServiceTest.php
@@ -14,6 +14,7 @@ use Shaarli\Bookmark\Exception\BookmarkNotFoundException;
14use Shaarli\Config\ConfigManager; 14use Shaarli\Config\ConfigManager;
15use Shaarli\Formatter\BookmarkMarkdownFormatter; 15use Shaarli\Formatter\BookmarkMarkdownFormatter;
16use Shaarli\History; 16use Shaarli\History;
17use Shaarli\Plugin\PluginManager;
17use Shaarli\TestCase; 18use Shaarli\TestCase;
18 19
19/** 20/**
@@ -56,6 +57,9 @@ class BookmarkFileServiceTest extends TestCase
56 /** @var NoMutex */ 57 /** @var NoMutex */
57 protected $mutex; 58 protected $mutex;
58 59
60 /** @var PluginManager */
61 protected $pluginManager;
62
59 /** 63 /**
60 * Instantiates public and private LinkDBs with test data 64 * Instantiates public and private LinkDBs with test data
61 * 65 *
@@ -93,8 +97,21 @@ class BookmarkFileServiceTest extends TestCase
93 $this->refDB = new \ReferenceLinkDB(); 97 $this->refDB = new \ReferenceLinkDB();
94 $this->refDB->write(self::$testDatastore); 98 $this->refDB->write(self::$testDatastore);
95 $this->history = new History('sandbox/history.php'); 99 $this->history = new History('sandbox/history.php');
96 $this->publicLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, false); 100 $this->pluginManager = new PluginManager($this->conf);
97 $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); 101 $this->publicLinkDB = new BookmarkFileService(
102 $this->conf,
103 $this->pluginManager,
104 $this->history,
105 $this->mutex,
106 false
107 );
108 $this->privateLinkDB = new BookmarkFileService(
109 $this->conf,
110 $this->pluginManager,
111 $this->history,
112 $this->mutex,
113 true
114 );
98 } 115 }
99 116
100 /** 117 /**
@@ -111,7 +128,13 @@ class BookmarkFileServiceTest extends TestCase
111 $db = self::getMethod('migrate'); 128 $db = self::getMethod('migrate');
112 $db->invokeArgs($this->privateLinkDB, []); 129 $db->invokeArgs($this->privateLinkDB, []);
113 130
114 $db = new \FakeBookmarkService($this->conf, $this->history, $this->mutex, true); 131 $db = new \FakeBookmarkService(
132 $this->conf,
133 $this->pluginManager,
134 $this->history,
135 $this->mutex,
136 true
137 );
115 $this->assertInstanceOf(BookmarkArray::class, $db->getBookmarks()); 138 $this->assertInstanceOf(BookmarkArray::class, $db->getBookmarks());
116 $this->assertEquals($this->refDB->countLinks(), $db->count()); 139 $this->assertEquals($this->refDB->countLinks(), $db->count());
117 } 140 }
@@ -180,7 +203,13 @@ class BookmarkFileServiceTest extends TestCase
180 $this->assertEquals($updated, $bookmark->getUpdated()); 203 $this->assertEquals($updated, $bookmark->getUpdated());
181 204
182 // reload from file 205 // reload from file
183 $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); 206 $this->privateLinkDB = new \FakeBookmarkService(
207 $this->conf,
208 $this->pluginManager,
209 $this->history,
210 $this->mutex,
211 true
212 );
184 213
185 $bookmark = $this->privateLinkDB->get(43); 214 $bookmark = $this->privateLinkDB->get(43);
186 $this->assertEquals(43, $bookmark->getId()); 215 $this->assertEquals(43, $bookmark->getId());
@@ -218,7 +247,13 @@ class BookmarkFileServiceTest extends TestCase
218 $this->assertNull($bookmark->getUpdated()); 247 $this->assertNull($bookmark->getUpdated());
219 248
220 // reload from file 249 // reload from file
221 $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); 250 $this->privateLinkDB = new BookmarkFileService(
251 $this->conf,
252 $this->pluginManager,
253 $this->history,
254 $this->mutex,
255 true
256 );
222 257
223 $bookmark = $this->privateLinkDB->get(43); 258 $bookmark = $this->privateLinkDB->get(43);
224 $this->assertEquals(43, $bookmark->getId()); 259 $this->assertEquals(43, $bookmark->getId());
@@ -248,7 +283,13 @@ class BookmarkFileServiceTest extends TestCase
248 $this->assertEquals(43, $bookmark->getId()); 283 $this->assertEquals(43, $bookmark->getId());
249 284
250 // reload from file 285 // reload from file
251 $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); 286 $this->privateLinkDB = new BookmarkFileService(
287 $this->conf,
288 $this->pluginManager,
289 $this->history,
290 $this->mutex,
291 true
292 );
252 293
253 $this->privateLinkDB->get(43); 294 $this->privateLinkDB->get(43);
254 } 295 }
@@ -309,7 +350,13 @@ class BookmarkFileServiceTest extends TestCase
309 $this->assertTrue(new \DateTime('5 seconds ago') < $bookmark->getUpdated()); 350 $this->assertTrue(new \DateTime('5 seconds ago') < $bookmark->getUpdated());
310 351
311 // reload from file 352 // reload from file
312 $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); 353 $this->privateLinkDB = new BookmarkFileService(
354 $this->conf,
355 $this->pluginManager,
356 $this->history,
357 $this->mutex,
358 true
359 );
313 360
314 $bookmark = $this->privateLinkDB->get(42); 361 $bookmark = $this->privateLinkDB->get(42);
315 $this->assertEquals(42, $bookmark->getId()); 362 $this->assertEquals(42, $bookmark->getId());
@@ -350,7 +397,13 @@ class BookmarkFileServiceTest extends TestCase
350 $this->assertTrue(new \DateTime('5 seconds ago') < $bookmark->getUpdated()); 397 $this->assertTrue(new \DateTime('5 seconds ago') < $bookmark->getUpdated());
351 398
352 // reload from file 399 // reload from file
353 $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); 400 $this->privateLinkDB = new BookmarkFileService(
401 $this->conf,
402 $this->pluginManager,
403 $this->history,
404 $this->mutex,
405 true
406 );
354 407
355 $bookmark = $this->privateLinkDB->get(42); 408 $bookmark = $this->privateLinkDB->get(42);
356 $this->assertEquals(42, $bookmark->getId()); 409 $this->assertEquals(42, $bookmark->getId());
@@ -383,7 +436,13 @@ class BookmarkFileServiceTest extends TestCase
383 $this->assertEquals($title, $bookmark->getTitle()); 436 $this->assertEquals($title, $bookmark->getTitle());
384 437
385 // reload from file 438 // reload from file
386 $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); 439 $this->privateLinkDB = new BookmarkFileService(
440 $this->conf,
441 $this->pluginManager,
442 $this->history,
443 $this->mutex,
444 true
445 );
387 446
388 $bookmark = $this->privateLinkDB->get(42); 447 $bookmark = $this->privateLinkDB->get(42);
389 $this->assertEquals(42, $bookmark->getId()); 448 $this->assertEquals(42, $bookmark->getId());
@@ -436,7 +495,13 @@ class BookmarkFileServiceTest extends TestCase
436 $this->assertEquals(43, $bookmark->getId()); 495 $this->assertEquals(43, $bookmark->getId());
437 496
438 // reload from file 497 // reload from file
439 $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); 498 $this->privateLinkDB = new BookmarkFileService(
499 $this->conf,
500 $this->pluginManager,
501 $this->history,
502 $this->mutex,
503 true
504 );
440 505
441 $bookmark = $this->privateLinkDB->get(43); 506 $bookmark = $this->privateLinkDB->get(43);
442 $this->assertEquals(43, $bookmark->getId()); 507 $this->assertEquals(43, $bookmark->getId());
@@ -456,7 +521,13 @@ class BookmarkFileServiceTest extends TestCase
456 $this->assertEquals($title, $bookmark->getTitle()); 521 $this->assertEquals($title, $bookmark->getTitle());
457 522
458 // reload from file 523 // reload from file
459 $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); 524 $this->privateLinkDB = new BookmarkFileService(
525 $this->conf,
526 $this->pluginManager,
527 $this->history,
528 $this->mutex,
529 true
530 );
460 531
461 $bookmark = $this->privateLinkDB->get(42); 532 $bookmark = $this->privateLinkDB->get(42);
462 $this->assertEquals(42, $bookmark->getId()); 533 $this->assertEquals(42, $bookmark->getId());
@@ -488,7 +559,13 @@ class BookmarkFileServiceTest extends TestCase
488 $this->assertEquals($title, $bookmark->getTitle()); 559 $this->assertEquals($title, $bookmark->getTitle());
489 560
490 // reload from file 561 // reload from file
491 $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); 562 $this->privateLinkDB = new BookmarkFileService(
563 $this->conf,
564 $this->pluginManager,
565 $this->history,
566 $this->mutex,
567 true
568 );
492 569
493 $bookmark = $this->privateLinkDB->get(42); 570 $bookmark = $this->privateLinkDB->get(42);
494 $this->assertEquals(42, $bookmark->getId()); 571 $this->assertEquals(42, $bookmark->getId());
@@ -514,7 +591,13 @@ class BookmarkFileServiceTest extends TestCase
514 $this->assertInstanceOf(BookmarkNotFoundException::class, $exception); 591 $this->assertInstanceOf(BookmarkNotFoundException::class, $exception);
515 592
516 // reload from file 593 // reload from file
517 $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); 594 $this->privateLinkDB = new BookmarkFileService(
595 $this->conf,
596 $this->pluginManager,
597 $this->history,
598 $this->mutex,
599 true
600 );
518 601
519 $this->privateLinkDB->get(42); 602 $this->privateLinkDB->get(42);
520 } 603 }
@@ -607,7 +690,7 @@ class BookmarkFileServiceTest extends TestCase
607 690
608 $conf = new ConfigManager('tests/utils/config/configJson'); 691 $conf = new ConfigManager('tests/utils/config/configJson');
609 $conf->set('resource.datastore', 'null/store.db'); 692 $conf->set('resource.datastore', 'null/store.db');
610 new BookmarkFileService($conf, $this->history, $this->mutex, true); 693 new BookmarkFileService($conf, $this->pluginManager, $this->history, $this->mutex, true);
611 } 694 }
612 695
613 /** 696 /**
@@ -617,7 +700,7 @@ class BookmarkFileServiceTest extends TestCase
617 { 700 {
618 unlink(self::$testDatastore); 701 unlink(self::$testDatastore);
619 $this->assertFileNotExists(self::$testDatastore); 702 $this->assertFileNotExists(self::$testDatastore);
620 new BookmarkFileService($this->conf, $this->history, $this->mutex, true); 703 new BookmarkFileService($this->conf, $this->pluginManager, $this->history, $this->mutex, true);
621 $this->assertFileExists(self::$testDatastore); 704 $this->assertFileExists(self::$testDatastore);
622 705
623 // ensure the correct data has been written 706 // ensure the correct data has been written
@@ -631,7 +714,7 @@ class BookmarkFileServiceTest extends TestCase
631 { 714 {
632 unlink(self::$testDatastore); 715 unlink(self::$testDatastore);
633 $this->assertFileNotExists(self::$testDatastore); 716 $this->assertFileNotExists(self::$testDatastore);
634 $db = new \FakeBookmarkService($this->conf, $this->history, $this->mutex, false); 717 $db = new \FakeBookmarkService($this->conf, $this->pluginManager, $this->history, $this->mutex, false);
635 $this->assertFileNotExists(self::$testDatastore); 718 $this->assertFileNotExists(self::$testDatastore);
636 $this->assertInstanceOf(BookmarkArray::class, $db->getBookmarks()); 719 $this->assertInstanceOf(BookmarkArray::class, $db->getBookmarks());
637 $this->assertCount(0, $db->getBookmarks()); 720 $this->assertCount(0, $db->getBookmarks());
@@ -664,13 +747,13 @@ class BookmarkFileServiceTest extends TestCase
664 */ 747 */
665 public function testSave() 748 public function testSave()
666 { 749 {
667 $testDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); 750 $testDB = new BookmarkFileService($this->conf, $this->pluginManager, $this->history, $this->mutex, true);
668 $dbSize = $testDB->count(); 751 $dbSize = $testDB->count();
669 752
670 $bookmark = new Bookmark(); 753 $bookmark = new Bookmark();
671 $testDB->add($bookmark); 754 $testDB->add($bookmark);
672 755
673 $testDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); 756 $testDB = new BookmarkFileService($this->conf, $this->pluginManager, $this->history, $this->mutex, true);
674 $this->assertEquals($dbSize + 1, $testDB->count()); 757 $this->assertEquals($dbSize + 1, $testDB->count());
675 } 758 }
676 759
@@ -680,7 +763,7 @@ class BookmarkFileServiceTest extends TestCase
680 public function testCountHiddenPublic() 763 public function testCountHiddenPublic()
681 { 764 {
682 $this->conf->set('privacy.hide_public_links', true); 765 $this->conf->set('privacy.hide_public_links', true);
683 $linkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, false); 766 $linkDB = new BookmarkFileService($this->conf, $this->pluginManager, $this->history, $this->mutex, false);
684 767
685 $this->assertEquals(0, $linkDB->count()); 768 $this->assertEquals(0, $linkDB->count());
686 } 769 }
@@ -906,7 +989,13 @@ class BookmarkFileServiceTest extends TestCase
906 $bookmark->addAdditionalContentEntry('private_key', $privateKey); 989 $bookmark->addAdditionalContentEntry('private_key', $privateKey);
907 $this->privateLinkDB->save(); 990 $this->privateLinkDB->save();
908 991
909 $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, false); 992 $this->privateLinkDB = new BookmarkFileService(
993 $this->conf,
994 $this->pluginManager,
995 $this->history,
996 $this->mutex,
997 false
998 );
910 $bookmark = $this->privateLinkDB->findByHash($hash, $privateKey); 999 $bookmark = $this->privateLinkDB->findByHash($hash, $privateKey);
911 1000
912 static::assertSame(6, $bookmark->getId()); 1001 static::assertSame(6, $bookmark->getId());
@@ -1152,7 +1241,13 @@ class BookmarkFileServiceTest extends TestCase
1152 public function testGetLatestEmptyDatastore(): void 1241 public function testGetLatestEmptyDatastore(): void
1153 { 1242 {
1154 unlink($this->conf->get('resource.datastore')); 1243 unlink($this->conf->get('resource.datastore'));
1155 $this->publicLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, false); 1244 $this->publicLinkDB = new BookmarkFileService(
1245 $this->conf,
1246 $this->pluginManager,
1247 $this->history,
1248 $this->mutex,
1249 false
1250 );
1156 1251
1157 $bookmark = $this->publicLinkDB->getLatest(); 1252 $bookmark = $this->publicLinkDB->getLatest();
1158 1253