diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-11-12 13:02:36 +0100 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2020-11-12 13:02:36 +0100 |
commit | 1409f1c89a7ca01456ae2dcd6357d296e2b99f5a (patch) | |
tree | ffa30a9358e82d27be75d8fc5e57f3c8820dc6d3 /tests/netscape/BookmarkImportTest.php | |
parent | 054e03f37fa29da8066f1a637919f13c7e7dc5d2 (diff) | |
parent | a6935feb22df8d9634189ee87d257da9f03eedbd (diff) | |
download | Shaarli-1409f1c89a7ca01456ae2dcd6357d296e2b99f5a.tar.gz Shaarli-1409f1c89a7ca01456ae2dcd6357d296e2b99f5a.tar.zst Shaarli-1409f1c89a7ca01456ae2dcd6357d296e2b99f5a.zip |
Diffstat (limited to 'tests/netscape/BookmarkImportTest.php')
-rw-r--r-- | tests/netscape/BookmarkImportTest.php | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/tests/netscape/BookmarkImportTest.php b/tests/netscape/BookmarkImportTest.php index c1e49b5f..6856ebca 100644 --- a/tests/netscape/BookmarkImportTest.php +++ b/tests/netscape/BookmarkImportTest.php | |||
@@ -3,6 +3,7 @@ | |||
3 | namespace Shaarli\Netscape; | 3 | namespace Shaarli\Netscape; |
4 | 4 | ||
5 | use DateTime; | 5 | use DateTime; |
6 | use malkusch\lock\mutex\NoMutex; | ||
6 | use Psr\Http\Message\UploadedFileInterface; | 7 | use Psr\Http\Message\UploadedFileInterface; |
7 | use Shaarli\Bookmark\Bookmark; | 8 | use Shaarli\Bookmark\Bookmark; |
8 | use Shaarli\Bookmark\BookmarkFileService; | 9 | use Shaarli\Bookmark\BookmarkFileService; |
@@ -87,6 +88,7 @@ class BookmarkImportTest extends TestCase | |||
87 | */ | 88 | */ |
88 | protected function setUp(): void | 89 | protected function setUp(): void |
89 | { | 90 | { |
91 | $mutex = new NoMutex(); | ||
90 | if (file_exists(self::$testDatastore)) { | 92 | if (file_exists(self::$testDatastore)) { |
91 | unlink(self::$testDatastore); | 93 | unlink(self::$testDatastore); |
92 | } | 94 | } |
@@ -97,7 +99,7 @@ class BookmarkImportTest extends TestCase | |||
97 | $this->conf->set('resource.page_cache', $this->pagecache); | 99 | $this->conf->set('resource.page_cache', $this->pagecache); |
98 | $this->conf->set('resource.datastore', self::$testDatastore); | 100 | $this->conf->set('resource.datastore', self::$testDatastore); |
99 | $this->history = new History(self::$historyFilePath); | 101 | $this->history = new History(self::$historyFilePath); |
100 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); | 102 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $mutex, true); |
101 | $this->netscapeBookmarkUtils = new NetscapeBookmarkUtils($this->bookmarkService, $this->conf, $this->history); | 103 | $this->netscapeBookmarkUtils = new NetscapeBookmarkUtils($this->bookmarkService, $this->conf, $this->history); |
102 | } | 104 | } |
103 | 105 | ||
@@ -529,7 +531,7 @@ class BookmarkImportTest extends TestCase | |||
529 | { | 531 | { |
530 | $post = array( | 532 | $post = array( |
531 | 'privacy' => 'public', | 533 | 'privacy' => 'public', |
532 | 'default_tags' => 'tag1,tag2 tag3' | 534 | 'default_tags' => 'tag1 tag2 tag3' |
533 | ); | 535 | ); |
534 | $files = file2array('netscape_basic.htm'); | 536 | $files = file2array('netscape_basic.htm'); |
535 | $this->assertStringMatchesFormat( | 537 | $this->assertStringMatchesFormat( |
@@ -550,7 +552,7 @@ class BookmarkImportTest extends TestCase | |||
550 | { | 552 | { |
551 | $post = array( | 553 | $post = array( |
552 | 'privacy' => 'public', | 554 | 'privacy' => 'public', |
553 | 'default_tags' => 'tag1&,tag2 "tag3"' | 555 | 'default_tags' => 'tag1& tag2 "tag3"' |
554 | ); | 556 | ); |
555 | $files = file2array('netscape_basic.htm'); | 557 | $files = file2array('netscape_basic.htm'); |
556 | $this->assertStringMatchesFormat( | 558 | $this->assertStringMatchesFormat( |
@@ -571,6 +573,43 @@ class BookmarkImportTest extends TestCase | |||
571 | } | 573 | } |
572 | 574 | ||
573 | /** | 575 | /** |
576 | * Add user-specified tags to all imported bookmarks | ||
577 | */ | ||
578 | public function testSetDefaultTagsWithCustomSeparator() | ||
579 | { | ||
580 | $separator = '@'; | ||
581 | $this->conf->set('general.tags_separator', $separator); | ||
582 | $post = [ | ||
583 | 'privacy' => 'public', | ||
584 | 'default_tags' => 'tag1@tag2@tag3@multiple words tag' | ||
585 | ]; | ||
586 | $files = file2array('netscape_basic.htm'); | ||
587 | $this->assertStringMatchesFormat( | ||
588 | 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:' | ||
589 | .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.', | ||
590 | $this->netscapeBookmarkUtils->import($post, $files) | ||
591 | ); | ||
592 | $this->assertEquals(2, $this->bookmarkService->count()); | ||
593 | $this->assertEquals(0, $this->bookmarkService->count(BookmarkFilter::$PRIVATE)); | ||
594 | $this->assertEquals( | ||
595 | 'tag1@tag2@tag3@multiple words tag@private@secret', | ||
596 | $this->bookmarkService->get(0)->getTagsString($separator) | ||
597 | ); | ||
598 | $this->assertEquals( | ||
599 | ['tag1', 'tag2', 'tag3', 'multiple words tag', 'private', 'secret'], | ||
600 | $this->bookmarkService->get(0)->getTags() | ||
601 | ); | ||
602 | $this->assertEquals( | ||
603 | 'tag1@tag2@tag3@multiple words tag@public@hello@world', | ||
604 | $this->bookmarkService->get(1)->getTagsString($separator) | ||
605 | ); | ||
606 | $this->assertEquals( | ||
607 | ['tag1', 'tag2', 'tag3', 'multiple words tag', 'public', 'hello', 'world'], | ||
608 | $this->bookmarkService->get(1)->getTags() | ||
609 | ); | ||
610 | } | ||
611 | |||
612 | /** | ||
574 | * Ensure each imported bookmark has a unique id | 613 | * Ensure each imported bookmark has a unique id |
575 | * | 614 | * |
576 | * See https://github.com/shaarli/Shaarli/issues/351 | 615 | * See https://github.com/shaarli/Shaarli/issues/351 |