aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/bookmark
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-10-22 16:21:03 +0200
committerArthurHoaro <arthur@hoa.ro>2020-11-05 17:54:42 +0100
commitb3bd8c3e8d367975980043e772f7cd78b7f96bc6 (patch)
treeec79899ea564c093d8b0578f3e614881a4ea7c3d /tests/bookmark
parent48df9f45b8c4b2995c1e04146071628668531b37 (diff)
downloadShaarli-b3bd8c3e8d367975980043e772f7cd78b7f96bc6.tar.gz
Shaarli-b3bd8c3e8d367975980043e772f7cd78b7f96bc6.tar.zst
Shaarli-b3bd8c3e8d367975980043e772f7cd78b7f96bc6.zip
Feature: support any tag separator
So it allows to have multiple words tags. Breaking change: commas ',' are no longer a default separator. Fixes #594
Diffstat (limited to 'tests/bookmark')
-rw-r--r--tests/bookmark/BookmarkFilterTest.php2
-rw-r--r--tests/bookmark/BookmarkTest.php25
-rw-r--r--tests/bookmark/LinkUtilsTest.php124
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 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.