diff options
Diffstat (limited to 'tests/bookmark')
-rw-r--r-- | tests/bookmark/BookmarkArrayTest.php | 29 | ||||
-rw-r--r-- | tests/bookmark/BookmarkFileServiceTest.php | 141 | ||||
-rw-r--r-- | tests/bookmark/BookmarkFilterTest.php | 30 | ||||
-rw-r--r-- | tests/bookmark/BookmarkInitializerTest.php | 72 | ||||
-rw-r--r-- | tests/bookmark/BookmarkTest.php | 12 | ||||
-rw-r--r-- | tests/bookmark/LinkUtilsTest.php | 35 |
6 files changed, 200 insertions, 119 deletions
diff --git a/tests/bookmark/BookmarkArrayTest.php b/tests/bookmark/BookmarkArrayTest.php index 0f8f04c5..ebed9bfc 100644 --- a/tests/bookmark/BookmarkArrayTest.php +++ b/tests/bookmark/BookmarkArrayTest.php | |||
@@ -2,10 +2,7 @@ | |||
2 | 2 | ||
3 | namespace Shaarli\Bookmark; | 3 | namespace Shaarli\Bookmark; |
4 | 4 | ||
5 | use PHPUnit\Framework\TestCase; | 5 | use Shaarli\TestCase; |
6 | use Shaarli\Bookmark\Exception\InvalidBookmarkException; | ||
7 | use Shaarli\Config\ConfigManager; | ||
8 | use Shaarli\History; | ||
9 | 6 | ||
10 | /** | 7 | /** |
11 | * Class BookmarkArrayTest | 8 | * Class BookmarkArrayTest |
@@ -47,22 +44,22 @@ class BookmarkArrayTest extends TestCase | |||
47 | 44 | ||
48 | /** | 45 | /** |
49 | * Test adding a bad entry: wrong type | 46 | * Test adding a bad entry: wrong type |
50 | * | ||
51 | * @expectedException Shaarli\Bookmark\Exception\InvalidBookmarkException | ||
52 | */ | 47 | */ |
53 | public function testArrayAccessAddBadEntryInstance() | 48 | public function testArrayAccessAddBadEntryInstance() |
54 | { | 49 | { |
50 | $this->expectException(\Shaarli\Bookmark\Exception\InvalidBookmarkException::class); | ||
51 | |||
55 | $array = new BookmarkArray(); | 52 | $array = new BookmarkArray(); |
56 | $array[] = 'nope'; | 53 | $array[] = 'nope'; |
57 | } | 54 | } |
58 | 55 | ||
59 | /** | 56 | /** |
60 | * Test adding a bad entry: no id | 57 | * Test adding a bad entry: no id |
61 | * | ||
62 | * @expectedException Shaarli\Bookmark\Exception\InvalidBookmarkException | ||
63 | */ | 58 | */ |
64 | public function testArrayAccessAddBadEntryNoId() | 59 | public function testArrayAccessAddBadEntryNoId() |
65 | { | 60 | { |
61 | $this->expectException(\Shaarli\Bookmark\Exception\InvalidBookmarkException::class); | ||
62 | |||
66 | $array = new BookmarkArray(); | 63 | $array = new BookmarkArray(); |
67 | $bookmark = new Bookmark(); | 64 | $bookmark = new Bookmark(); |
68 | $array[] = $bookmark; | 65 | $array[] = $bookmark; |
@@ -70,11 +67,11 @@ class BookmarkArrayTest extends TestCase | |||
70 | 67 | ||
71 | /** | 68 | /** |
72 | * Test adding a bad entry: no url | 69 | * Test adding a bad entry: no url |
73 | * | ||
74 | * @expectedException Shaarli\Bookmark\Exception\InvalidBookmarkException | ||
75 | */ | 70 | */ |
76 | public function testArrayAccessAddBadEntryNoUrl() | 71 | public function testArrayAccessAddBadEntryNoUrl() |
77 | { | 72 | { |
73 | $this->expectException(\Shaarli\Bookmark\Exception\InvalidBookmarkException::class); | ||
74 | |||
78 | $array = new BookmarkArray(); | 75 | $array = new BookmarkArray(); |
79 | $bookmark = (new Bookmark())->setId(11); | 76 | $bookmark = (new Bookmark())->setId(11); |
80 | $array[] = $bookmark; | 77 | $array[] = $bookmark; |
@@ -82,11 +79,11 @@ class BookmarkArrayTest extends TestCase | |||
82 | 79 | ||
83 | /** | 80 | /** |
84 | * Test adding a bad entry: invalid offset | 81 | * Test adding a bad entry: invalid offset |
85 | * | ||
86 | * @expectedException Shaarli\Bookmark\Exception\InvalidBookmarkException | ||
87 | */ | 82 | */ |
88 | public function testArrayAccessAddBadEntryOffset() | 83 | public function testArrayAccessAddBadEntryOffset() |
89 | { | 84 | { |
85 | $this->expectException(\Shaarli\Bookmark\Exception\InvalidBookmarkException::class); | ||
86 | |||
90 | $array = new BookmarkArray(); | 87 | $array = new BookmarkArray(); |
91 | $bookmark = (new Bookmark())->setId(11); | 88 | $bookmark = (new Bookmark())->setId(11); |
92 | $bookmark->validate(); | 89 | $bookmark->validate(); |
@@ -95,11 +92,11 @@ class BookmarkArrayTest extends TestCase | |||
95 | 92 | ||
96 | /** | 93 | /** |
97 | * Test adding a bad entry: invalid ID type | 94 | * Test adding a bad entry: invalid ID type |
98 | * | ||
99 | * @expectedException Shaarli\Bookmark\Exception\InvalidBookmarkException | ||
100 | */ | 95 | */ |
101 | public function testArrayAccessAddBadEntryIdType() | 96 | public function testArrayAccessAddBadEntryIdType() |
102 | { | 97 | { |
98 | $this->expectException(\Shaarli\Bookmark\Exception\InvalidBookmarkException::class); | ||
99 | |||
103 | $array = new BookmarkArray(); | 100 | $array = new BookmarkArray(); |
104 | $bookmark = (new Bookmark())->setId('nope'); | 101 | $bookmark = (new Bookmark())->setId('nope'); |
105 | $bookmark->validate(); | 102 | $bookmark->validate(); |
@@ -108,11 +105,11 @@ class BookmarkArrayTest extends TestCase | |||
108 | 105 | ||
109 | /** | 106 | /** |
110 | * Test adding a bad entry: ID/offset not consistent | 107 | * Test adding a bad entry: ID/offset not consistent |
111 | * | ||
112 | * @expectedException Shaarli\Bookmark\Exception\InvalidBookmarkException | ||
113 | */ | 108 | */ |
114 | public function testArrayAccessAddBadEntryIdOffset() | 109 | public function testArrayAccessAddBadEntryIdOffset() |
115 | { | 110 | { |
111 | $this->expectException(\Shaarli\Bookmark\Exception\InvalidBookmarkException::class); | ||
112 | |||
116 | $array = new BookmarkArray(); | 113 | $array = new BookmarkArray(); |
117 | $bookmark = (new Bookmark())->setId(11); | 114 | $bookmark = (new Bookmark())->setId(11); |
118 | $bookmark->validate(); | 115 | $bookmark->validate(); |
diff --git a/tests/bookmark/BookmarkFileServiceTest.php b/tests/bookmark/BookmarkFileServiceTest.php index 7b1906d3..c399822b 100644 --- a/tests/bookmark/BookmarkFileServiceTest.php +++ b/tests/bookmark/BookmarkFileServiceTest.php | |||
@@ -6,7 +6,6 @@ | |||
6 | namespace Shaarli\Bookmark; | 6 | namespace Shaarli\Bookmark; |
7 | 7 | ||
8 | use DateTime; | 8 | use DateTime; |
9 | use PHPUnit\Framework\TestCase; | ||
10 | use ReferenceLinkDB; | 9 | use ReferenceLinkDB; |
11 | use ReflectionClass; | 10 | use ReflectionClass; |
12 | use Shaarli; | 11 | use Shaarli; |
@@ -14,6 +13,7 @@ use Shaarli\Bookmark\Exception\BookmarkNotFoundException; | |||
14 | use Shaarli\Config\ConfigManager; | 13 | use Shaarli\Config\ConfigManager; |
15 | use Shaarli\Formatter\BookmarkMarkdownFormatter; | 14 | use Shaarli\Formatter\BookmarkMarkdownFormatter; |
16 | use Shaarli\History; | 15 | use Shaarli\History; |
16 | use Shaarli\TestCase; | ||
17 | 17 | ||
18 | /** | 18 | /** |
19 | * Unitary tests for LegacyLinkDBTest | 19 | * Unitary tests for LegacyLinkDBTest |
@@ -66,7 +66,7 @@ class BookmarkFileServiceTest extends TestCase | |||
66 | * | 66 | * |
67 | * Resets test data for each test | 67 | * Resets test data for each test |
68 | */ | 68 | */ |
69 | protected function setUp() | 69 | protected function setUp(): void |
70 | { | 70 | { |
71 | if (file_exists(self::$testDatastore)) { | 71 | if (file_exists(self::$testDatastore)) { |
72 | unlink(self::$testDatastore); | 72 | unlink(self::$testDatastore); |
@@ -134,11 +134,11 @@ class BookmarkFileServiceTest extends TestCase | |||
134 | 134 | ||
135 | /** | 135 | /** |
136 | * Test get() method for an undefined bookmark | 136 | * Test get() method for an undefined bookmark |
137 | * | ||
138 | * @expectedException Shaarli\Bookmark\Exception\BookmarkNotFoundException | ||
139 | */ | 137 | */ |
140 | public function testGetUndefined() | 138 | public function testGetUndefined() |
141 | { | 139 | { |
140 | $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class); | ||
141 | |||
142 | $this->privateLinkDB->get(666); | 142 | $this->privateLinkDB->get(666); |
143 | } | 143 | } |
144 | 144 | ||
@@ -230,13 +230,13 @@ class BookmarkFileServiceTest extends TestCase | |||
230 | 230 | ||
231 | /** | 231 | /** |
232 | * Test add() method for a bookmark without any field set and without writing the data store | 232 | * Test add() method for a bookmark without any field set and without writing the data store |
233 | * | ||
234 | * @expectedExceptionMessage Shaarli\Bookmark\Exception\BookmarkNotFoundException | ||
235 | */ | 233 | */ |
236 | public function testAddMinimalNoWrite() | 234 | public function testAddMinimalNoWrite() |
237 | { | 235 | { |
236 | $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class); | ||
237 | |||
238 | $bookmark = new Bookmark(); | 238 | $bookmark = new Bookmark(); |
239 | $this->privateLinkDB->add($bookmark); | 239 | $this->privateLinkDB->add($bookmark, false); |
240 | 240 | ||
241 | $bookmark = $this->privateLinkDB->get(43); | 241 | $bookmark = $this->privateLinkDB->get(43); |
242 | $this->assertEquals(43, $bookmark->getId()); | 242 | $this->assertEquals(43, $bookmark->getId()); |
@@ -249,34 +249,34 @@ class BookmarkFileServiceTest extends TestCase | |||
249 | 249 | ||
250 | /** | 250 | /** |
251 | * Test add() method while logged out | 251 | * Test add() method while logged out |
252 | * | ||
253 | * @expectedException \Exception | ||
254 | * @expectedExceptionMessage You're not authorized to alter the datastore | ||
255 | */ | 252 | */ |
256 | public function testAddLoggedOut() | 253 | public function testAddLoggedOut() |
257 | { | 254 | { |
255 | $this->expectException(\Exception::class); | ||
256 | $this->expectExceptionMessage('You\'re not authorized to alter the datastore'); | ||
257 | |||
258 | $this->publicLinkDB->add(new Bookmark()); | 258 | $this->publicLinkDB->add(new Bookmark()); |
259 | } | 259 | } |
260 | 260 | ||
261 | /** | 261 | /** |
262 | * Test add() method with an entry which is not a bookmark instance | 262 | * Test add() method with an entry which is not a bookmark instance |
263 | * | ||
264 | * @expectedException \Exception | ||
265 | * @expectedExceptionMessage Provided data is invalid | ||
266 | */ | 263 | */ |
267 | public function testAddNotABookmark() | 264 | public function testAddNotABookmark() |
268 | { | 265 | { |
266 | $this->expectException(\Exception::class); | ||
267 | $this->expectExceptionMessage('Provided data is invalid'); | ||
268 | |||
269 | $this->privateLinkDB->add(['title' => 'hi!']); | 269 | $this->privateLinkDB->add(['title' => 'hi!']); |
270 | } | 270 | } |
271 | 271 | ||
272 | /** | 272 | /** |
273 | * Test add() method with a Bookmark already containing an ID | 273 | * Test add() method with a Bookmark already containing an ID |
274 | * | ||
275 | * @expectedException \Exception | ||
276 | * @expectedExceptionMessage This bookmarks already exists | ||
277 | */ | 274 | */ |
278 | public function testAddWithId() | 275 | public function testAddWithId() |
279 | { | 276 | { |
277 | $this->expectException(\Exception::class); | ||
278 | $this->expectExceptionMessage('This bookmarks already exists'); | ||
279 | |||
280 | $bookmark = new Bookmark(); | 280 | $bookmark = new Bookmark(); |
281 | $bookmark->setId(43); | 281 | $bookmark->setId(43); |
282 | $this->privateLinkDB->add($bookmark); | 282 | $this->privateLinkDB->add($bookmark); |
@@ -397,44 +397,44 @@ class BookmarkFileServiceTest extends TestCase | |||
397 | 397 | ||
398 | /** | 398 | /** |
399 | * Test set() method while logged out | 399 | * Test set() method while logged out |
400 | * | ||
401 | * @expectedException \Exception | ||
402 | * @expectedExceptionMessage You're not authorized to alter the datastore | ||
403 | */ | 400 | */ |
404 | public function testSetLoggedOut() | 401 | public function testSetLoggedOut() |
405 | { | 402 | { |
403 | $this->expectException(\Exception::class); | ||
404 | $this->expectExceptionMessage('You\'re not authorized to alter the datastore'); | ||
405 | |||
406 | $this->publicLinkDB->set(new Bookmark()); | 406 | $this->publicLinkDB->set(new Bookmark()); |
407 | } | 407 | } |
408 | 408 | ||
409 | /** | 409 | /** |
410 | * Test set() method with an entry which is not a bookmark instance | 410 | * Test set() method with an entry which is not a bookmark instance |
411 | * | ||
412 | * @expectedException \Exception | ||
413 | * @expectedExceptionMessage Provided data is invalid | ||
414 | */ | 411 | */ |
415 | public function testSetNotABookmark() | 412 | public function testSetNotABookmark() |
416 | { | 413 | { |
414 | $this->expectException(\Exception::class); | ||
415 | $this->expectExceptionMessage('Provided data is invalid'); | ||
416 | |||
417 | $this->privateLinkDB->set(['title' => 'hi!']); | 417 | $this->privateLinkDB->set(['title' => 'hi!']); |
418 | } | 418 | } |
419 | 419 | ||
420 | /** | 420 | /** |
421 | * Test set() method with a Bookmark without an ID defined. | 421 | * Test set() method with a Bookmark without an ID defined. |
422 | * | ||
423 | * @expectedException Shaarli\Bookmark\Exception\BookmarkNotFoundException | ||
424 | */ | 422 | */ |
425 | public function testSetWithoutId() | 423 | public function testSetWithoutId() |
426 | { | 424 | { |
425 | $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class); | ||
426 | |||
427 | $bookmark = new Bookmark(); | 427 | $bookmark = new Bookmark(); |
428 | $this->privateLinkDB->set($bookmark); | 428 | $this->privateLinkDB->set($bookmark); |
429 | } | 429 | } |
430 | 430 | ||
431 | /** | 431 | /** |
432 | * Test set() method with a Bookmark with an unknow ID | 432 | * Test set() method with a Bookmark with an unknow ID |
433 | * | ||
434 | * @expectedException Shaarli\Bookmark\Exception\BookmarkNotFoundException | ||
435 | */ | 433 | */ |
436 | public function testSetWithUnknownId() | 434 | public function testSetWithUnknownId() |
437 | { | 435 | { |
436 | $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class); | ||
437 | |||
438 | $bookmark = new Bookmark(); | 438 | $bookmark = new Bookmark(); |
439 | $bookmark->setId(666); | 439 | $bookmark->setId(666); |
440 | $this->privateLinkDB->set($bookmark); | 440 | $this->privateLinkDB->set($bookmark); |
@@ -481,23 +481,23 @@ class BookmarkFileServiceTest extends TestCase | |||
481 | 481 | ||
482 | /** | 482 | /** |
483 | * Test addOrSet() method while logged out | 483 | * Test addOrSet() method while logged out |
484 | * | ||
485 | * @expectedException \Exception | ||
486 | * @expectedExceptionMessage You're not authorized to alter the datastore | ||
487 | */ | 484 | */ |
488 | public function testAddOrSetLoggedOut() | 485 | public function testAddOrSetLoggedOut() |
489 | { | 486 | { |
487 | $this->expectException(\Exception::class); | ||
488 | $this->expectExceptionMessage('You\'re not authorized to alter the datastore'); | ||
489 | |||
490 | $this->publicLinkDB->addOrSet(new Bookmark()); | 490 | $this->publicLinkDB->addOrSet(new Bookmark()); |
491 | } | 491 | } |
492 | 492 | ||
493 | /** | 493 | /** |
494 | * Test addOrSet() method with an entry which is not a bookmark instance | 494 | * Test addOrSet() method with an entry which is not a bookmark instance |
495 | * | ||
496 | * @expectedException \Exception | ||
497 | * @expectedExceptionMessage Provided data is invalid | ||
498 | */ | 495 | */ |
499 | public function testAddOrSetNotABookmark() | 496 | public function testAddOrSetNotABookmark() |
500 | { | 497 | { |
498 | $this->expectException(\Exception::class); | ||
499 | $this->expectExceptionMessage('Provided data is invalid'); | ||
500 | |||
501 | $this->privateLinkDB->addOrSet(['title' => 'hi!']); | 501 | $this->privateLinkDB->addOrSet(['title' => 'hi!']); |
502 | } | 502 | } |
503 | 503 | ||
@@ -524,11 +524,11 @@ class BookmarkFileServiceTest extends TestCase | |||
524 | 524 | ||
525 | /** | 525 | /** |
526 | * Test remove() method with an existing Bookmark | 526 | * Test remove() method with an existing Bookmark |
527 | * | ||
528 | * @expectedException Shaarli\Bookmark\Exception\BookmarkNotFoundException | ||
529 | */ | 527 | */ |
530 | public function testRemoveExisting() | 528 | public function testRemoveExisting() |
531 | { | 529 | { |
530 | $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class); | ||
531 | |||
532 | $bookmark = $this->privateLinkDB->get(42); | 532 | $bookmark = $this->privateLinkDB->get(42); |
533 | $this->privateLinkDB->remove($bookmark); | 533 | $this->privateLinkDB->remove($bookmark); |
534 | 534 | ||
@@ -548,34 +548,34 @@ class BookmarkFileServiceTest extends TestCase | |||
548 | 548 | ||
549 | /** | 549 | /** |
550 | * Test remove() method while logged out | 550 | * Test remove() method while logged out |
551 | * | ||
552 | * @expectedException \Exception | ||
553 | * @expectedExceptionMessage You're not authorized to alter the datastore | ||
554 | */ | 551 | */ |
555 | public function testRemoveLoggedOut() | 552 | public function testRemoveLoggedOut() |
556 | { | 553 | { |
554 | $this->expectException(\Exception::class); | ||
555 | $this->expectExceptionMessage('You\'re not authorized to alter the datastore'); | ||
556 | |||
557 | $bookmark = $this->privateLinkDB->get(42); | 557 | $bookmark = $this->privateLinkDB->get(42); |
558 | $this->publicLinkDB->remove($bookmark); | 558 | $this->publicLinkDB->remove($bookmark); |
559 | } | 559 | } |
560 | 560 | ||
561 | /** | 561 | /** |
562 | * Test remove() method with an entry which is not a bookmark instance | 562 | * Test remove() method with an entry which is not a bookmark instance |
563 | * | ||
564 | * @expectedException \Exception | ||
565 | * @expectedExceptionMessage Provided data is invalid | ||
566 | */ | 563 | */ |
567 | public function testRemoveNotABookmark() | 564 | public function testRemoveNotABookmark() |
568 | { | 565 | { |
566 | $this->expectException(\Exception::class); | ||
567 | $this->expectExceptionMessage('Provided data is invalid'); | ||
568 | |||
569 | $this->privateLinkDB->remove(['title' => 'hi!']); | 569 | $this->privateLinkDB->remove(['title' => 'hi!']); |
570 | } | 570 | } |
571 | 571 | ||
572 | /** | 572 | /** |
573 | * Test remove() method with a Bookmark with an unknown ID | 573 | * Test remove() method with a Bookmark with an unknown ID |
574 | * | ||
575 | * @expectedException Shaarli\Bookmark\Exception\BookmarkNotFoundException | ||
576 | */ | 574 | */ |
577 | public function testRemoveWithUnknownId() | 575 | public function testRemoveWithUnknownId() |
578 | { | 576 | { |
577 | $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class); | ||
578 | |||
579 | $bookmark = new Bookmark(); | 579 | $bookmark = new Bookmark(); |
580 | $bookmark->setId(666); | 580 | $bookmark->setId(666); |
581 | $this->privateLinkDB->remove($bookmark); | 581 | $this->privateLinkDB->remove($bookmark); |
@@ -615,14 +615,18 @@ class BookmarkFileServiceTest extends TestCase | |||
615 | { | 615 | { |
616 | $dbSize = $this->privateLinkDB->count(); | 616 | $dbSize = $this->privateLinkDB->count(); |
617 | $this->privateLinkDB->initialize(); | 617 | $this->privateLinkDB->initialize(); |
618 | $this->assertEquals($dbSize + 2, $this->privateLinkDB->count()); | 618 | $this->assertEquals($dbSize + 3, $this->privateLinkDB->count()); |
619 | $this->assertEquals( | 619 | $this->assertStringStartsWith( |
620 | 'My secret stuff... - Pastebin.com', | 620 | 'Shaarli will automatically pick up the thumbnail for links to a variety of websites.', |
621 | $this->privateLinkDB->get(43)->getTitle() | 621 | $this->privateLinkDB->get(43)->getDescription() |
622 | ); | 622 | ); |
623 | $this->assertEquals( | 623 | $this->assertStringStartsWith( |
624 | 'The personal, minimalist, super-fast, database free, bookmarking service', | 624 | 'Adding a shaare without entering a URL creates a text-only "note" post such as this one.', |
625 | $this->privateLinkDB->get(44)->getTitle() | 625 | $this->privateLinkDB->get(44)->getDescription() |
626 | ); | ||
627 | $this->assertStringStartsWith( | ||
628 | 'Welcome to Shaarli!', | ||
629 | $this->privateLinkDB->get(45)->getDescription() | ||
626 | ); | 630 | ); |
627 | } | 631 | } |
628 | 632 | ||
@@ -631,15 +635,14 @@ class BookmarkFileServiceTest extends TestCase | |||
631 | * to make sure that nothing have been broken in the migration process. | 635 | * to make sure that nothing have been broken in the migration process. |
632 | * They mostly cover search/filters. Some of them might be redundant with the previous ones. | 636 | * They mostly cover search/filters. Some of them might be redundant with the previous ones. |
633 | */ | 637 | */ |
634 | |||
635 | /** | 638 | /** |
636 | * Attempt to instantiate a LinkDB whereas the datastore is not writable | 639 | * Attempt to instantiate a LinkDB whereas the datastore is not writable |
637 | * | ||
638 | * @expectedException Shaarli\Bookmark\Exception\NotWritableDataStoreException | ||
639 | * @expectedExceptionMessageRegExp #Couldn't load data from the data store file "null".*# | ||
640 | */ | 640 | */ |
641 | public function testConstructDatastoreNotWriteable() | 641 | public function testConstructDatastoreNotWriteable() |
642 | { | 642 | { |
643 | $this->expectException(\Shaarli\Bookmark\Exception\NotWritableDataStoreException::class); | ||
644 | $this->expectExceptionMessageRegExp('#Couldn\'t load data from the data store file "null".*#'); | ||
645 | |||
643 | $conf = new ConfigManager('tests/utils/config/configJson'); | 646 | $conf = new ConfigManager('tests/utils/config/configJson'); |
644 | $conf->set('resource.datastore', 'null/store.db'); | 647 | $conf->set('resource.datastore', 'null/store.db'); |
645 | new BookmarkFileService($conf, $this->history, true); | 648 | new BookmarkFileService($conf, $this->history, true); |
@@ -744,7 +747,7 @@ class BookmarkFileServiceTest extends TestCase | |||
744 | $link = $this->publicLinkDB->findByUrl('http://mediagoblin.org/'); | 747 | $link = $this->publicLinkDB->findByUrl('http://mediagoblin.org/'); |
745 | 748 | ||
746 | $this->assertNotEquals(false, $link); | 749 | $this->assertNotEquals(false, $link); |
747 | $this->assertContains( | 750 | $this->assertContainsPolyfill( |
748 | 'A free software media publishing platform', | 751 | 'A free software media publishing platform', |
749 | $link->getDescription() | 752 | $link->getDescription() |
750 | ); | 753 | ); |
@@ -1062,6 +1065,36 @@ class BookmarkFileServiceTest extends TestCase | |||
1062 | } | 1065 | } |
1063 | 1066 | ||
1064 | /** | 1067 | /** |
1068 | * Test filterDay while logged in | ||
1069 | */ | ||
1070 | public function testFilterDayLoggedIn(): void | ||
1071 | { | ||
1072 | $bookmarks = $this->privateLinkDB->filterDay('20121206'); | ||
1073 | $expectedIds = [4, 9, 1, 0]; | ||
1074 | |||
1075 | static::assertCount(4, $bookmarks); | ||
1076 | foreach ($bookmarks as $bookmark) { | ||
1077 | $i = ($i ?? -1) + 1; | ||
1078 | static::assertSame($expectedIds[$i], $bookmark->getId()); | ||
1079 | } | ||
1080 | } | ||
1081 | |||
1082 | /** | ||
1083 | * Test filterDay while logged out | ||
1084 | */ | ||
1085 | public function testFilterDayLoggedOut(): void | ||
1086 | { | ||
1087 | $bookmarks = $this->publicLinkDB->filterDay('20121206'); | ||
1088 | $expectedIds = [4, 9, 1]; | ||
1089 | |||
1090 | static::assertCount(3, $bookmarks); | ||
1091 | foreach ($bookmarks as $bookmark) { | ||
1092 | $i = ($i ?? -1) + 1; | ||
1093 | static::assertSame($expectedIds[$i], $bookmark->getId()); | ||
1094 | } | ||
1095 | } | ||
1096 | |||
1097 | /** | ||
1065 | * Allows to test LinkDB's private methods | 1098 | * Allows to test LinkDB's private methods |
1066 | * | 1099 | * |
1067 | * @see | 1100 | * @see |
diff --git a/tests/bookmark/BookmarkFilterTest.php b/tests/bookmark/BookmarkFilterTest.php index d4c71cb9..48c7f824 100644 --- a/tests/bookmark/BookmarkFilterTest.php +++ b/tests/bookmark/BookmarkFilterTest.php | |||
@@ -3,11 +3,10 @@ | |||
3 | namespace Shaarli\Bookmark; | 3 | namespace Shaarli\Bookmark; |
4 | 4 | ||
5 | use Exception; | 5 | use Exception; |
6 | use PHPUnit\Framework\TestCase; | ||
7 | use ReferenceLinkDB; | 6 | use ReferenceLinkDB; |
8 | use Shaarli\Config\ConfigManager; | 7 | use Shaarli\Config\ConfigManager; |
9 | use Shaarli\Formatter\FormatterFactory; | ||
10 | use Shaarli\History; | 8 | use Shaarli\History; |
9 | use Shaarli\TestCase; | ||
11 | 10 | ||
12 | /** | 11 | /** |
13 | * Class BookmarkFilterTest. | 12 | * Class BookmarkFilterTest. |
@@ -36,7 +35,7 @@ class BookmarkFilterTest extends TestCase | |||
36 | /** | 35 | /** |
37 | * Instantiate linkFilter with ReferenceLinkDB data. | 36 | * Instantiate linkFilter with ReferenceLinkDB data. |
38 | */ | 37 | */ |
39 | public static function setUpBeforeClass() | 38 | public static function setUpBeforeClass(): void |
40 | { | 39 | { |
41 | $conf = new ConfigManager('tests/utils/config/configJson'); | 40 | $conf = new ConfigManager('tests/utils/config/configJson'); |
42 | $conf->set('resource.datastore', self::$testDatastore); | 41 | $conf->set('resource.datastore', self::$testDatastore); |
@@ -190,6 +189,17 @@ class BookmarkFilterTest extends TestCase | |||
190 | } | 189 | } |
191 | 190 | ||
192 | /** | 191 | /** |
192 | * Return bookmarks for a given day | ||
193 | */ | ||
194 | public function testFilterDayRestrictedVisibility(): void | ||
195 | { | ||
196 | $this->assertEquals( | ||
197 | 3, | ||
198 | count(self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, '20121206', false, BookmarkFilter::$PUBLIC)) | ||
199 | ); | ||
200 | } | ||
201 | |||
202 | /** | ||
193 | * 404 - day not found | 203 | * 404 - day not found |
194 | */ | 204 | */ |
195 | public function testFilterUnknownDay() | 205 | public function testFilterUnknownDay() |
@@ -202,21 +212,23 @@ class BookmarkFilterTest extends TestCase | |||
202 | 212 | ||
203 | /** | 213 | /** |
204 | * Use an invalid date format | 214 | * Use an invalid date format |
205 | * @expectedException Exception | ||
206 | * @expectedExceptionMessageRegExp /Invalid date format/ | ||
207 | */ | 215 | */ |
208 | public function testFilterInvalidDayWithChars() | 216 | public function testFilterInvalidDayWithChars() |
209 | { | 217 | { |
218 | $this->expectException(\Exception::class); | ||
219 | $this->expectExceptionMessageRegExp('/Invalid date format/'); | ||
220 | |||
210 | self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, 'Rainy day, dream away'); | 221 | self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, 'Rainy day, dream away'); |
211 | } | 222 | } |
212 | 223 | ||
213 | /** | 224 | /** |
214 | * Use an invalid date format | 225 | * Use an invalid date format |
215 | * @expectedException Exception | ||
216 | * @expectedExceptionMessageRegExp /Invalid date format/ | ||
217 | */ | 226 | */ |
218 | public function testFilterInvalidDayDigits() | 227 | public function testFilterInvalidDayDigits() |
219 | { | 228 | { |
229 | $this->expectException(\Exception::class); | ||
230 | $this->expectExceptionMessageRegExp('/Invalid date format/'); | ||
231 | |||
220 | self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, '20'); | 232 | self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, '20'); |
221 | } | 233 | } |
222 | 234 | ||
@@ -240,11 +252,11 @@ class BookmarkFilterTest extends TestCase | |||
240 | 252 | ||
241 | /** | 253 | /** |
242 | * No link for this hash | 254 | * No link for this hash |
243 | * | ||
244 | * @expectedException \Shaarli\Bookmark\Exception\BookmarkNotFoundException | ||
245 | */ | 255 | */ |
246 | public function testFilterUnknownSmallHash() | 256 | public function testFilterUnknownSmallHash() |
247 | { | 257 | { |
258 | $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class); | ||
259 | |||
248 | self::$linkFilter->filter(BookmarkFilter::$FILTER_HASH, 'Iblaah'); | 260 | self::$linkFilter->filter(BookmarkFilter::$FILTER_HASH, 'Iblaah'); |
249 | } | 261 | } |
250 | 262 | ||
diff --git a/tests/bookmark/BookmarkInitializerTest.php b/tests/bookmark/BookmarkInitializerTest.php index 3906cc7f..25704004 100644 --- a/tests/bookmark/BookmarkInitializerTest.php +++ b/tests/bookmark/BookmarkInitializerTest.php | |||
@@ -2,9 +2,9 @@ | |||
2 | 2 | ||
3 | namespace Shaarli\Bookmark; | 3 | namespace Shaarli\Bookmark; |
4 | 4 | ||
5 | use PHPUnit\Framework\TestCase; | ||
6 | use Shaarli\Config\ConfigManager; | 5 | use Shaarli\Config\ConfigManager; |
7 | use Shaarli\History; | 6 | use Shaarli\History; |
7 | use Shaarli\TestCase; | ||
8 | 8 | ||
9 | /** | 9 | /** |
10 | * Class BookmarkInitializerTest | 10 | * Class BookmarkInitializerTest |
@@ -37,7 +37,7 @@ class BookmarkInitializerTest extends TestCase | |||
37 | /** | 37 | /** |
38 | * Initialize an empty BookmarkFileService | 38 | * Initialize an empty BookmarkFileService |
39 | */ | 39 | */ |
40 | public function setUp() | 40 | public function setUp(): void |
41 | { | 41 | { |
42 | if (file_exists(self::$testDatastore)) { | 42 | if (file_exists(self::$testDatastore)) { |
43 | unlink(self::$testDatastore); | 43 | unlink(self::$testDatastore); |
@@ -64,17 +64,26 @@ class BookmarkInitializerTest extends TestCase | |||
64 | 64 | ||
65 | $this->initializer->initialize(); | 65 | $this->initializer->initialize(); |
66 | 66 | ||
67 | $this->assertEquals($refDB->countLinks() + 2, $this->bookmarkService->count()); | 67 | $this->assertEquals($refDB->countLinks() + 3, $this->bookmarkService->count()); |
68 | |||
68 | $bookmark = $this->bookmarkService->get(43); | 69 | $bookmark = $this->bookmarkService->get(43); |
69 | $this->assertEquals(43, $bookmark->getId()); | 70 | $this->assertStringStartsWith( |
70 | $this->assertEquals('My secret stuff... - Pastebin.com', $bookmark->getTitle()); | 71 | 'Shaarli will automatically pick up the thumbnail for links to a variety of websites.', |
72 | $bookmark->getDescription() | ||
73 | ); | ||
71 | $this->assertTrue($bookmark->isPrivate()); | 74 | $this->assertTrue($bookmark->isPrivate()); |
72 | 75 | ||
73 | $bookmark = $this->bookmarkService->get(44); | 76 | $bookmark = $this->bookmarkService->get(44); |
74 | $this->assertEquals(44, $bookmark->getId()); | 77 | $this->assertStringStartsWith( |
75 | $this->assertEquals( | 78 | 'Adding a shaare without entering a URL creates a text-only "note" post such as this one.', |
76 | 'The personal, minimalist, super-fast, database free, bookmarking service', | 79 | $bookmark->getDescription() |
77 | $bookmark->getTitle() | 80 | ); |
81 | $this->assertTrue($bookmark->isPrivate()); | ||
82 | |||
83 | $bookmark = $this->bookmarkService->get(45); | ||
84 | $this->assertStringStartsWith( | ||
85 | 'Welcome to Shaarli!', | ||
86 | $bookmark->getDescription() | ||
78 | ); | 87 | ); |
79 | $this->assertFalse($bookmark->isPrivate()); | 88 | $this->assertFalse($bookmark->isPrivate()); |
80 | 89 | ||
@@ -82,17 +91,26 @@ class BookmarkInitializerTest extends TestCase | |||
82 | 91 | ||
83 | // Reload from file | 92 | // Reload from file |
84 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); | 93 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); |
85 | $this->assertEquals($refDB->countLinks() + 2, $this->bookmarkService->count()); | 94 | $this->assertEquals($refDB->countLinks() + 3, $this->bookmarkService->count()); |
95 | |||
86 | $bookmark = $this->bookmarkService->get(43); | 96 | $bookmark = $this->bookmarkService->get(43); |
87 | $this->assertEquals(43, $bookmark->getId()); | 97 | $this->assertStringStartsWith( |
88 | $this->assertEquals('My secret stuff... - Pastebin.com', $bookmark->getTitle()); | 98 | 'Shaarli will automatically pick up the thumbnail for links to a variety of websites.', |
99 | $bookmark->getDescription() | ||
100 | ); | ||
89 | $this->assertTrue($bookmark->isPrivate()); | 101 | $this->assertTrue($bookmark->isPrivate()); |
90 | 102 | ||
91 | $bookmark = $this->bookmarkService->get(44); | 103 | $bookmark = $this->bookmarkService->get(44); |
92 | $this->assertEquals(44, $bookmark->getId()); | 104 | $this->assertStringStartsWith( |
93 | $this->assertEquals( | 105 | 'Adding a shaare without entering a URL creates a text-only "note" post such as this one.', |
94 | 'The personal, minimalist, super-fast, database free, bookmarking service', | 106 | $bookmark->getDescription() |
95 | $bookmark->getTitle() | 107 | ); |
108 | $this->assertTrue($bookmark->isPrivate()); | ||
109 | |||
110 | $bookmark = $this->bookmarkService->get(45); | ||
111 | $this->assertStringStartsWith( | ||
112 | 'Welcome to Shaarli!', | ||
113 | $bookmark->getDescription() | ||
96 | ); | 114 | ); |
97 | $this->assertFalse($bookmark->isPrivate()); | 115 | $this->assertFalse($bookmark->isPrivate()); |
98 | } | 116 | } |
@@ -107,17 +125,25 @@ class BookmarkInitializerTest extends TestCase | |||
107 | 125 | ||
108 | $this->initializer->initialize(); | 126 | $this->initializer->initialize(); |
109 | 127 | ||
110 | $this->assertEquals(2, $this->bookmarkService->count()); | 128 | $this->assertEquals(3, $this->bookmarkService->count()); |
111 | $bookmark = $this->bookmarkService->get(0); | 129 | $bookmark = $this->bookmarkService->get(0); |
112 | $this->assertEquals(0, $bookmark->getId()); | 130 | $this->assertStringStartsWith( |
113 | $this->assertEquals('My secret stuff... - Pastebin.com', $bookmark->getTitle()); | 131 | 'Shaarli will automatically pick up the thumbnail for links to a variety of websites.', |
132 | $bookmark->getDescription() | ||
133 | ); | ||
114 | $this->assertTrue($bookmark->isPrivate()); | 134 | $this->assertTrue($bookmark->isPrivate()); |
115 | 135 | ||
116 | $bookmark = $this->bookmarkService->get(1); | 136 | $bookmark = $this->bookmarkService->get(1); |
117 | $this->assertEquals(1, $bookmark->getId()); | 137 | $this->assertStringStartsWith( |
118 | $this->assertEquals( | 138 | 'Adding a shaare without entering a URL creates a text-only "note" post such as this one.', |
119 | 'The personal, minimalist, super-fast, database free, bookmarking service', | 139 | $bookmark->getDescription() |
120 | $bookmark->getTitle() | 140 | ); |
141 | $this->assertTrue($bookmark->isPrivate()); | ||
142 | |||
143 | $bookmark = $this->bookmarkService->get(2); | ||
144 | $this->assertStringStartsWith( | ||
145 | 'Welcome to Shaarli!', | ||
146 | $bookmark->getDescription() | ||
121 | ); | 147 | ); |
122 | $this->assertFalse($bookmark->isPrivate()); | 148 | $this->assertFalse($bookmark->isPrivate()); |
123 | } | 149 | } |
diff --git a/tests/bookmark/BookmarkTest.php b/tests/bookmark/BookmarkTest.php index 4b6a3c07..afec2440 100644 --- a/tests/bookmark/BookmarkTest.php +++ b/tests/bookmark/BookmarkTest.php | |||
@@ -2,8 +2,8 @@ | |||
2 | 2 | ||
3 | namespace Shaarli\Bookmark; | 3 | namespace Shaarli\Bookmark; |
4 | 4 | ||
5 | use PHPUnit\Framework\TestCase; | ||
6 | use Shaarli\Bookmark\Exception\InvalidBookmarkException; | 5 | use Shaarli\Bookmark\Exception\InvalidBookmarkException; |
6 | use Shaarli\TestCase; | ||
7 | 7 | ||
8 | /** | 8 | /** |
9 | * Class BookmarkTest | 9 | * Class BookmarkTest |
@@ -150,7 +150,7 @@ class BookmarkTest extends TestCase | |||
150 | $exception = $e; | 150 | $exception = $e; |
151 | } | 151 | } |
152 | $this->assertNotNull($exception); | 152 | $this->assertNotNull($exception); |
153 | $this->assertContains('- ID: '. PHP_EOL, $exception->getMessage()); | 153 | $this->assertContainsPolyfill('- ID: '. PHP_EOL, $exception->getMessage()); |
154 | } | 154 | } |
155 | 155 | ||
156 | /** | 156 | /** |
@@ -169,7 +169,7 @@ class BookmarkTest extends TestCase | |||
169 | $exception = $e; | 169 | $exception = $e; |
170 | } | 170 | } |
171 | $this->assertNotNull($exception); | 171 | $this->assertNotNull($exception); |
172 | $this->assertContains('- ID: str'. PHP_EOL, $exception->getMessage()); | 172 | $this->assertContainsPolyfill('- ID: str'. PHP_EOL, $exception->getMessage()); |
173 | } | 173 | } |
174 | 174 | ||
175 | /** | 175 | /** |
@@ -188,7 +188,7 @@ class BookmarkTest extends TestCase | |||
188 | $exception = $e; | 188 | $exception = $e; |
189 | } | 189 | } |
190 | $this->assertNotNull($exception); | 190 | $this->assertNotNull($exception); |
191 | $this->assertContains('- ShortUrl: '. PHP_EOL, $exception->getMessage()); | 191 | $this->assertContainsPolyfill('- ShortUrl: '. PHP_EOL, $exception->getMessage()); |
192 | } | 192 | } |
193 | 193 | ||
194 | /** | 194 | /** |
@@ -207,7 +207,7 @@ class BookmarkTest extends TestCase | |||
207 | $exception = $e; | 207 | $exception = $e; |
208 | } | 208 | } |
209 | $this->assertNotNull($exception); | 209 | $this->assertNotNull($exception); |
210 | $this->assertContains('- Created: '. PHP_EOL, $exception->getMessage()); | 210 | $this->assertContainsPolyfill('- Created: '. PHP_EOL, $exception->getMessage()); |
211 | } | 211 | } |
212 | 212 | ||
213 | /** | 213 | /** |
@@ -226,7 +226,7 @@ class BookmarkTest extends TestCase | |||
226 | $exception = $e; | 226 | $exception = $e; |
227 | } | 227 | } |
228 | $this->assertNotNull($exception); | 228 | $this->assertNotNull($exception); |
229 | $this->assertContains('- Created: Not a DateTime object'. PHP_EOL, $exception->getMessage()); | 229 | $this->assertContainsPolyfill('- Created: Not a DateTime object'. PHP_EOL, $exception->getMessage()); |
230 | } | 230 | } |
231 | 231 | ||
232 | /** | 232 | /** |
diff --git a/tests/bookmark/LinkUtilsTest.php b/tests/bookmark/LinkUtilsTest.php index cc7819bc..29941c8c 100644 --- a/tests/bookmark/LinkUtilsTest.php +++ b/tests/bookmark/LinkUtilsTest.php | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | namespace Shaarli\Bookmark; | 3 | namespace Shaarli\Bookmark; |
4 | 4 | ||
5 | use PHPUnit\Framework\TestCase; | 5 | use Shaarli\TestCase; |
6 | 6 | ||
7 | require_once 'tests/utils/CurlUtils.php'; | 7 | require_once 'tests/utils/CurlUtils.php'; |
8 | 8 | ||
@@ -43,6 +43,19 @@ class LinkUtilsTest extends TestCase | |||
43 | } | 43 | } |
44 | 44 | ||
45 | /** | 45 | /** |
46 | * Test headers_extract_charset() when the charset is found with odd quotes. | ||
47 | */ | ||
48 | public function testHeadersExtractExistentCharsetWithQuotes() | ||
49 | { | ||
50 | $charset = 'x-MacCroatian'; | ||
51 | $headers = 'text/html; charset="' . $charset . '"otherstuff="test"'; | ||
52 | $this->assertEquals(strtolower($charset), header_extract_charset($headers)); | ||
53 | |||
54 | $headers = 'text/html; charset=\'' . $charset . '\'otherstuff="test"'; | ||
55 | $this->assertEquals(strtolower($charset), header_extract_charset($headers)); | ||
56 | } | ||
57 | |||
58 | /** | ||
46 | * Test headers_extract_charset() when the charset is not found. | 59 | * Test headers_extract_charset() when the charset is not found. |
47 | */ | 60 | */ |
48 | public function testHeadersExtractNonExistentCharset() | 61 | public function testHeadersExtractNonExistentCharset() |
@@ -526,13 +539,13 @@ class LinkUtilsTest extends TestCase | |||
526 | カタカナ #カタカナ」カタカナ\n'; | 539 | カタカナ #カタカナ」カタカナ\n'; |
527 | $autolinkedDescription = hashtag_autolink($rawDescription, $index); | 540 | $autolinkedDescription = hashtag_autolink($rawDescription, $index); |
528 | 541 | ||
529 | $this->assertContains($this->getHashtagLink('hashtag', $index), $autolinkedDescription); | 542 | $this->assertContainsPolyfill($this->getHashtagLink('hashtag', $index), $autolinkedDescription); |
530 | $this->assertNotContains(' #hashtag', $autolinkedDescription); | 543 | $this->assertNotContainsPolyfill(' #hashtag', $autolinkedDescription); |
531 | $this->assertNotContains('>#nothashtag', $autolinkedDescription); | 544 | $this->assertNotContainsPolyfill('>#nothashtag', $autolinkedDescription); |
532 | $this->assertContains($this->getHashtagLink('ашок', $index), $autolinkedDescription); | 545 | $this->assertContainsPolyfill($this->getHashtagLink('ашок', $index), $autolinkedDescription); |
533 | $this->assertContains($this->getHashtagLink('カタカナ', $index), $autolinkedDescription); | 546 | $this->assertContainsPolyfill($this->getHashtagLink('カタカナ', $index), $autolinkedDescription); |
534 | $this->assertContains($this->getHashtagLink('hashtag_hashtag', $index), $autolinkedDescription); | 547 | $this->assertContainsPolyfill($this->getHashtagLink('hashtag_hashtag', $index), $autolinkedDescription); |
535 | $this->assertNotContains($this->getHashtagLink('hashtag-nothashtag', $index), $autolinkedDescription); | 548 | $this->assertNotContainsPolyfill($this->getHashtagLink('hashtag-nothashtag', $index), $autolinkedDescription); |
536 | } | 549 | } |
537 | 550 | ||
538 | /** | 551 | /** |
@@ -543,9 +556,9 @@ class LinkUtilsTest extends TestCase | |||
543 | $rawDescription = 'blabla #hashtag x#nothashtag'; | 556 | $rawDescription = 'blabla #hashtag x#nothashtag'; |
544 | $autolinkedDescription = hashtag_autolink($rawDescription); | 557 | $autolinkedDescription = hashtag_autolink($rawDescription); |
545 | 558 | ||
546 | $this->assertContains($this->getHashtagLink('hashtag'), $autolinkedDescription); | 559 | $this->assertContainsPolyfill($this->getHashtagLink('hashtag'), $autolinkedDescription); |
547 | $this->assertNotContains(' #hashtag', $autolinkedDescription); | 560 | $this->assertNotContainsPolyfill(' #hashtag', $autolinkedDescription); |
548 | $this->assertNotContains('>#nothashtag', $autolinkedDescription); | 561 | $this->assertNotContainsPolyfill('>#nothashtag', $autolinkedDescription); |
549 | } | 562 | } |
550 | 563 | ||
551 | /** | 564 | /** |