3 namespace Shaarli\Netscape
;
6 use malkusch\lock\mutex\NoMutex
;
7 use Psr\Http\Message\UploadedFileInterface
;
8 use Shaarli\Bookmark\Bookmark
;
9 use Shaarli\Bookmark\BookmarkFileService
;
10 use Shaarli\Bookmark\BookmarkFilter
;
11 use Shaarli\Config\ConfigManager
;
13 use Shaarli\Plugin\PluginManager
;
15 use Slim\Http\UploadedFile
;
18 * Utility function to load a file's metadata in a $_FILES-like array
20 * @param string $filename Basename of the file
22 * @return UploadedFileInterface Upload file in PSR-7 compatible object
24 function file2array($filename)
26 return new UploadedFile(
27 __DIR__
. '/input/' . $filename,
30 filesize(__DIR__
. '/input/' . $filename)
36 * Netscape bookmark import
38 class BookmarkImportTest
extends TestCase
41 * @var string datastore to test write operations
43 protected static $testDatastore = 'sandbox/datastore.php';
46 * @var string History file path
48 protected static $historyFilePath = 'sandbox/history.php';
51 * @var BookmarkFileService private LinkDB instance
53 protected $bookmarkService = null;
56 * @var string Dummy page cache
58 protected $pagecache = 'tests';
61 * @var ConfigManager instance.
66 * @var History instance.
71 * @var NetscapeBookmarkUtils
73 protected $netscapeBookmarkUtils;
75 /** @var PluginManager */
76 protected $pluginManager;
79 * @var string Save the current timezone.
81 protected static $defaultTimeZone;
83 public static function setUpBeforeClass(): void
85 self
::$defaultTimeZone = date_default_timezone_get();
86 // Timezone without DST for test consistency
87 date_default_timezone_set('Africa/Nairobi');
91 * Resets test data before each test
93 protected function setUp(): void
95 $mutex = new NoMutex();
96 if (file_exists(self
::$testDatastore)) {
97 unlink(self
::$testDatastore);
99 // start with an empty datastore
100 file_put_contents(self
::$testDatastore, '<?php /* S7QysKquBQA= */ ?>');
102 $this->conf
= new ConfigManager('tests/utils/config/configJson');
103 $this->conf
->set('resource.page_cache', $this->pagecache
);
104 $this->conf
->set('resource.datastore', self
::$testDatastore);
105 $this->history
= new History(self
::$historyFilePath);
106 $this->pluginManager
= new PluginManager($this->conf
);
107 $this->bookmarkService
= new BookmarkFileService(
109 $this->pluginManager
,
114 $this->netscapeBookmarkUtils
= new NetscapeBookmarkUtils($this->bookmarkService
, $this->conf
, $this->history
);
118 * Delete history file.
120 protected function tearDown(): void
122 @unlink(self
::$historyFilePath);
125 public static function tearDownAfterClass(): void
127 date_default_timezone_set(self
::$defaultTimeZone);
131 * Attempt to import bookmarks from an empty file
133 public function testImportEmptyData()
135 $files = file2array('empty.htm');
137 'File empty.htm (0 bytes) has an unknown file format.'
138 .' Nothing was imported.',
139 $this->netscapeBookmarkUtils
->import(null, $files)
141 $this->assertEquals(0, $this->bookmarkService
->count());
145 * Attempt to import bookmarks from a file with no Doctype
147 public function testImportNoDoctype()
149 $files = file2array('no_doctype.htm');
151 'File no_doctype.htm (350 bytes) has an unknown file format. Nothing was imported.',
152 $this->netscapeBookmarkUtils
->import(null, $files)
154 $this->assertEquals(0, $this->bookmarkService
->count());
158 * Attempt to import bookmarks from a file with a lowercase Doctype
160 public function testImportLowecaseDoctype()
162 $files = file2array('lowercase_doctype.htm');
163 $this->assertStringMatchesFormat(
164 'File lowercase_doctype.htm (386 bytes) was successfully processed in %d seconds:'
165 .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
166 $this->netscapeBookmarkUtils
->import(null, $files)
168 $this->assertEquals(2, $this->bookmarkService
->count());
173 * Ensure IE dumps are supported
175 public function testImportInternetExplorerEncoding()
177 $files = file2array('internet_explorer_encoding.htm');
178 $this->assertStringMatchesFormat(
179 'File internet_explorer_encoding.htm (356 bytes) was successfully processed in %d seconds:'
180 .' 1 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
181 $this->netscapeBookmarkUtils
->import([], $files)
183 $this->assertEquals(1, $this->bookmarkService
->count());
184 $this->assertEquals(0, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
186 $bookmark = $this->bookmarkService
->findByUrl('http://hginit.com/');
187 $this->assertEquals(0, $bookmark->getId());
189 DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, '20160618_203944'),
190 $bookmark->getCreated()
192 $this->assertEquals('Hg Init a Mercurial tutorial by Joel Spolsky', $bookmark->getTitle());
193 $this->assertEquals('http://hginit.com/', $bookmark->getUrl());
194 $this->assertEquals('', $bookmark->getDescription());
195 $this->assertFalse($bookmark->isPrivate());
196 $this->assertEquals('', $bookmark->getTagsString());
197 $this->assertEquals('La37cg', $bookmark->getShortUrl());
201 * Import bookmarks nested in a folder hierarchy
203 public function testImportNested()
205 $files = file2array('netscape_nested.htm');
206 $this->assertStringMatchesFormat(
207 'File netscape_nested.htm (1337 bytes) was successfully processed in %d seconds:'
208 .' 8 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
209 $this->netscapeBookmarkUtils
->import([], $files)
211 $this->assertEquals(8, $this->bookmarkService
->count());
212 $this->assertEquals(2, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
214 $bookmark = $this->bookmarkService
->findByUrl('http://nest.ed/1');
215 $this->assertEquals(0, $bookmark->getId());
217 DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, '20160225_235541'),
218 $bookmark->getCreated()
220 $this->assertEquals('Nested 1', $bookmark->getTitle());
221 $this->assertEquals('http://nest.ed/1', $bookmark->getUrl());
222 $this->assertEquals('', $bookmark->getDescription());
223 $this->assertFalse($bookmark->isPrivate());
224 $this->assertEquals('tag1 tag2', $bookmark->getTagsString());
225 $this->assertEquals('KyDNKA', $bookmark->getShortUrl());
227 $bookmark = $this->bookmarkService
->findByUrl('http://nest.ed/1-1');
228 $this->assertEquals(1, $bookmark->getId());
230 DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, '20160225_235542'),
231 $bookmark->getCreated()
233 $this->assertEquals('Nested 1-1', $bookmark->getTitle());
234 $this->assertEquals('http://nest.ed/1-1', $bookmark->getUrl());
235 $this->assertEquals('', $bookmark->getDescription());
236 $this->assertFalse($bookmark->isPrivate());
237 $this->assertEquals('folder1 tag1 tag2', $bookmark->getTagsString());
238 $this->assertEquals('T2LnXg', $bookmark->getShortUrl());
240 $bookmark = $this->bookmarkService
->findByUrl('http://nest.ed/1-2');
241 $this->assertEquals(2, $bookmark->getId());
243 DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, '20160225_235547'),
244 $bookmark->getCreated()
246 $this->assertEquals('Nested 1-2', $bookmark->getTitle());
247 $this->assertEquals('http://nest.ed/1-2', $bookmark->getUrl());
248 $this->assertEquals('', $bookmark->getDescription());
249 $this->assertFalse($bookmark->isPrivate());
250 $this->assertEquals('folder1 tag3 tag4', $bookmark->getTagsString());
251 $this->assertEquals('46SZxA', $bookmark->getShortUrl());
253 $bookmark = $this->bookmarkService
->findByUrl('http://nest.ed/2-1');
254 $this->assertEquals(3, $bookmark->getId());
256 DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, '20160202_202222'),
257 $bookmark->getCreated()
259 $this->assertEquals('Nested 2-1', $bookmark->getTitle());
260 $this->assertEquals('http://nest.ed/2-1', $bookmark->getUrl());
261 $this->assertEquals('First link of the second section', $bookmark->getDescription());
262 $this->assertTrue($bookmark->isPrivate());
263 $this->assertEquals('folder2', $bookmark->getTagsString());
264 $this->assertEquals('4UHOSw', $bookmark->getShortUrl());
266 $bookmark = $this->bookmarkService
->findByUrl('http://nest.ed/2-2');
267 $this->assertEquals(4, $bookmark->getId());
269 DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, '20160119_230227'),
270 $bookmark->getCreated()
272 $this->assertEquals('Nested 2-2', $bookmark->getTitle());
273 $this->assertEquals('http://nest.ed/2-2', $bookmark->getUrl());
274 $this->assertEquals('Second link of the second section', $bookmark->getDescription());
275 $this->assertTrue($bookmark->isPrivate());
276 $this->assertEquals('folder2', $bookmark->getTagsString());
277 $this->assertEquals('yfzwbw', $bookmark->getShortUrl());
279 $bookmark = $this->bookmarkService
->findByUrl('http://nest.ed/3-1');
280 $this->assertEquals(5, $bookmark->getId());
282 DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, '20160202_202222'),
283 $bookmark->getCreated()
285 $this->assertEquals('Nested 3-1', $bookmark->getTitle());
286 $this->assertEquals('http://nest.ed/3-1', $bookmark->getUrl());
287 $this->assertEquals('', $bookmark->getDescription());
288 $this->assertFalse($bookmark->isPrivate());
289 $this->assertEquals('folder3 folder3-1 tag3', $bookmark->getTagsString());
290 $this->assertEquals('UwxIUQ', $bookmark->getShortUrl());
292 $bookmark = $this->bookmarkService
->findByUrl('http://nest.ed/3-2');
293 $this->assertEquals(6, $bookmark->getId());
295 DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, '20160119_230227'),
296 $bookmark->getCreated()
298 $this->assertEquals('Nested 3-2', $bookmark->getTitle());
299 $this->assertEquals('http://nest.ed/3-2', $bookmark->getUrl());
300 $this->assertEquals('', $bookmark->getDescription());
301 $this->assertFalse($bookmark->isPrivate());
302 $this->assertEquals('folder3 folder3-1', $bookmark->getTagsString());
303 $this->assertEquals('p8dyZg', $bookmark->getShortUrl());
305 $bookmark = $this->bookmarkService
->findByUrl('http://nest.ed/2');
306 $this->assertEquals(7, $bookmark->getId());
308 DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, '20160229_111541'),
309 $bookmark->getCreated()
311 $this->assertEquals('Nested 2', $bookmark->getTitle());
312 $this->assertEquals('http://nest.ed/2', $bookmark->getUrl());
313 $this->assertEquals('', $bookmark->getDescription());
314 $this->assertFalse($bookmark->isPrivate());
315 $this->assertEquals('tag4', $bookmark->getTagsString());
316 $this->assertEquals('Gt3Uug', $bookmark->getShortUrl());
320 * Import bookmarks with the default privacy setting (reuse from file)
322 * The $_POST array is not set.
324 public function testImportDefaultPrivacyNoPost()
326 $files = file2array('netscape_basic.htm');
327 $this->assertStringMatchesFormat(
328 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
329 .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
330 $this->netscapeBookmarkUtils
->import([], $files)
333 $this->assertEquals(2, $this->bookmarkService
->count());
334 $this->assertEquals(1, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
336 $bookmark = $this->bookmarkService
->findByUrl('https://private.tld');
337 $this->assertEquals(0, $bookmark->getId());
339 DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, '20001010_135536'),
340 $bookmark->getCreated()
342 $this->assertEquals('Secret stuff', $bookmark->getTitle());
343 $this->assertEquals('https://private.tld', $bookmark->getUrl());
344 $this->assertEquals('Super-secret stuff you\'re not supposed to know about', $bookmark->getDescription());
345 $this->assertTrue($bookmark->isPrivate());
346 $this->assertEquals('private secret', $bookmark->getTagsString());
347 $this->assertEquals('EokDtA', $bookmark->getShortUrl());
349 $bookmark = $this->bookmarkService
->findByUrl('http://public.tld');
350 $this->assertEquals(1, $bookmark->getId());
352 DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, '20160225_235548'),
353 $bookmark->getCreated()
355 $this->assertEquals('Public stuff', $bookmark->getTitle());
356 $this->assertEquals('http://public.tld', $bookmark->getUrl());
357 $this->assertEquals('', $bookmark->getDescription());
358 $this->assertFalse($bookmark->isPrivate());
359 $this->assertEquals('public hello world', $bookmark->getTagsString());
360 $this->assertEquals('Er9ddA', $bookmark->getShortUrl());
364 * Import bookmarks with the default privacy setting (reuse from file)
366 public function testImportKeepPrivacy()
368 $post = array('privacy' => 'default');
369 $files = file2array('netscape_basic.htm');
370 $this->assertStringMatchesFormat(
371 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
372 .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
373 $this->netscapeBookmarkUtils
->import($post, $files)
376 $this->assertEquals(2, $this->bookmarkService
->count());
377 $this->assertEquals(1, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
379 $bookmark = $this->bookmarkService
->findByUrl('https://private.tld');
380 $this->assertEquals(0, $bookmark->getId());
382 DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, '20001010_135536'),
383 $bookmark->getCreated()
385 $this->assertEquals('Secret stuff', $bookmark->getTitle());
386 $this->assertEquals('https://private.tld', $bookmark->getUrl());
387 $this->assertEquals('Super-secret stuff you\'re not supposed to know about', $bookmark->getDescription());
388 $this->assertTrue($bookmark->isPrivate());
389 $this->assertEquals('private secret', $bookmark->getTagsString());
390 $this->assertEquals('EokDtA', $bookmark->getShortUrl());
392 $bookmark = $this->bookmarkService
->findByUrl('http://public.tld');
393 $this->assertEquals(1, $bookmark->getId());
395 DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, '20160225_235548'),
396 $bookmark->getCreated()
398 $this->assertEquals('Public stuff', $bookmark->getTitle());
399 $this->assertEquals('http://public.tld', $bookmark->getUrl());
400 $this->assertEquals('', $bookmark->getDescription());
401 $this->assertFalse($bookmark->isPrivate());
402 $this->assertEquals('public hello world', $bookmark->getTagsString());
403 $this->assertEquals('Er9ddA', $bookmark->getShortUrl());
407 * Import bookmarks as public
409 public function testImportAsPublic()
411 $post = array('privacy' => 'public');
412 $files = file2array('netscape_basic.htm');
413 $this->assertStringMatchesFormat(
414 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
415 .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
416 $this->netscapeBookmarkUtils
->import($post, $files)
418 $this->assertEquals(2, $this->bookmarkService
->count());
419 $this->assertEquals(0, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
420 $this->assertFalse($this->bookmarkService
->get(0)->isPrivate());
421 $this->assertFalse($this->bookmarkService
->get(1)->isPrivate());
425 * Import bookmarks as private
427 public function testImportAsPrivate()
429 $post = array('privacy' => 'private');
430 $files = file2array('netscape_basic.htm');
431 $this->assertStringMatchesFormat(
432 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
433 .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
434 $this->netscapeBookmarkUtils
->import($post, $files)
436 $this->assertEquals(2, $this->bookmarkService
->count());
437 $this->assertEquals(2, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
438 $this->assertTrue($this->bookmarkService
->get(0)->isPrivate());
439 $this->assertTrue($this->bookmarkService
->get(1)->isPrivate());
443 * Overwrite private bookmarks so they become public
445 public function testOverwriteAsPublic()
447 $files = file2array('netscape_basic.htm');
449 // import bookmarks as private
450 $post = array('privacy' => 'private');
451 $this->assertStringMatchesFormat(
452 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
453 .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
454 $this->netscapeBookmarkUtils
->import($post, $files)
456 $this->assertEquals(2, $this->bookmarkService
->count());
457 $this->assertEquals(2, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
458 $this->assertTrue($this->bookmarkService
->get(0)->isPrivate());
459 $this->assertTrue($this->bookmarkService
->get(1)->isPrivate());
461 // re-import as public, enable overwriting
463 'privacy' => 'public',
464 'overwrite' => 'true'
466 $this->assertStringMatchesFormat(
467 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
468 .' 2 bookmarks imported, 2 bookmarks overwritten, 0 bookmarks skipped.',
469 $this->netscapeBookmarkUtils
->import($post, $files)
471 $this->assertEquals(2, $this->bookmarkService
->count());
472 $this->assertEquals(0, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
473 $this->assertFalse($this->bookmarkService
->get(0)->isPrivate());
474 $this->assertFalse($this->bookmarkService
->get(1)->isPrivate());
478 * Overwrite public bookmarks so they become private
480 public function testOverwriteAsPrivate()
482 $files = file2array('netscape_basic.htm');
484 // import bookmarks as public
485 $post = array('privacy' => 'public');
486 $this->assertStringMatchesFormat(
487 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
488 .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
489 $this->netscapeBookmarkUtils
->import($post, $files)
491 $this->assertEquals(2, $this->bookmarkService
->count());
492 $this->assertEquals(0, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
493 $this->assertFalse($this->bookmarkService
->get(0)->isPrivate());
494 $this->assertFalse($this->bookmarkService
->get(1)->isPrivate());
496 // re-import as private, enable overwriting
498 'privacy' => 'private',
499 'overwrite' => 'true'
501 $this->assertStringMatchesFormat(
502 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
503 .' 2 bookmarks imported, 2 bookmarks overwritten, 0 bookmarks skipped.',
504 $this->netscapeBookmarkUtils
->import($post, $files)
506 $this->assertEquals(2, $this->bookmarkService
->count());
507 $this->assertEquals(2, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
508 $this->assertTrue($this->bookmarkService
->get(0)->isPrivate());
509 $this->assertTrue($this->bookmarkService
->get(1)->isPrivate());
513 * Attept to import the same bookmarks twice without enabling overwriting
515 public function testSkipOverwrite()
517 $post = array('privacy' => 'public');
518 $files = file2array('netscape_basic.htm');
519 $this->assertStringMatchesFormat(
520 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
521 .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
522 $this->netscapeBookmarkUtils
->import($post, $files)
524 $this->assertEquals(2, $this->bookmarkService
->count());
525 $this->assertEquals(0, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
527 // re-import as private, DO NOT enable overwriting
528 $post = array('privacy' => 'private');
529 $this->assertStringMatchesFormat(
530 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
531 .' 0 bookmarks imported, 0 bookmarks overwritten, 2 bookmarks skipped.',
532 $this->netscapeBookmarkUtils
->import($post, $files)
534 $this->assertEquals(2, $this->bookmarkService
->count());
535 $this->assertEquals(0, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
539 * Add user-specified tags to all imported bookmarks
541 public function testSetDefaultTags()
544 'privacy' => 'public',
545 'default_tags' => 'tag1 tag2 tag3'
547 $files = file2array('netscape_basic.htm');
548 $this->assertStringMatchesFormat(
549 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
550 .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
551 $this->netscapeBookmarkUtils
->import($post, $files)
553 $this->assertEquals(2, $this->bookmarkService
->count());
554 $this->assertEquals(0, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
555 $this->assertEquals('tag1 tag2 tag3 private secret', $this->bookmarkService
->get(0)->getTagsString());
556 $this->assertEquals('tag1 tag2 tag3 public hello world', $this->bookmarkService
->get(1)->getTagsString());
560 * The user-specified tags contain characters to be escaped
562 public function testSanitizeDefaultTags()
565 'privacy' => 'public',
566 'default_tags' => 'tag1& tag2 "tag3"'
568 $files = file2array('netscape_basic.htm');
569 $this->assertStringMatchesFormat(
570 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
571 .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
572 $this->netscapeBookmarkUtils
->import($post, $files)
574 $this->assertEquals(2, $this->bookmarkService
->count());
575 $this->assertEquals(0, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
577 'tag1& tag2 "tag3" private secret',
578 $this->bookmarkService
->get(0)->getTagsString()
581 'tag1& tag2 "tag3" public hello world',
582 $this->bookmarkService
->get(1)->getTagsString()
587 * Add user-specified tags to all imported bookmarks
589 public function testSetDefaultTagsWithCustomSeparator()
592 $this->conf
->set('general.tags_separator', $separator);
594 'privacy' => 'public',
595 'default_tags' => 'tag1@tag2@tag3@multiple words tag'
597 $files = file2array('netscape_basic.htm');
598 $this->assertStringMatchesFormat(
599 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
600 .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
601 $this->netscapeBookmarkUtils
->import($post, $files)
603 $this->assertEquals(2, $this->bookmarkService
->count());
604 $this->assertEquals(0, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
606 'tag1@tag2@tag3@multiple words tag@private@secret',
607 $this->bookmarkService
->get(0)->getTagsString($separator)
610 ['tag1', 'tag2', 'tag3', 'multiple words tag', 'private', 'secret'],
611 $this->bookmarkService
->get(0)->getTags()
614 'tag1@tag2@tag3@multiple words tag@public@hello@world',
615 $this->bookmarkService
->get(1)->getTagsString($separator)
618 ['tag1', 'tag2', 'tag3', 'multiple words tag', 'public', 'hello', 'world'],
619 $this->bookmarkService
->get(1)->getTags()
624 * Ensure each imported bookmark has a unique id
626 * See https://github.com/shaarli/Shaarli/issues/351
628 public function testImportSameDate()
630 $files = file2array('same_date.htm');
631 $this->assertStringMatchesFormat(
632 'File same_date.htm (453 bytes) was successfully processed in %d seconds:'
633 .' 3 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
634 $this->netscapeBookmarkUtils
->import(array(), $files)
636 $this->assertEquals(3, $this->bookmarkService
->count());
637 $this->assertEquals(0, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
638 $this->assertEquals(0, $this->bookmarkService
->get(0)->getId());
639 $this->assertEquals(1, $this->bookmarkService
->get(1)->getId());
640 $this->assertEquals(2, $this->bookmarkService
->get(2)->getId());
643 public function testImportCreateUpdateHistory()
646 'privacy' => 'public',
647 'overwrite' => 'true',
649 $files = file2array('netscape_basic.htm');
650 $this->netscapeBookmarkUtils
->import($post, $files);
651 $history = $this->history
->getHistory();
652 $this->assertEquals(1, count($history));
653 $this->assertEquals(History
::IMPORT
, $history[0]['event']);
654 $this->assertTrue(new DateTime('-5 seconds') < $history[0]['datetime']);
656 // re-import as private, enable overwriting
657 $this->netscapeBookmarkUtils
->import($post, $files);
658 $history = $this->history
->getHistory();
659 $this->assertEquals(2, count($history));
660 $this->assertEquals(History
::IMPORT
, $history[0]['event']);
661 $this->assertTrue(new DateTime('-5 seconds') < $history[0]['datetime']);
662 $this->assertEquals(History
::IMPORT
, $history[1]['event']);
663 $this->assertTrue(new DateTime('-5 seconds') < $history[1]['datetime']);