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
;
14 use Slim\Http\UploadedFile
;
17 * Utility function to load a file's metadata in a $_FILES-like array
19 * @param string $filename Basename of the file
21 * @return UploadedFileInterface Upload file in PSR-7 compatible object
23 function file2array($filename)
25 return new UploadedFile(
26 __DIR__
. '/input/' . $filename,
29 filesize(__DIR__
. '/input/' . $filename)
35 * Netscape bookmark import
37 class BookmarkImportTest
extends TestCase
40 * @var string datastore to test write operations
42 protected static $testDatastore = 'sandbox/datastore.php';
45 * @var string History file path
47 protected static $historyFilePath = 'sandbox/history.php';
50 * @var BookmarkFileService private LinkDB instance
52 protected $bookmarkService = null;
55 * @var string Dummy page cache
57 protected $pagecache = 'tests';
60 * @var ConfigManager instance.
65 * @var History instance.
70 * @var NetscapeBookmarkUtils
72 protected $netscapeBookmarkUtils;
75 * @var string Save the current timezone.
77 protected static $defaultTimeZone;
79 public static function setUpBeforeClass(): void
81 self
::$defaultTimeZone = date_default_timezone_get();
82 // Timezone without DST for test consistency
83 date_default_timezone_set('Africa/Nairobi');
87 * Resets test data before each test
89 protected function setUp(): void
91 $mutex = new NoMutex();
92 if (file_exists(self
::$testDatastore)) {
93 unlink(self
::$testDatastore);
95 // start with an empty datastore
96 file_put_contents(self
::$testDatastore, '<?php /* S7QysKquBQA= */ ?>');
98 $this->conf
= new ConfigManager('tests/utils/config/configJson');
99 $this->conf
->set('resource.page_cache', $this->pagecache
);
100 $this->conf
->set('resource.datastore', self
::$testDatastore);
101 $this->history
= new History(self
::$historyFilePath);
102 $this->bookmarkService
= new BookmarkFileService($this->conf
, $this->history
, $mutex, true);
103 $this->netscapeBookmarkUtils
= new NetscapeBookmarkUtils($this->bookmarkService
, $this->conf
, $this->history
);
107 * Delete history file.
109 protected function tearDown(): void
111 @unlink(self
::$historyFilePath);
114 public static function tearDownAfterClass(): void
116 date_default_timezone_set(self
::$defaultTimeZone);
120 * Attempt to import bookmarks from an empty file
122 public function testImportEmptyData()
124 $files = file2array('empty.htm');
126 'File empty.htm (0 bytes) has an unknown file format.'
127 .' Nothing was imported.',
128 $this->netscapeBookmarkUtils
->import(null, $files)
130 $this->assertEquals(0, $this->bookmarkService
->count());
134 * Attempt to import bookmarks from a file with no Doctype
136 public function testImportNoDoctype()
138 $files = file2array('no_doctype.htm');
140 'File no_doctype.htm (350 bytes) has an unknown file format. Nothing was imported.',
141 $this->netscapeBookmarkUtils
->import(null, $files)
143 $this->assertEquals(0, $this->bookmarkService
->count());
147 * Attempt to import bookmarks from a file with a lowercase Doctype
149 public function testImportLowecaseDoctype()
151 $files = file2array('lowercase_doctype.htm');
152 $this->assertStringMatchesFormat(
153 'File lowercase_doctype.htm (386 bytes) was successfully processed in %d seconds:'
154 .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
155 $this->netscapeBookmarkUtils
->import(null, $files)
157 $this->assertEquals(2, $this->bookmarkService
->count());
162 * Ensure IE dumps are supported
164 public function testImportInternetExplorerEncoding()
166 $files = file2array('internet_explorer_encoding.htm');
167 $this->assertStringMatchesFormat(
168 'File internet_explorer_encoding.htm (356 bytes) was successfully processed in %d seconds:'
169 .' 1 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
170 $this->netscapeBookmarkUtils
->import([], $files)
172 $this->assertEquals(1, $this->bookmarkService
->count());
173 $this->assertEquals(0, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
175 $bookmark = $this->bookmarkService
->findByUrl('http://hginit.com/');
176 $this->assertEquals(0, $bookmark->getId());
178 DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, '20160618_203944'),
179 $bookmark->getCreated()
181 $this->assertEquals('Hg Init a Mercurial tutorial by Joel Spolsky', $bookmark->getTitle());
182 $this->assertEquals('http://hginit.com/', $bookmark->getUrl());
183 $this->assertEquals('', $bookmark->getDescription());
184 $this->assertFalse($bookmark->isPrivate());
185 $this->assertEquals('', $bookmark->getTagsString());
186 $this->assertEquals('La37cg', $bookmark->getShortUrl());
190 * Import bookmarks nested in a folder hierarchy
192 public function testImportNested()
194 $files = file2array('netscape_nested.htm');
195 $this->assertStringMatchesFormat(
196 'File netscape_nested.htm (1337 bytes) was successfully processed in %d seconds:'
197 .' 8 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
198 $this->netscapeBookmarkUtils
->import([], $files)
200 $this->assertEquals(8, $this->bookmarkService
->count());
201 $this->assertEquals(2, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
203 $bookmark = $this->bookmarkService
->findByUrl('http://nest.ed/1');
204 $this->assertEquals(0, $bookmark->getId());
206 DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, '20160225_235541'),
207 $bookmark->getCreated()
209 $this->assertEquals('Nested 1', $bookmark->getTitle());
210 $this->assertEquals('http://nest.ed/1', $bookmark->getUrl());
211 $this->assertEquals('', $bookmark->getDescription());
212 $this->assertFalse($bookmark->isPrivate());
213 $this->assertEquals('tag1 tag2', $bookmark->getTagsString());
214 $this->assertEquals('KyDNKA', $bookmark->getShortUrl());
216 $bookmark = $this->bookmarkService
->findByUrl('http://nest.ed/1-1');
217 $this->assertEquals(1, $bookmark->getId());
219 DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, '20160225_235542'),
220 $bookmark->getCreated()
222 $this->assertEquals('Nested 1-1', $bookmark->getTitle());
223 $this->assertEquals('http://nest.ed/1-1', $bookmark->getUrl());
224 $this->assertEquals('', $bookmark->getDescription());
225 $this->assertFalse($bookmark->isPrivate());
226 $this->assertEquals('folder1 tag1 tag2', $bookmark->getTagsString());
227 $this->assertEquals('T2LnXg', $bookmark->getShortUrl());
229 $bookmark = $this->bookmarkService
->findByUrl('http://nest.ed/1-2');
230 $this->assertEquals(2, $bookmark->getId());
232 DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, '20160225_235547'),
233 $bookmark->getCreated()
235 $this->assertEquals('Nested 1-2', $bookmark->getTitle());
236 $this->assertEquals('http://nest.ed/1-2', $bookmark->getUrl());
237 $this->assertEquals('', $bookmark->getDescription());
238 $this->assertFalse($bookmark->isPrivate());
239 $this->assertEquals('folder1 tag3 tag4', $bookmark->getTagsString());
240 $this->assertEquals('46SZxA', $bookmark->getShortUrl());
242 $bookmark = $this->bookmarkService
->findByUrl('http://nest.ed/2-1');
243 $this->assertEquals(3, $bookmark->getId());
245 DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, '20160202_202222'),
246 $bookmark->getCreated()
248 $this->assertEquals('Nested 2-1', $bookmark->getTitle());
249 $this->assertEquals('http://nest.ed/2-1', $bookmark->getUrl());
250 $this->assertEquals('First link of the second section', $bookmark->getDescription());
251 $this->assertTrue($bookmark->isPrivate());
252 $this->assertEquals('folder2', $bookmark->getTagsString());
253 $this->assertEquals('4UHOSw', $bookmark->getShortUrl());
255 $bookmark = $this->bookmarkService
->findByUrl('http://nest.ed/2-2');
256 $this->assertEquals(4, $bookmark->getId());
258 DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, '20160119_230227'),
259 $bookmark->getCreated()
261 $this->assertEquals('Nested 2-2', $bookmark->getTitle());
262 $this->assertEquals('http://nest.ed/2-2', $bookmark->getUrl());
263 $this->assertEquals('Second link of the second section', $bookmark->getDescription());
264 $this->assertTrue($bookmark->isPrivate());
265 $this->assertEquals('folder2', $bookmark->getTagsString());
266 $this->assertEquals('yfzwbw', $bookmark->getShortUrl());
268 $bookmark = $this->bookmarkService
->findByUrl('http://nest.ed/3-1');
269 $this->assertEquals(5, $bookmark->getId());
271 DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, '20160202_202222'),
272 $bookmark->getCreated()
274 $this->assertEquals('Nested 3-1', $bookmark->getTitle());
275 $this->assertEquals('http://nest.ed/3-1', $bookmark->getUrl());
276 $this->assertEquals('', $bookmark->getDescription());
277 $this->assertFalse($bookmark->isPrivate());
278 $this->assertEquals('folder3 folder3-1 tag3', $bookmark->getTagsString());
279 $this->assertEquals('UwxIUQ', $bookmark->getShortUrl());
281 $bookmark = $this->bookmarkService
->findByUrl('http://nest.ed/3-2');
282 $this->assertEquals(6, $bookmark->getId());
284 DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, '20160119_230227'),
285 $bookmark->getCreated()
287 $this->assertEquals('Nested 3-2', $bookmark->getTitle());
288 $this->assertEquals('http://nest.ed/3-2', $bookmark->getUrl());
289 $this->assertEquals('', $bookmark->getDescription());
290 $this->assertFalse($bookmark->isPrivate());
291 $this->assertEquals('folder3 folder3-1', $bookmark->getTagsString());
292 $this->assertEquals('p8dyZg', $bookmark->getShortUrl());
294 $bookmark = $this->bookmarkService
->findByUrl('http://nest.ed/2');
295 $this->assertEquals(7, $bookmark->getId());
297 DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, '20160229_111541'),
298 $bookmark->getCreated()
300 $this->assertEquals('Nested 2', $bookmark->getTitle());
301 $this->assertEquals('http://nest.ed/2', $bookmark->getUrl());
302 $this->assertEquals('', $bookmark->getDescription());
303 $this->assertFalse($bookmark->isPrivate());
304 $this->assertEquals('tag4', $bookmark->getTagsString());
305 $this->assertEquals('Gt3Uug', $bookmark->getShortUrl());
309 * Import bookmarks with the default privacy setting (reuse from file)
311 * The $_POST array is not set.
313 public function testImportDefaultPrivacyNoPost()
315 $files = file2array('netscape_basic.htm');
316 $this->assertStringMatchesFormat(
317 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
318 .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
319 $this->netscapeBookmarkUtils
->import([], $files)
322 $this->assertEquals(2, $this->bookmarkService
->count());
323 $this->assertEquals(1, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
325 $bookmark = $this->bookmarkService
->findByUrl('https://private.tld');
326 $this->assertEquals(0, $bookmark->getId());
328 DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, '20001010_135536'),
329 $bookmark->getCreated()
331 $this->assertEquals('Secret stuff', $bookmark->getTitle());
332 $this->assertEquals('https://private.tld', $bookmark->getUrl());
333 $this->assertEquals('Super-secret stuff you\'re not supposed to know about', $bookmark->getDescription());
334 $this->assertTrue($bookmark->isPrivate());
335 $this->assertEquals('private secret', $bookmark->getTagsString());
336 $this->assertEquals('EokDtA', $bookmark->getShortUrl());
338 $bookmark = $this->bookmarkService
->findByUrl('http://public.tld');
339 $this->assertEquals(1, $bookmark->getId());
341 DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, '20160225_235548'),
342 $bookmark->getCreated()
344 $this->assertEquals('Public stuff', $bookmark->getTitle());
345 $this->assertEquals('http://public.tld', $bookmark->getUrl());
346 $this->assertEquals('', $bookmark->getDescription());
347 $this->assertFalse($bookmark->isPrivate());
348 $this->assertEquals('public hello world', $bookmark->getTagsString());
349 $this->assertEquals('Er9ddA', $bookmark->getShortUrl());
353 * Import bookmarks with the default privacy setting (reuse from file)
355 public function testImportKeepPrivacy()
357 $post = array('privacy' => 'default');
358 $files = file2array('netscape_basic.htm');
359 $this->assertStringMatchesFormat(
360 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
361 .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
362 $this->netscapeBookmarkUtils
->import($post, $files)
365 $this->assertEquals(2, $this->bookmarkService
->count());
366 $this->assertEquals(1, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
368 $bookmark = $this->bookmarkService
->findByUrl('https://private.tld');
369 $this->assertEquals(0, $bookmark->getId());
371 DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, '20001010_135536'),
372 $bookmark->getCreated()
374 $this->assertEquals('Secret stuff', $bookmark->getTitle());
375 $this->assertEquals('https://private.tld', $bookmark->getUrl());
376 $this->assertEquals('Super-secret stuff you\'re not supposed to know about', $bookmark->getDescription());
377 $this->assertTrue($bookmark->isPrivate());
378 $this->assertEquals('private secret', $bookmark->getTagsString());
379 $this->assertEquals('EokDtA', $bookmark->getShortUrl());
381 $bookmark = $this->bookmarkService
->findByUrl('http://public.tld');
382 $this->assertEquals(1, $bookmark->getId());
384 DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, '20160225_235548'),
385 $bookmark->getCreated()
387 $this->assertEquals('Public stuff', $bookmark->getTitle());
388 $this->assertEquals('http://public.tld', $bookmark->getUrl());
389 $this->assertEquals('', $bookmark->getDescription());
390 $this->assertFalse($bookmark->isPrivate());
391 $this->assertEquals('public hello world', $bookmark->getTagsString());
392 $this->assertEquals('Er9ddA', $bookmark->getShortUrl());
396 * Import bookmarks as public
398 public function testImportAsPublic()
400 $post = array('privacy' => 'public');
401 $files = file2array('netscape_basic.htm');
402 $this->assertStringMatchesFormat(
403 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
404 .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
405 $this->netscapeBookmarkUtils
->import($post, $files)
407 $this->assertEquals(2, $this->bookmarkService
->count());
408 $this->assertEquals(0, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
409 $this->assertFalse($this->bookmarkService
->get(0)->isPrivate());
410 $this->assertFalse($this->bookmarkService
->get(1)->isPrivate());
414 * Import bookmarks as private
416 public function testImportAsPrivate()
418 $post = array('privacy' => 'private');
419 $files = file2array('netscape_basic.htm');
420 $this->assertStringMatchesFormat(
421 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
422 .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
423 $this->netscapeBookmarkUtils
->import($post, $files)
425 $this->assertEquals(2, $this->bookmarkService
->count());
426 $this->assertEquals(2, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
427 $this->assertTrue($this->bookmarkService
->get(0)->isPrivate());
428 $this->assertTrue($this->bookmarkService
->get(1)->isPrivate());
432 * Overwrite private bookmarks so they become public
434 public function testOverwriteAsPublic()
436 $files = file2array('netscape_basic.htm');
438 // import bookmarks as private
439 $post = array('privacy' => 'private');
440 $this->assertStringMatchesFormat(
441 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
442 .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
443 $this->netscapeBookmarkUtils
->import($post, $files)
445 $this->assertEquals(2, $this->bookmarkService
->count());
446 $this->assertEquals(2, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
447 $this->assertTrue($this->bookmarkService
->get(0)->isPrivate());
448 $this->assertTrue($this->bookmarkService
->get(1)->isPrivate());
450 // re-import as public, enable overwriting
452 'privacy' => 'public',
453 'overwrite' => 'true'
455 $this->assertStringMatchesFormat(
456 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
457 .' 2 bookmarks imported, 2 bookmarks overwritten, 0 bookmarks skipped.',
458 $this->netscapeBookmarkUtils
->import($post, $files)
460 $this->assertEquals(2, $this->bookmarkService
->count());
461 $this->assertEquals(0, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
462 $this->assertFalse($this->bookmarkService
->get(0)->isPrivate());
463 $this->assertFalse($this->bookmarkService
->get(1)->isPrivate());
467 * Overwrite public bookmarks so they become private
469 public function testOverwriteAsPrivate()
471 $files = file2array('netscape_basic.htm');
473 // import bookmarks as public
474 $post = array('privacy' => 'public');
475 $this->assertStringMatchesFormat(
476 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
477 .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
478 $this->netscapeBookmarkUtils
->import($post, $files)
480 $this->assertEquals(2, $this->bookmarkService
->count());
481 $this->assertEquals(0, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
482 $this->assertFalse($this->bookmarkService
->get(0)->isPrivate());
483 $this->assertFalse($this->bookmarkService
->get(1)->isPrivate());
485 // re-import as private, enable overwriting
487 'privacy' => 'private',
488 'overwrite' => 'true'
490 $this->assertStringMatchesFormat(
491 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
492 .' 2 bookmarks imported, 2 bookmarks overwritten, 0 bookmarks skipped.',
493 $this->netscapeBookmarkUtils
->import($post, $files)
495 $this->assertEquals(2, $this->bookmarkService
->count());
496 $this->assertEquals(2, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
497 $this->assertTrue($this->bookmarkService
->get(0)->isPrivate());
498 $this->assertTrue($this->bookmarkService
->get(1)->isPrivate());
502 * Attept to import the same bookmarks twice without enabling overwriting
504 public function testSkipOverwrite()
506 $post = array('privacy' => 'public');
507 $files = file2array('netscape_basic.htm');
508 $this->assertStringMatchesFormat(
509 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
510 .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
511 $this->netscapeBookmarkUtils
->import($post, $files)
513 $this->assertEquals(2, $this->bookmarkService
->count());
514 $this->assertEquals(0, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
516 // re-import as private, DO NOT enable overwriting
517 $post = array('privacy' => 'private');
518 $this->assertStringMatchesFormat(
519 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
520 .' 0 bookmarks imported, 0 bookmarks overwritten, 2 bookmarks skipped.',
521 $this->netscapeBookmarkUtils
->import($post, $files)
523 $this->assertEquals(2, $this->bookmarkService
->count());
524 $this->assertEquals(0, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
528 * Add user-specified tags to all imported bookmarks
530 public function testSetDefaultTags()
533 'privacy' => 'public',
534 'default_tags' => 'tag1 tag2 tag3'
536 $files = file2array('netscape_basic.htm');
537 $this->assertStringMatchesFormat(
538 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
539 .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
540 $this->netscapeBookmarkUtils
->import($post, $files)
542 $this->assertEquals(2, $this->bookmarkService
->count());
543 $this->assertEquals(0, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
544 $this->assertEquals('tag1 tag2 tag3 private secret', $this->bookmarkService
->get(0)->getTagsString());
545 $this->assertEquals('tag1 tag2 tag3 public hello world', $this->bookmarkService
->get(1)->getTagsString());
549 * The user-specified tags contain characters to be escaped
551 public function testSanitizeDefaultTags()
554 'privacy' => 'public',
555 'default_tags' => 'tag1& tag2 "tag3"'
557 $files = file2array('netscape_basic.htm');
558 $this->assertStringMatchesFormat(
559 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
560 .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
561 $this->netscapeBookmarkUtils
->import($post, $files)
563 $this->assertEquals(2, $this->bookmarkService
->count());
564 $this->assertEquals(0, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
566 'tag1& tag2 "tag3" private secret',
567 $this->bookmarkService
->get(0)->getTagsString()
570 'tag1& tag2 "tag3" public hello world',
571 $this->bookmarkService
->get(1)->getTagsString()
576 * Add user-specified tags to all imported bookmarks
578 public function testSetDefaultTagsWithCustomSeparator()
581 $this->conf
->set('general.tags_separator', $separator);
583 'privacy' => 'public',
584 'default_tags' => 'tag1@tag2@tag3@multiple words tag'
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)
592 $this->assertEquals(2, $this->bookmarkService
->count());
593 $this->assertEquals(0, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
595 'tag1@tag2@tag3@multiple words tag@private@secret',
596 $this->bookmarkService
->get(0)->getTagsString($separator)
599 ['tag1', 'tag2', 'tag3', 'multiple words tag', 'private', 'secret'],
600 $this->bookmarkService
->get(0)->getTags()
603 'tag1@tag2@tag3@multiple words tag@public@hello@world',
604 $this->bookmarkService
->get(1)->getTagsString($separator)
607 ['tag1', 'tag2', 'tag3', 'multiple words tag', 'public', 'hello', 'world'],
608 $this->bookmarkService
->get(1)->getTags()
613 * Ensure each imported bookmark has a unique id
615 * See https://github.com/shaarli/Shaarli/issues/351
617 public function testImportSameDate()
619 $files = file2array('same_date.htm');
620 $this->assertStringMatchesFormat(
621 'File same_date.htm (453 bytes) was successfully processed in %d seconds:'
622 .' 3 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
623 $this->netscapeBookmarkUtils
->import(array(), $files)
625 $this->assertEquals(3, $this->bookmarkService
->count());
626 $this->assertEquals(0, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
627 $this->assertEquals(0, $this->bookmarkService
->get(0)->getId());
628 $this->assertEquals(1, $this->bookmarkService
->get(1)->getId());
629 $this->assertEquals(2, $this->bookmarkService
->get(2)->getId());
632 public function testImportCreateUpdateHistory()
635 'privacy' => 'public',
636 'overwrite' => 'true',
638 $files = file2array('netscape_basic.htm');
639 $this->netscapeBookmarkUtils
->import($post, $files);
640 $history = $this->history
->getHistory();
641 $this->assertEquals(1, count($history));
642 $this->assertEquals(History
::IMPORT
, $history[0]['event']);
643 $this->assertTrue(new DateTime('-5 seconds') < $history[0]['datetime']);
645 // re-import as private, enable overwriting
646 $this->netscapeBookmarkUtils
->import($post, $files);
647 $history = $this->history
->getHistory();
648 $this->assertEquals(2, count($history));
649 $this->assertEquals(History
::IMPORT
, $history[0]['event']);
650 $this->assertTrue(new DateTime('-5 seconds') < $history[0]['datetime']);
651 $this->assertEquals(History
::IMPORT
, $history[1]['event']);
652 $this->assertTrue(new DateTime('-5 seconds') < $history[1]['datetime']);