aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/bookmark/LinkUtilsTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/bookmark/LinkUtilsTest.php')
-rw-r--r--tests/bookmark/LinkUtilsTest.php124
1 files changed, 119 insertions, 5 deletions
diff --git a/tests/bookmark/LinkUtilsTest.php b/tests/bookmark/LinkUtilsTest.php
index 3321242f..c2f9f930 100644
--- a/tests/bookmark/LinkUtilsTest.php
+++ b/tests/bookmark/LinkUtilsTest.php
@@ -247,7 +247,8 @@ class LinkUtilsTest extends TestCase
247 $title, 247 $title,
248 $desc, 248 $desc,
249 $keywords, 249 $keywords,
250 false 250 false,
251 ' '
251 ); 252 );
252 253
253 $data = [ 254 $data = [
@@ -297,7 +298,8 @@ class LinkUtilsTest extends TestCase
297 $title, 298 $title,
298 $desc, 299 $desc,
299 $keywords, 300 $keywords,
300 false 301 false,
302 ' '
301 ); 303 );
302 304
303 $data = [ 305 $data = [
@@ -330,7 +332,8 @@ class LinkUtilsTest extends TestCase
330 $title, 332 $title,
331 $desc, 333 $desc,
332 $keywords, 334 $keywords,
333 false 335 false,
336 ' '
334 ); 337 );
335 338
336 $data = [ 339 $data = [
@@ -363,7 +366,8 @@ class LinkUtilsTest extends TestCase
363 $title, 366 $title,
364 $desc, 367 $desc,
365 $keywords, 368 $keywords,
366 false 369 false,
370 ' '
367 ); 371 );
368 372
369 $data = [ 373 $data = [
@@ -428,7 +432,8 @@ class LinkUtilsTest extends TestCase
428 $title, 432 $title,
429 $desc, 433 $desc,
430 $keywords, 434 $keywords,
431 true 435 true,
436 ' '
432 ); 437 );
433 $data = [ 438 $data = [
434 'th=device-width">' 439 'th=device-width">'
@@ -575,6 +580,115 @@ class LinkUtilsTest extends TestCase
575 } 580 }
576 581
577 /** 582 /**
583 * Test tags_str2array with whitespace separator.
584 */
585 public function testTagsStr2ArrayWithSpaceSeparator(): void
586 {
587 $separator = ' ';
588
589 static::assertSame(['tag1', 'tag2', 'tag3'], tags_str2array('tag1 tag2 tag3', $separator));
590 static::assertSame(['tag1', 'tag2', 'tag3'], tags_str2array('tag1 tag2 tag3', $separator));
591 static::assertSame(['tag1', 'tag2', 'tag3'], tags_str2array(' tag1 tag2 tag3 ', $separator));
592 static::assertSame(['tag1@', 'tag2,', '.tag3'], tags_str2array(' tag1@ tag2, .tag3 ', $separator));
593 static::assertSame([], tags_str2array('', $separator));
594 static::assertSame([], tags_str2array(' ', $separator));
595 static::assertSame([], tags_str2array(null, $separator));
596 }
597
598 /**
599 * Test tags_str2array with @ separator.
600 */
601 public function testTagsStr2ArrayWithCharSeparator(): void
602 {
603 $separator = '@';
604
605 static::assertSame(['tag1', 'tag2', 'tag3'], tags_str2array('tag1@tag2@tag3', $separator));
606 static::assertSame(['tag1', 'tag2', 'tag3'], tags_str2array('tag1@@@@tag2@@@@tag3', $separator));
607 static::assertSame(['tag1', 'tag2', 'tag3'], tags_str2array('@@@tag1@@@tag2@@@@tag3@@', $separator));
608 static::assertSame(
609 ['tag1#', 'tag2, and other', '.tag3'],
610 tags_str2array('@@@ tag1# @@@ tag2, and other @@@@.tag3@@', $separator)
611 );
612 static::assertSame([], tags_str2array('', $separator));
613 static::assertSame([], tags_str2array(' ', $separator));
614 static::assertSame([], tags_str2array(null, $separator));
615 }
616
617 /**
618 * Test tags_array2str with ' ' separator.
619 */
620 public function testTagsArray2StrWithSpaceSeparator(): void
621 {
622 $separator = ' ';
623
624 static::assertSame('tag1 tag2 tag3', tags_array2str(['tag1', 'tag2', 'tag3'], $separator));
625 static::assertSame('tag1, tag2@ tag3', tags_array2str(['tag1,', 'tag2@', 'tag3'], $separator));
626 static::assertSame('tag1 tag2 tag3', tags_array2str([' tag1 ', 'tag2', 'tag3 '], $separator));
627 static::assertSame('tag1 tag2 tag3', tags_array2str([' tag1 ', ' ', 'tag2', ' ', 'tag3 '], $separator));
628 static::assertSame('tag1', tags_array2str([' tag1 '], $separator));
629 static::assertSame('', tags_array2str([' '], $separator));
630 static::assertSame('', tags_array2str([], $separator));
631 static::assertSame('', tags_array2str(null, $separator));
632 }
633
634 /**
635 * Test tags_array2str with @ separator.
636 */
637 public function testTagsArray2StrWithCharSeparator(): void
638 {
639 $separator = '@';
640
641 static::assertSame('tag1@tag2@tag3', tags_array2str(['tag1', 'tag2', 'tag3'], $separator));
642 static::assertSame('tag1,@tag2@tag3', tags_array2str(['tag1,', 'tag2@', 'tag3'], $separator));
643 static::assertSame(
644 'tag1@tag2, and other@tag3',
645 tags_array2str(['@@@@ tag1@@@', ' @tag2, and other @', 'tag3@@@@'], $separator)
646 );
647 static::assertSame('tag1@tag2@tag3', tags_array2str(['@@@tag1@@@', '@', 'tag2', '@@@', 'tag3@@@'], $separator));
648 static::assertSame('tag1', tags_array2str(['@@@@tag1@@@@'], $separator));
649 static::assertSame('', tags_array2str(['@@@'], $separator));
650 static::assertSame('', tags_array2str([], $separator));
651 static::assertSame('', tags_array2str(null, $separator));
652 }
653
654 /**
655 * Test tags_array2str with @ separator.
656 */
657 public function testTagsFilterWithSpaceSeparator(): void
658 {
659 $separator = ' ';
660
661 static::assertSame(['tag1', 'tag2', 'tag3'], tags_filter(['tag1', 'tag2', 'tag3'], $separator));
662 static::assertSame(['tag1,', 'tag2@', 'tag3'], tags_filter(['tag1,', 'tag2@', 'tag3'], $separator));
663 static::assertSame(['tag1', 'tag2', 'tag3'], tags_filter([' tag1 ', 'tag2', 'tag3 '], $separator));
664 static::assertSame(['tag1', 'tag2', 'tag3'], tags_filter([' tag1 ', ' ', 'tag2', ' ', 'tag3 '], $separator));
665 static::assertSame(['tag1'], tags_filter([' tag1 '], $separator));
666 static::assertSame([], tags_filter([' '], $separator));
667 static::assertSame([], tags_filter([], $separator));
668 static::assertSame([], tags_filter(null, $separator));
669 }
670
671 /**
672 * Test tags_array2str with @ separator.
673 */
674 public function testTagsArrayFilterWithSpaceSeparator(): void
675 {
676 $separator = '@';
677
678 static::assertSame(['tag1', 'tag2', 'tag3'], tags_filter(['tag1', 'tag2', 'tag3'], $separator));
679 static::assertSame(['tag1,', 'tag2#', 'tag3'], tags_filter(['tag1,', 'tag2#', 'tag3'], $separator));
680 static::assertSame(
681 ['tag1', 'tag2, and other', 'tag3'],
682 tags_filter(['@@@@ tag1@@@', ' @tag2, and other @', 'tag3@@@@'], $separator)
683 );
684 static::assertSame(['tag1', 'tag2', 'tag3'], tags_filter(['@@@tag1@@@', '@', 'tag2', '@@@', 'tag3@@@'], $separator));
685 static::assertSame(['tag1'], tags_filter(['@@@@tag1@@@@'], $separator));
686 static::assertSame([], tags_filter(['@@@'], $separator));
687 static::assertSame([], tags_filter([], $separator));
688 static::assertSame([], tags_filter(null, $separator));
689 }
690
691 /**
578 * Util function to build an hashtag link. 692 * Util function to build an hashtag link.
579 * 693 *
580 * @param string $hashtag Hashtag name. 694 * @param string $hashtag Hashtag name.