2 namespace Shaarli\Netscape
;
5 use Shaarli\Bookmark\Bookmark
;
6 use Shaarli\Bookmark\BookmarkFilter
;
7 use Shaarli\Bookmark\BookmarkFileService
;
8 use Shaarli\Bookmark\LinkDB
;
9 use Shaarli\Config\ConfigManager
;
13 * Utility function to load a file's metadata in a $_FILES-like array
15 * @param string $filename Basename of the file
17 * @return array A $_FILES-like array
19 function file2array($filename)
22 'filetoupload' => array(
24 'tmp_name' => __DIR__
. '/input/' . $filename,
25 'size' => filesize(__DIR__
. '/input/' . $filename)
32 * Netscape bookmark import
34 class BookmarkImportTest
extends \PHPUnit\Framework\TestCase
37 * @var string datastore to test write operations
39 protected static $testDatastore = 'sandbox/datastore.php';
42 * @var string History file path
44 protected static $historyFilePath = 'sandbox/history.php';
47 * @var BookmarkFileService private LinkDB instance
49 protected $bookmarkService = null;
52 * @var string Dummy page cache
54 protected $pagecache = 'tests';
57 * @var ConfigManager instance.
62 * @var History instance.
67 * @var string Save the current timezone.
69 protected static $defaultTimeZone;
71 public static function setUpBeforeClass()
73 self
::$defaultTimeZone = date_default_timezone_get();
74 // Timezone without DST for test consistency
75 date_default_timezone_set('Africa/Nairobi');
79 * Resets test data before each test
81 protected function setUp()
83 if (file_exists(self
::$testDatastore)) {
84 unlink(self
::$testDatastore);
86 // start with an empty datastore
87 file_put_contents(self
::$testDatastore, '<?php /* S7QysKquBQA= */ ?>');
89 $this->conf
= new ConfigManager('tests/utils/config/configJson');
90 $this->conf
->set('resource.page_cache', $this->pagecache
);
91 $this->conf
->set('resource.datastore', self
::$testDatastore);
92 $this->history
= new History(self
::$historyFilePath);
93 $this->bookmarkService
= new BookmarkFileService($this->conf
, $this->history
, true);
97 * Delete history file.
99 public function tearDown()
101 @unlink(self
::$historyFilePath);
104 public static function tearDownAfterClass()
106 date_default_timezone_set(self
::$defaultTimeZone);
110 * Attempt to import bookmarks from an empty file
112 public function testImportEmptyData()
114 $files = file2array('empty.htm');
116 'File empty.htm (0 bytes) has an unknown file format.'
117 .' Nothing was imported.',
118 NetscapeBookmarkUtils
::import(null, $files, null, $this->conf
, $this->history
)
120 $this->assertEquals(0, $this->bookmarkService
->count());
124 * Attempt to import bookmarks from a file with no Doctype
126 public function testImportNoDoctype()
128 $files = file2array('no_doctype.htm');
130 'File no_doctype.htm (350 bytes) has an unknown file format. Nothing was imported.',
131 NetscapeBookmarkUtils
::import(null, $files, null, $this->conf
, $this->history
)
133 $this->assertEquals(0, $this->bookmarkService
->count());
137 * Attempt to import bookmarks from a file with a lowercase Doctype
139 public function testImportLowecaseDoctype()
141 $files = file2array('lowercase_doctype.htm');
142 $this->assertStringMatchesFormat(
143 'File lowercase_doctype.htm (386 bytes) was successfully processed in %d seconds:'
144 .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
145 NetscapeBookmarkUtils
::import(null, $files, $this->bookmarkService
, $this->conf
, $this->history
)
147 $this->assertEquals(2, $this->bookmarkService
->count());
152 * Ensure IE dumps are supported
154 public function testImportInternetExplorerEncoding()
156 $files = file2array('internet_explorer_encoding.htm');
157 $this->assertStringMatchesFormat(
158 'File internet_explorer_encoding.htm (356 bytes) was successfully processed in %d seconds:'
159 .' 1 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
160 NetscapeBookmarkUtils
::import([], $files, $this->bookmarkService
, $this->conf
, $this->history
)
162 $this->assertEquals(1, $this->bookmarkService
->count());
163 $this->assertEquals(0, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
165 $bookmark = $this->bookmarkService
->findByUrl('http://hginit.com/');
166 $this->assertEquals(0, $bookmark->getId());
168 DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, '20160618_203944'),
169 $bookmark->getCreated()
171 $this->assertEquals('Hg Init a Mercurial tutorial by Joel Spolsky', $bookmark->getTitle());
172 $this->assertEquals('http://hginit.com/', $bookmark->getUrl());
173 $this->assertEquals('', $bookmark->getDescription());
174 $this->assertFalse($bookmark->isPrivate());
175 $this->assertEquals('', $bookmark->getTagsString());
176 $this->assertEquals('La37cg', $bookmark->getShortUrl());
180 * Import bookmarks nested in a folder hierarchy
182 public function testImportNested()
184 $files = file2array('netscape_nested.htm');
185 $this->assertStringMatchesFormat(
186 'File netscape_nested.htm (1337 bytes) was successfully processed in %d seconds:'
187 .' 8 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
188 NetscapeBookmarkUtils
::import([], $files, $this->bookmarkService
, $this->conf
, $this->history
)
190 $this->assertEquals(8, $this->bookmarkService
->count());
191 $this->assertEquals(2, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
193 $bookmark = $this->bookmarkService
->findByUrl('http://nest.ed/1');
194 $this->assertEquals(0, $bookmark->getId());
196 DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, '20160225_235541'),
197 $bookmark->getCreated()
199 $this->assertEquals('Nested 1', $bookmark->getTitle());
200 $this->assertEquals('http://nest.ed/1', $bookmark->getUrl());
201 $this->assertEquals('', $bookmark->getDescription());
202 $this->assertFalse($bookmark->isPrivate());
203 $this->assertEquals('tag1 tag2', $bookmark->getTagsString());
204 $this->assertEquals('KyDNKA', $bookmark->getShortUrl());
206 $bookmark = $this->bookmarkService
->findByUrl('http://nest.ed/1-1');
207 $this->assertEquals(1, $bookmark->getId());
209 DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, '20160225_235542'),
210 $bookmark->getCreated()
212 $this->assertEquals('Nested 1-1', $bookmark->getTitle());
213 $this->assertEquals('http://nest.ed/1-1', $bookmark->getUrl());
214 $this->assertEquals('', $bookmark->getDescription());
215 $this->assertFalse($bookmark->isPrivate());
216 $this->assertEquals('folder1 tag1 tag2', $bookmark->getTagsString());
217 $this->assertEquals('T2LnXg', $bookmark->getShortUrl());
219 $bookmark = $this->bookmarkService
->findByUrl('http://nest.ed/1-2');
220 $this->assertEquals(2, $bookmark->getId());
222 DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, '20160225_235547'),
223 $bookmark->getCreated()
225 $this->assertEquals('Nested 1-2', $bookmark->getTitle());
226 $this->assertEquals('http://nest.ed/1-2', $bookmark->getUrl());
227 $this->assertEquals('', $bookmark->getDescription());
228 $this->assertFalse($bookmark->isPrivate());
229 $this->assertEquals('folder1 tag3 tag4', $bookmark->getTagsString());
230 $this->assertEquals('46SZxA', $bookmark->getShortUrl());
232 $bookmark = $this->bookmarkService
->findByUrl('http://nest.ed/2-1');
233 $this->assertEquals(3, $bookmark->getId());
235 DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, '20160202_202222'),
236 $bookmark->getCreated()
238 $this->assertEquals('Nested 2-1', $bookmark->getTitle());
239 $this->assertEquals('http://nest.ed/2-1', $bookmark->getUrl());
240 $this->assertEquals('First link of the second section', $bookmark->getDescription());
241 $this->assertTrue($bookmark->isPrivate());
242 $this->assertEquals('folder2', $bookmark->getTagsString());
243 $this->assertEquals('4UHOSw', $bookmark->getShortUrl());
245 $bookmark = $this->bookmarkService
->findByUrl('http://nest.ed/2-2');
246 $this->assertEquals(4, $bookmark->getId());
248 DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, '20160119_230227'),
249 $bookmark->getCreated()
251 $this->assertEquals('Nested 2-2', $bookmark->getTitle());
252 $this->assertEquals('http://nest.ed/2-2', $bookmark->getUrl());
253 $this->assertEquals('Second link of the second section', $bookmark->getDescription());
254 $this->assertTrue($bookmark->isPrivate());
255 $this->assertEquals('folder2', $bookmark->getTagsString());
256 $this->assertEquals('yfzwbw', $bookmark->getShortUrl());
258 $bookmark = $this->bookmarkService
->findByUrl('http://nest.ed/3-1');
259 $this->assertEquals(5, $bookmark->getId());
261 DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, '20160202_202222'),
262 $bookmark->getCreated()
264 $this->assertEquals('Nested 3-1', $bookmark->getTitle());
265 $this->assertEquals('http://nest.ed/3-1', $bookmark->getUrl());
266 $this->assertEquals('', $bookmark->getDescription());
267 $this->assertFalse($bookmark->isPrivate());
268 $this->assertEquals('folder3 folder3-1 tag3', $bookmark->getTagsString());
269 $this->assertEquals('UwxIUQ', $bookmark->getShortUrl());
271 $bookmark = $this->bookmarkService
->findByUrl('http://nest.ed/3-2');
272 $this->assertEquals(6, $bookmark->getId());
274 DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, '20160119_230227'),
275 $bookmark->getCreated()
277 $this->assertEquals('Nested 3-2', $bookmark->getTitle());
278 $this->assertEquals('http://nest.ed/3-2', $bookmark->getUrl());
279 $this->assertEquals('', $bookmark->getDescription());
280 $this->assertFalse($bookmark->isPrivate());
281 $this->assertEquals('folder3 folder3-1', $bookmark->getTagsString());
282 $this->assertEquals('p8dyZg', $bookmark->getShortUrl());
284 $bookmark = $this->bookmarkService
->findByUrl('http://nest.ed/2');
285 $this->assertEquals(7, $bookmark->getId());
287 DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, '20160229_111541'),
288 $bookmark->getCreated()
290 $this->assertEquals('Nested 2', $bookmark->getTitle());
291 $this->assertEquals('http://nest.ed/2', $bookmark->getUrl());
292 $this->assertEquals('', $bookmark->getDescription());
293 $this->assertFalse($bookmark->isPrivate());
294 $this->assertEquals('tag4', $bookmark->getTagsString());
295 $this->assertEquals('Gt3Uug', $bookmark->getShortUrl());
299 * Import bookmarks with the default privacy setting (reuse from file)
301 * The $_POST array is not set.
303 public function testImportDefaultPrivacyNoPost()
305 $files = file2array('netscape_basic.htm');
306 $this->assertStringMatchesFormat(
307 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
308 .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
309 NetscapeBookmarkUtils
::import([], $files, $this->bookmarkService
, $this->conf
, $this->history
)
312 $this->assertEquals(2, $this->bookmarkService
->count());
313 $this->assertEquals(1, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
315 $bookmark = $this->bookmarkService
->findByUrl('https://private.tld');
316 $this->assertEquals(0, $bookmark->getId());
318 DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, '20001010_135536'),
319 $bookmark->getCreated()
321 $this->assertEquals('Secret stuff', $bookmark->getTitle());
322 $this->assertEquals('https://private.tld', $bookmark->getUrl());
323 $this->assertEquals('Super-secret stuff you\'re not supposed to know about', $bookmark->getDescription());
324 $this->assertTrue($bookmark->isPrivate());
325 $this->assertEquals('private secret', $bookmark->getTagsString());
326 $this->assertEquals('EokDtA', $bookmark->getShortUrl());
328 $bookmark = $this->bookmarkService
->findByUrl('http://public.tld');
329 $this->assertEquals(1, $bookmark->getId());
331 DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, '20160225_235548'),
332 $bookmark->getCreated()
334 $this->assertEquals('Public stuff', $bookmark->getTitle());
335 $this->assertEquals('http://public.tld', $bookmark->getUrl());
336 $this->assertEquals('', $bookmark->getDescription());
337 $this->assertFalse($bookmark->isPrivate());
338 $this->assertEquals('public hello world', $bookmark->getTagsString());
339 $this->assertEquals('Er9ddA', $bookmark->getShortUrl());
343 * Import bookmarks with the default privacy setting (reuse from file)
345 public function testImportKeepPrivacy()
347 $post = array('privacy' => 'default');
348 $files = file2array('netscape_basic.htm');
349 $this->assertStringMatchesFormat(
350 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
351 .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
352 NetscapeBookmarkUtils
::import($post, $files, $this->bookmarkService
, $this->conf
, $this->history
)
355 $this->assertEquals(2, $this->bookmarkService
->count());
356 $this->assertEquals(1, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
358 $bookmark = $this->bookmarkService
->findByUrl('https://private.tld');
359 $this->assertEquals(0, $bookmark->getId());
361 DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, '20001010_135536'),
362 $bookmark->getCreated()
364 $this->assertEquals('Secret stuff', $bookmark->getTitle());
365 $this->assertEquals('https://private.tld', $bookmark->getUrl());
366 $this->assertEquals('Super-secret stuff you\'re not supposed to know about', $bookmark->getDescription());
367 $this->assertTrue($bookmark->isPrivate());
368 $this->assertEquals('private secret', $bookmark->getTagsString());
369 $this->assertEquals('EokDtA', $bookmark->getShortUrl());
371 $bookmark = $this->bookmarkService
->findByUrl('http://public.tld');
372 $this->assertEquals(1, $bookmark->getId());
374 DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, '20160225_235548'),
375 $bookmark->getCreated()
377 $this->assertEquals('Public stuff', $bookmark->getTitle());
378 $this->assertEquals('http://public.tld', $bookmark->getUrl());
379 $this->assertEquals('', $bookmark->getDescription());
380 $this->assertFalse($bookmark->isPrivate());
381 $this->assertEquals('public hello world', $bookmark->getTagsString());
382 $this->assertEquals('Er9ddA', $bookmark->getShortUrl());
386 * Import bookmarks as public
388 public function testImportAsPublic()
390 $post = array('privacy' => 'public');
391 $files = file2array('netscape_basic.htm');
392 $this->assertStringMatchesFormat(
393 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
394 .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
395 NetscapeBookmarkUtils
::import($post, $files, $this->bookmarkService
, $this->conf
, $this->history
)
397 $this->assertEquals(2, $this->bookmarkService
->count());
398 $this->assertEquals(0, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
399 $this->assertFalse($this->bookmarkService
->get(0)->isPrivate());
400 $this->assertFalse($this->bookmarkService
->get(1)->isPrivate());
404 * Import bookmarks as private
406 public function testImportAsPrivate()
408 $post = array('privacy' => 'private');
409 $files = file2array('netscape_basic.htm');
410 $this->assertStringMatchesFormat(
411 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
412 .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
413 NetscapeBookmarkUtils
::import($post, $files, $this->bookmarkService
, $this->conf
, $this->history
)
415 $this->assertEquals(2, $this->bookmarkService
->count());
416 $this->assertEquals(2, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
417 $this->assertTrue($this->bookmarkService
->get(0)->isPrivate());
418 $this->assertTrue($this->bookmarkService
->get(1)->isPrivate());
422 * Overwrite private bookmarks so they become public
424 public function testOverwriteAsPublic()
426 $files = file2array('netscape_basic.htm');
428 // import bookmarks as private
429 $post = array('privacy' => 'private');
430 $this->assertStringMatchesFormat(
431 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
432 .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
433 NetscapeBookmarkUtils
::import($post, $files, $this->bookmarkService
, $this->conf
, $this->history
)
435 $this->assertEquals(2, $this->bookmarkService
->count());
436 $this->assertEquals(2, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
437 $this->assertTrue($this->bookmarkService
->get(0)->isPrivate());
438 $this->assertTrue($this->bookmarkService
->get(1)->isPrivate());
440 // re-import as public, enable overwriting
442 'privacy' => 'public',
443 'overwrite' => 'true'
445 $this->assertStringMatchesFormat(
446 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
447 .' 2 bookmarks imported, 2 bookmarks overwritten, 0 bookmarks skipped.',
448 NetscapeBookmarkUtils
::import($post, $files, $this->bookmarkService
, $this->conf
, $this->history
)
450 $this->assertEquals(2, $this->bookmarkService
->count());
451 $this->assertEquals(0, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
452 $this->assertFalse($this->bookmarkService
->get(0)->isPrivate());
453 $this->assertFalse($this->bookmarkService
->get(1)->isPrivate());
457 * Overwrite public bookmarks so they become private
459 public function testOverwriteAsPrivate()
461 $files = file2array('netscape_basic.htm');
463 // import bookmarks as public
464 $post = array('privacy' => 'public');
465 $this->assertStringMatchesFormat(
466 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
467 .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
468 NetscapeBookmarkUtils
::import($post, $files, $this->bookmarkService
, $this->conf
, $this->history
)
470 $this->assertEquals(2, $this->bookmarkService
->count());
471 $this->assertEquals(0, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
472 $this->assertFalse($this->bookmarkService
->get(0)->isPrivate());
473 $this->assertFalse($this->bookmarkService
->get(1)->isPrivate());
475 // re-import as private, enable overwriting
477 'privacy' => 'private',
478 'overwrite' => 'true'
480 $this->assertStringMatchesFormat(
481 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
482 .' 2 bookmarks imported, 2 bookmarks overwritten, 0 bookmarks skipped.',
483 NetscapeBookmarkUtils
::import($post, $files, $this->bookmarkService
, $this->conf
, $this->history
)
485 $this->assertEquals(2, $this->bookmarkService
->count());
486 $this->assertEquals(2, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
487 $this->assertTrue($this->bookmarkService
->get(0)->isPrivate());
488 $this->assertTrue($this->bookmarkService
->get(1)->isPrivate());
492 * Attept to import the same bookmarks twice without enabling overwriting
494 public function testSkipOverwrite()
496 $post = array('privacy' => 'public');
497 $files = file2array('netscape_basic.htm');
498 $this->assertStringMatchesFormat(
499 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
500 .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
501 NetscapeBookmarkUtils
::import($post, $files, $this->bookmarkService
, $this->conf
, $this->history
)
503 $this->assertEquals(2, $this->bookmarkService
->count());
504 $this->assertEquals(0, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
506 // re-import as private, DO NOT enable overwriting
507 $post = array('privacy' => 'private');
508 $this->assertStringMatchesFormat(
509 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
510 .' 0 bookmarks imported, 0 bookmarks overwritten, 2 bookmarks skipped.',
511 NetscapeBookmarkUtils
::import($post, $files, $this->bookmarkService
, $this->conf
, $this->history
)
513 $this->assertEquals(2, $this->bookmarkService
->count());
514 $this->assertEquals(0, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
518 * Add user-specified tags to all imported bookmarks
520 public function testSetDefaultTags()
523 'privacy' => 'public',
524 'default_tags' => 'tag1,tag2 tag3'
526 $files = file2array('netscape_basic.htm');
527 $this->assertStringMatchesFormat(
528 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
529 .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
530 NetscapeBookmarkUtils
::import($post, $files, $this->bookmarkService
, $this->conf
, $this->history
)
532 $this->assertEquals(2, $this->bookmarkService
->count());
533 $this->assertEquals(0, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
534 $this->assertEquals('tag1 tag2 tag3 private secret', $this->bookmarkService
->get(0)->getTagsString());
535 $this->assertEquals('tag1 tag2 tag3 public hello world', $this->bookmarkService
->get(1)->getTagsString());
539 * The user-specified tags contain characters to be escaped
541 public function testSanitizeDefaultTags()
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 NetscapeBookmarkUtils
::import($post, $files, $this->bookmarkService
, $this->conf
, $this->history
)
553 $this->assertEquals(2, $this->bookmarkService
->count());
554 $this->assertEquals(0, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
556 'tag1& tag2 "tag3" private secret',
557 $this->bookmarkService
->get(0)->getTagsString()
560 'tag1& tag2 "tag3" public hello world',
561 $this->bookmarkService
->get(1)->getTagsString()
566 * Ensure each imported bookmark has a unique id
568 * See https://github.com/shaarli/Shaarli/issues/351
570 public function testImportSameDate()
572 $files = file2array('same_date.htm');
573 $this->assertStringMatchesFormat(
574 'File same_date.htm (453 bytes) was successfully processed in %d seconds:'
575 .' 3 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
576 NetscapeBookmarkUtils
::import(array(), $files, $this->bookmarkService
, $this->conf
, $this->history
)
578 $this->assertEquals(3, $this->bookmarkService
->count());
579 $this->assertEquals(0, $this->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
580 $this->assertEquals(0, $this->bookmarkService
->get(0)->getId());
581 $this->assertEquals(1, $this->bookmarkService
->get(1)->getId());
582 $this->assertEquals(2, $this->bookmarkService
->get(2)->getId());
585 public function testImportCreateUpdateHistory()
588 'privacy' => 'public',
589 'overwrite' => 'true',
591 $files = file2array('netscape_basic.htm');
592 NetscapeBookmarkUtils
::import($post, $files, $this->bookmarkService
, $this->conf
, $this->history
);
593 $history = $this->history
->getHistory();
594 $this->assertEquals(1, count($history));
595 $this->assertEquals(History
::IMPORT
, $history[0]['event']);
596 $this->assertTrue(new DateTime('-5 seconds') < $history[0]['datetime']);
598 // re-import as private, enable overwriting
599 NetscapeBookmarkUtils
::import($post, $files, $this->bookmarkService
, $this->conf
, $this->history
);
600 $history = $this->history
->getHistory();
601 $this->assertEquals(2, count($history));
602 $this->assertEquals(History
::IMPORT
, $history[0]['event']);
603 $this->assertTrue(new DateTime('-5 seconds') < $history[0]['datetime']);
604 $this->assertEquals(History
::IMPORT
, $history[1]['event']);
605 $this->assertTrue(new DateTime('-5 seconds') < $history[1]['datetime']);