diff options
Diffstat (limited to 'tests/bookmark')
-rw-r--r-- | tests/bookmark/BookmarkFilterTest.php | 2 | ||||
-rw-r--r-- | tests/bookmark/BookmarkTest.php | 25 | ||||
-rw-r--r-- | tests/bookmark/LinkUtilsTest.php | 124 |
3 files changed, 141 insertions, 10 deletions
diff --git a/tests/bookmark/BookmarkFilterTest.php b/tests/bookmark/BookmarkFilterTest.php index 574d8e3f..835674f2 100644 --- a/tests/bookmark/BookmarkFilterTest.php +++ b/tests/bookmark/BookmarkFilterTest.php | |||
@@ -44,7 +44,7 @@ class BookmarkFilterTest extends TestCase | |||
44 | self::$refDB->write(self::$testDatastore); | 44 | self::$refDB->write(self::$testDatastore); |
45 | $history = new History('sandbox/history.php'); | 45 | $history = new History('sandbox/history.php'); |
46 | self::$bookmarkService = new \FakeBookmarkService($conf, $history, $mutex, true); | 46 | self::$bookmarkService = new \FakeBookmarkService($conf, $history, $mutex, true); |
47 | self::$linkFilter = new BookmarkFilter(self::$bookmarkService->getBookmarks()); | 47 | self::$linkFilter = new BookmarkFilter(self::$bookmarkService->getBookmarks(), $conf); |
48 | } | 48 | } |
49 | 49 | ||
50 | /** | 50 | /** |
diff --git a/tests/bookmark/BookmarkTest.php b/tests/bookmark/BookmarkTest.php index 4c1ae25d..cb91b26b 100644 --- a/tests/bookmark/BookmarkTest.php +++ b/tests/bookmark/BookmarkTest.php | |||
@@ -79,6 +79,23 @@ class BookmarkTest extends TestCase | |||
79 | } | 79 | } |
80 | 80 | ||
81 | /** | 81 | /** |
82 | * Test fromArray() with a link with a custom tags separator | ||
83 | */ | ||
84 | public function testFromArrayCustomTagsSeparator() | ||
85 | { | ||
86 | $data = [ | ||
87 | 'id' => 1, | ||
88 | 'tags' => ['tag1', 'tag2', 'chair'], | ||
89 | ]; | ||
90 | |||
91 | $bookmark = (new Bookmark())->fromArray($data, '@'); | ||
92 | $this->assertEquals($data['id'], $bookmark->getId()); | ||
93 | $this->assertEquals($data['tags'], $bookmark->getTags()); | ||
94 | $this->assertEquals('tag1@tag2@chair', $bookmark->getTagsString('@')); | ||
95 | } | ||
96 | |||
97 | |||
98 | /** | ||
82 | * Test validate() with a valid minimal bookmark | 99 | * Test validate() with a valid minimal bookmark |
83 | */ | 100 | */ |
84 | public function testValidateValidFullBookmark() | 101 | public function testValidateValidFullBookmark() |
@@ -252,7 +269,7 @@ class BookmarkTest extends TestCase | |||
252 | { | 269 | { |
253 | $bookmark = new Bookmark(); | 270 | $bookmark = new Bookmark(); |
254 | 271 | ||
255 | $str = 'tag1 tag2 tag3.tag3-2, tag4 , -tag5 '; | 272 | $str = 'tag1 tag2 tag3.tag3-2 tag4 -tag5 '; |
256 | $bookmark->setTagsString($str); | 273 | $bookmark->setTagsString($str); |
257 | $this->assertEquals( | 274 | $this->assertEquals( |
258 | [ | 275 | [ |
@@ -276,9 +293,9 @@ class BookmarkTest extends TestCase | |||
276 | $array = [ | 293 | $array = [ |
277 | 'tag1 ', | 294 | 'tag1 ', |
278 | ' tag2', | 295 | ' tag2', |
279 | 'tag3.tag3-2,', | 296 | 'tag3.tag3-2', |
280 | ', tag4', | 297 | ' tag4', |
281 | ', ', | 298 | ' ', |
282 | '-tag5 ', | 299 | '-tag5 ', |
283 | ]; | 300 | ]; |
284 | $bookmark->setTags($array); | 301 | $bookmark->setTags($array); |
diff --git a/tests/bookmark/LinkUtilsTest.php b/tests/bookmark/LinkUtilsTest.php index 9bddf84b..ddab4e3c 100644 --- a/tests/bookmark/LinkUtilsTest.php +++ b/tests/bookmark/LinkUtilsTest.php | |||
@@ -277,7 +277,8 @@ class LinkUtilsTest extends TestCase | |||
277 | $title, | 277 | $title, |
278 | $desc, | 278 | $desc, |
279 | $keywords, | 279 | $keywords, |
280 | false | 280 | false, |
281 | ' ' | ||
281 | ); | 282 | ); |
282 | 283 | ||
283 | $data = [ | 284 | $data = [ |
@@ -327,7 +328,8 @@ class LinkUtilsTest extends TestCase | |||
327 | $title, | 328 | $title, |
328 | $desc, | 329 | $desc, |
329 | $keywords, | 330 | $keywords, |
330 | false | 331 | false, |
332 | ' ' | ||
331 | ); | 333 | ); |
332 | 334 | ||
333 | $data = [ | 335 | $data = [ |
@@ -360,7 +362,8 @@ class LinkUtilsTest extends TestCase | |||
360 | $title, | 362 | $title, |
361 | $desc, | 363 | $desc, |
362 | $keywords, | 364 | $keywords, |
363 | false | 365 | false, |
366 | ' ' | ||
364 | ); | 367 | ); |
365 | 368 | ||
366 | $data = [ | 369 | $data = [ |
@@ -393,7 +396,8 @@ class LinkUtilsTest extends TestCase | |||
393 | $title, | 396 | $title, |
394 | $desc, | 397 | $desc, |
395 | $keywords, | 398 | $keywords, |
396 | false | 399 | false, |
400 | ' ' | ||
397 | ); | 401 | ); |
398 | 402 | ||
399 | $data = [ | 403 | $data = [ |
@@ -458,7 +462,8 @@ class LinkUtilsTest extends TestCase | |||
458 | $title, | 462 | $title, |
459 | $desc, | 463 | $desc, |
460 | $keywords, | 464 | $keywords, |
461 | true | 465 | true, |
466 | ' ' | ||
462 | ); | 467 | ); |
463 | $data = [ | 468 | $data = [ |
464 | 'th=device-width">' | 469 | 'th=device-width">' |
@@ -605,6 +610,115 @@ class LinkUtilsTest extends TestCase | |||
605 | } | 610 | } |
606 | 611 | ||
607 | /** | 612 | /** |
613 | * Test tags_str2array with whitespace separator. | ||
614 | */ | ||
615 | public function testTagsStr2ArrayWithSpaceSeparator(): void | ||
616 | { | ||
617 | $separator = ' '; | ||
618 | |||
619 | static::assertSame(['tag1', 'tag2', 'tag3'], tags_str2array('tag1 tag2 tag3', $separator)); | ||
620 | static::assertSame(['tag1', 'tag2', 'tag3'], tags_str2array('tag1 tag2 tag3', $separator)); | ||
621 | static::assertSame(['tag1', 'tag2', 'tag3'], tags_str2array(' tag1 tag2 tag3 ', $separator)); | ||
622 | static::assertSame(['tag1@', 'tag2,', '.tag3'], tags_str2array(' tag1@ tag2, .tag3 ', $separator)); | ||
623 | static::assertSame([], tags_str2array('', $separator)); | ||
624 | static::assertSame([], tags_str2array(' ', $separator)); | ||
625 | static::assertSame([], tags_str2array(null, $separator)); | ||
626 | } | ||
627 | |||
628 | /** | ||
629 | * Test tags_str2array with @ separator. | ||
630 | */ | ||
631 | public function testTagsStr2ArrayWithCharSeparator(): void | ||
632 | { | ||
633 | $separator = '@'; | ||
634 | |||
635 | static::assertSame(['tag1', 'tag2', 'tag3'], tags_str2array('tag1@tag2@tag3', $separator)); | ||
636 | static::assertSame(['tag1', 'tag2', 'tag3'], tags_str2array('tag1@@@@tag2@@@@tag3', $separator)); | ||
637 | static::assertSame(['tag1', 'tag2', 'tag3'], tags_str2array('@@@tag1@@@tag2@@@@tag3@@', $separator)); | ||
638 | static::assertSame( | ||
639 | ['tag1#', 'tag2, and other', '.tag3'], | ||
640 | tags_str2array('@@@ tag1# @@@ tag2, and other @@@@.tag3@@', $separator) | ||
641 | ); | ||
642 | static::assertSame([], tags_str2array('', $separator)); | ||
643 | static::assertSame([], tags_str2array(' ', $separator)); | ||
644 | static::assertSame([], tags_str2array(null, $separator)); | ||
645 | } | ||
646 | |||
647 | /** | ||
648 | * Test tags_array2str with ' ' separator. | ||
649 | */ | ||
650 | public function testTagsArray2StrWithSpaceSeparator(): void | ||
651 | { | ||
652 | $separator = ' '; | ||
653 | |||
654 | static::assertSame('tag1 tag2 tag3', tags_array2str(['tag1', 'tag2', 'tag3'], $separator)); | ||
655 | static::assertSame('tag1, tag2@ tag3', tags_array2str(['tag1,', 'tag2@', 'tag3'], $separator)); | ||
656 | static::assertSame('tag1 tag2 tag3', tags_array2str([' tag1 ', 'tag2', 'tag3 '], $separator)); | ||
657 | static::assertSame('tag1 tag2 tag3', tags_array2str([' tag1 ', ' ', 'tag2', ' ', 'tag3 '], $separator)); | ||
658 | static::assertSame('tag1', tags_array2str([' tag1 '], $separator)); | ||
659 | static::assertSame('', tags_array2str([' '], $separator)); | ||
660 | static::assertSame('', tags_array2str([], $separator)); | ||
661 | static::assertSame('', tags_array2str(null, $separator)); | ||
662 | } | ||
663 | |||
664 | /** | ||
665 | * Test tags_array2str with @ separator. | ||
666 | */ | ||
667 | public function testTagsArray2StrWithCharSeparator(): void | ||
668 | { | ||
669 | $separator = '@'; | ||
670 | |||
671 | static::assertSame('tag1@tag2@tag3', tags_array2str(['tag1', 'tag2', 'tag3'], $separator)); | ||
672 | static::assertSame('tag1,@tag2@tag3', tags_array2str(['tag1,', 'tag2@', 'tag3'], $separator)); | ||
673 | static::assertSame( | ||
674 | 'tag1@tag2, and other@tag3', | ||
675 | tags_array2str(['@@@@ tag1@@@', ' @tag2, and other @', 'tag3@@@@'], $separator) | ||
676 | ); | ||
677 | static::assertSame('tag1@tag2@tag3', tags_array2str(['@@@tag1@@@', '@', 'tag2', '@@@', 'tag3@@@'], $separator)); | ||
678 | static::assertSame('tag1', tags_array2str(['@@@@tag1@@@@'], $separator)); | ||
679 | static::assertSame('', tags_array2str(['@@@'], $separator)); | ||
680 | static::assertSame('', tags_array2str([], $separator)); | ||
681 | static::assertSame('', tags_array2str(null, $separator)); | ||
682 | } | ||
683 | |||
684 | /** | ||
685 | * Test tags_array2str with @ separator. | ||
686 | */ | ||
687 | public function testTagsFilterWithSpaceSeparator(): void | ||
688 | { | ||
689 | $separator = ' '; | ||
690 | |||
691 | static::assertSame(['tag1', 'tag2', 'tag3'], tags_filter(['tag1', 'tag2', 'tag3'], $separator)); | ||
692 | static::assertSame(['tag1,', 'tag2@', 'tag3'], tags_filter(['tag1,', 'tag2@', 'tag3'], $separator)); | ||
693 | static::assertSame(['tag1', 'tag2', 'tag3'], tags_filter([' tag1 ', 'tag2', 'tag3 '], $separator)); | ||
694 | static::assertSame(['tag1', 'tag2', 'tag3'], tags_filter([' tag1 ', ' ', 'tag2', ' ', 'tag3 '], $separator)); | ||
695 | static::assertSame(['tag1'], tags_filter([' tag1 '], $separator)); | ||
696 | static::assertSame([], tags_filter([' '], $separator)); | ||
697 | static::assertSame([], tags_filter([], $separator)); | ||
698 | static::assertSame([], tags_filter(null, $separator)); | ||
699 | } | ||
700 | |||
701 | /** | ||
702 | * Test tags_array2str with @ separator. | ||
703 | */ | ||
704 | public function testTagsArrayFilterWithSpaceSeparator(): void | ||
705 | { | ||
706 | $separator = '@'; | ||
707 | |||
708 | static::assertSame(['tag1', 'tag2', 'tag3'], tags_filter(['tag1', 'tag2', 'tag3'], $separator)); | ||
709 | static::assertSame(['tag1,', 'tag2#', 'tag3'], tags_filter(['tag1,', 'tag2#', 'tag3'], $separator)); | ||
710 | static::assertSame( | ||
711 | ['tag1', 'tag2, and other', 'tag3'], | ||
712 | tags_filter(['@@@@ tag1@@@', ' @tag2, and other @', 'tag3@@@@'], $separator) | ||
713 | ); | ||
714 | static::assertSame(['tag1', 'tag2', 'tag3'], tags_filter(['@@@tag1@@@', '@', 'tag2', '@@@', 'tag3@@@'], $separator)); | ||
715 | static::assertSame(['tag1'], tags_filter(['@@@@tag1@@@@'], $separator)); | ||
716 | static::assertSame([], tags_filter(['@@@'], $separator)); | ||
717 | static::assertSame([], tags_filter([], $separator)); | ||
718 | static::assertSame([], tags_filter(null, $separator)); | ||
719 | } | ||
720 | |||
721 | /** | ||
608 | * Util function to build an hashtag link. | 722 | * Util function to build an hashtag link. |
609 | * | 723 | * |
610 | * @param string $hashtag Hashtag name. | 724 | * @param string $hashtag Hashtag name. |