X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2Fnetscape%2FBookmarkImportTest.php;h=ecd33ea1af16c1c212be81e0bd7a1aab062a03bb;hb=bcba6bd353161fab456b423e93571ab027d5423c;hp=f678e26bd5ca8d3199242d33f6613bb36f7afecc;hpb=af41d5ab5d2bd3ba64d052c997bc6afa6966a63c;p=github%2Fshaarli%2FShaarli.git diff --git a/tests/netscape/BookmarkImportTest.php b/tests/netscape/BookmarkImportTest.php index f678e26b..ecd33ea1 100644 --- a/tests/netscape/BookmarkImportTest.php +++ b/tests/netscape/BookmarkImportTest.php @@ -3,13 +3,15 @@ namespace Shaarli\Netscape; use DateTime; -use PHPUnit\Framework\TestCase; +use malkusch\lock\mutex\NoMutex; use Psr\Http\Message\UploadedFileInterface; use Shaarli\Bookmark\Bookmark; use Shaarli\Bookmark\BookmarkFileService; use Shaarli\Bookmark\BookmarkFilter; use Shaarli\Config\ConfigManager; use Shaarli\History; +use Shaarli\Plugin\PluginManager; +use Shaarli\TestCase; use Slim\Http\UploadedFile; /** @@ -70,12 +72,15 @@ class BookmarkImportTest extends TestCase */ protected $netscapeBookmarkUtils; + /** @var PluginManager */ + protected $pluginManager; + /** * @var string Save the current timezone. */ protected static $defaultTimeZone; - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { self::$defaultTimeZone = date_default_timezone_get(); // Timezone without DST for test consistency @@ -85,8 +90,9 @@ class BookmarkImportTest extends TestCase /** * Resets test data before each test */ - protected function setUp() + protected function setUp(): void { + $mutex = new NoMutex(); if (file_exists(self::$testDatastore)) { unlink(self::$testDatastore); } @@ -97,19 +103,26 @@ class BookmarkImportTest extends TestCase $this->conf->set('resource.page_cache', $this->pagecache); $this->conf->set('resource.datastore', self::$testDatastore); $this->history = new History(self::$historyFilePath); - $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); + $this->pluginManager = new PluginManager($this->conf); + $this->bookmarkService = new BookmarkFileService( + $this->conf, + $this->pluginManager, + $this->history, + $mutex, + true + ); $this->netscapeBookmarkUtils = new NetscapeBookmarkUtils($this->bookmarkService, $this->conf, $this->history); } /** * Delete history file. */ - public function tearDown() + protected function tearDown(): void { @unlink(self::$historyFilePath); } - public static function tearDownAfterClass() + public static function tearDownAfterClass(): void { date_default_timezone_set(self::$defaultTimeZone); } @@ -529,7 +542,7 @@ class BookmarkImportTest extends TestCase { $post = array( 'privacy' => 'public', - 'default_tags' => 'tag1,tag2 tag3' + 'default_tags' => 'tag1 tag2 tag3' ); $files = file2array('netscape_basic.htm'); $this->assertStringMatchesFormat( @@ -550,7 +563,7 @@ class BookmarkImportTest extends TestCase { $post = array( 'privacy' => 'public', - 'default_tags' => 'tag1&,tag2 "tag3"' + 'default_tags' => 'tag1& tag2 "tag3"' ); $files = file2array('netscape_basic.htm'); $this->assertStringMatchesFormat( @@ -570,6 +583,43 @@ class BookmarkImportTest extends TestCase ); } + /** + * Add user-specified tags to all imported bookmarks + */ + public function testSetDefaultTagsWithCustomSeparator() + { + $separator = '@'; + $this->conf->set('general.tags_separator', $separator); + $post = [ + 'privacy' => 'public', + 'default_tags' => 'tag1@tag2@tag3@multiple words tag' + ]; + $files = file2array('netscape_basic.htm'); + $this->assertStringMatchesFormat( + 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:' + .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.', + $this->netscapeBookmarkUtils->import($post, $files) + ); + $this->assertEquals(2, $this->bookmarkService->count()); + $this->assertEquals(0, $this->bookmarkService->count(BookmarkFilter::$PRIVATE)); + $this->assertEquals( + 'tag1@tag2@tag3@multiple words tag@private@secret', + $this->bookmarkService->get(0)->getTagsString($separator) + ); + $this->assertEquals( + ['tag1', 'tag2', 'tag3', 'multiple words tag', 'private', 'secret'], + $this->bookmarkService->get(0)->getTags() + ); + $this->assertEquals( + 'tag1@tag2@tag3@multiple words tag@public@hello@world', + $this->bookmarkService->get(1)->getTagsString($separator) + ); + $this->assertEquals( + ['tag1', 'tag2', 'tag3', 'multiple words tag', 'public', 'hello', 'world'], + $this->bookmarkService->get(1)->getTags() + ); + } + /** * Ensure each imported bookmark has a unique id *