diff options
Diffstat (limited to 'tests/bookmark/LinkUtilsTest.php')
-rw-r--r-- | tests/bookmark/LinkUtilsTest.php | 154 |
1 files changed, 149 insertions, 5 deletions
diff --git a/tests/bookmark/LinkUtilsTest.php b/tests/bookmark/LinkUtilsTest.php index 3321242f..ddab4e3c 100644 --- a/tests/bookmark/LinkUtilsTest.php +++ b/tests/bookmark/LinkUtilsTest.php | |||
@@ -169,6 +169,36 @@ class LinkUtilsTest extends TestCase | |||
169 | } | 169 | } |
170 | 170 | ||
171 | /** | 171 | /** |
172 | * Test html_extract_tag() with double quoted content containing single quote, and the opposite. | ||
173 | */ | ||
174 | public function testHtmlExtractExistentNameTagWithMixedQuotes(): void | ||
175 | { | ||
176 | $description = 'Bob and Alice share M&M\'s.'; | ||
177 | |||
178 | $html = '<meta property="og:description" content="' . $description . '">'; | ||
179 | $this->assertEquals($description, html_extract_tag('description', $html)); | ||
180 | |||
181 | $html = '<meta tag1="content1" property="og:unrelated1 og:description og:unrelated2" '. | ||
182 | 'tag2="content2" content="' . $description . '" tag3="content3">'; | ||
183 | $this->assertEquals($description, html_extract_tag('description', $html)); | ||
184 | |||
185 | $html = '<meta property="og:description" name="description" content="' . $description . '">'; | ||
186 | $this->assertEquals($description, html_extract_tag('description', $html)); | ||
187 | |||
188 | $description = 'Bob and Alice share "cookies".'; | ||
189 | |||
190 | $html = '<meta property="og:description" content=\'' . $description . '\'>'; | ||
191 | $this->assertEquals($description, html_extract_tag('description', $html)); | ||
192 | |||
193 | $html = '<meta tag1="content1" property="og:unrelated1 og:description og:unrelated2" '. | ||
194 | 'tag2="content2" content=\'' . $description . '\' tag3="content3">'; | ||
195 | $this->assertEquals($description, html_extract_tag('description', $html)); | ||
196 | |||
197 | $html = '<meta property="og:description" name="description" content=\'' . $description . '\'>'; | ||
198 | $this->assertEquals($description, html_extract_tag('description', $html)); | ||
199 | } | ||
200 | |||
201 | /** | ||
172 | * Test html_extract_tag() when the tag <meta name= is not found. | 202 | * Test html_extract_tag() when the tag <meta name= is not found. |
173 | */ | 203 | */ |
174 | public function testHtmlExtractNonExistentNameTag() | 204 | public function testHtmlExtractNonExistentNameTag() |
@@ -247,7 +277,8 @@ class LinkUtilsTest extends TestCase | |||
247 | $title, | 277 | $title, |
248 | $desc, | 278 | $desc, |
249 | $keywords, | 279 | $keywords, |
250 | false | 280 | false, |
281 | ' ' | ||
251 | ); | 282 | ); |
252 | 283 | ||
253 | $data = [ | 284 | $data = [ |
@@ -297,7 +328,8 @@ class LinkUtilsTest extends TestCase | |||
297 | $title, | 328 | $title, |
298 | $desc, | 329 | $desc, |
299 | $keywords, | 330 | $keywords, |
300 | false | 331 | false, |
332 | ' ' | ||
301 | ); | 333 | ); |
302 | 334 | ||
303 | $data = [ | 335 | $data = [ |
@@ -330,7 +362,8 @@ class LinkUtilsTest extends TestCase | |||
330 | $title, | 362 | $title, |
331 | $desc, | 363 | $desc, |
332 | $keywords, | 364 | $keywords, |
333 | false | 365 | false, |
366 | ' ' | ||
334 | ); | 367 | ); |
335 | 368 | ||
336 | $data = [ | 369 | $data = [ |
@@ -363,7 +396,8 @@ class LinkUtilsTest extends TestCase | |||
363 | $title, | 396 | $title, |
364 | $desc, | 397 | $desc, |
365 | $keywords, | 398 | $keywords, |
366 | false | 399 | false, |
400 | ' ' | ||
367 | ); | 401 | ); |
368 | 402 | ||
369 | $data = [ | 403 | $data = [ |
@@ -428,7 +462,8 @@ class LinkUtilsTest extends TestCase | |||
428 | $title, | 462 | $title, |
429 | $desc, | 463 | $desc, |
430 | $keywords, | 464 | $keywords, |
431 | true | 465 | true, |
466 | ' ' | ||
432 | ); | 467 | ); |
433 | $data = [ | 468 | $data = [ |
434 | 'th=device-width">' | 469 | 'th=device-width">' |
@@ -575,6 +610,115 @@ class LinkUtilsTest extends TestCase | |||
575 | } | 610 | } |
576 | 611 | ||
577 | /** | 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 | /** | ||
578 | * Util function to build an hashtag link. | 722 | * Util function to build an hashtag link. |
579 | * | 723 | * |
580 | * @param string $hashtag Hashtag name. | 724 | * @param string $hashtag Hashtag name. |