BookmarkImportTest.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. <?php
  2. require_once 'application/NetscapeBookmarkUtils.php';
  3. use Shaarli\Config\ConfigManager;
  4. /**
  5. * Utility function to load a file's metadata in a $_FILES-like array
  6. *
  7. * @param string $filename Basename of the file
  8. *
  9. * @return array A $_FILES-like array
  10. */
  11. function file2array($filename)
  12. {
  13. return array(
  14. 'filetoupload' => array(
  15. 'name' => $filename,
  16. 'tmp_name' => __DIR__ . '/input/' . $filename,
  17. 'size' => filesize(__DIR__ . '/input/' . $filename)
  18. )
  19. );
  20. }
  21. /**
  22. * Netscape bookmark import
  23. */
  24. class BookmarkImportTest extends PHPUnit_Framework_TestCase
  25. {
  26. /**
  27. * @var string datastore to test write operations
  28. */
  29. protected static $testDatastore = 'sandbox/datastore.php';
  30. /**
  31. * @var string History file path
  32. */
  33. protected static $historyFilePath = 'sandbox/history.php';
  34. /**
  35. * @var LinkDB private LinkDB instance
  36. */
  37. protected $linkDb = null;
  38. /**
  39. * @var string Dummy page cache
  40. */
  41. protected $pagecache = 'tests';
  42. /**
  43. * @var ConfigManager instance.
  44. */
  45. protected $conf;
  46. /**
  47. * @var History instance.
  48. */
  49. protected $history;
  50. /**
  51. * @var string Save the current timezone.
  52. */
  53. protected static $defaultTimeZone;
  54. public static function setUpBeforeClass()
  55. {
  56. self::$defaultTimeZone = date_default_timezone_get();
  57. // Timezone without DST for test consistency
  58. date_default_timezone_set('Africa/Nairobi');
  59. }
  60. /**
  61. * Resets test data before each test
  62. */
  63. protected function setUp()
  64. {
  65. if (file_exists(self::$testDatastore)) {
  66. unlink(self::$testDatastore);
  67. }
  68. // start with an empty datastore
  69. file_put_contents(self::$testDatastore, '<?php /* S7QysKquBQA= */ ?>');
  70. $this->linkDb = new LinkDB(self::$testDatastore, true, false);
  71. $this->conf = new ConfigManager('tests/utils/config/configJson');
  72. $this->conf->set('resource.page_cache', $this->pagecache);
  73. $this->history = new History(self::$historyFilePath);
  74. }
  75. /**
  76. * Delete history file.
  77. */
  78. public function tearDown()
  79. {
  80. @unlink(self::$historyFilePath);
  81. }
  82. public static function tearDownAfterClass()
  83. {
  84. date_default_timezone_set(self::$defaultTimeZone);
  85. }
  86. /**
  87. * Attempt to import bookmarks from an empty file
  88. */
  89. public function testImportEmptyData()
  90. {
  91. $files = file2array('empty.htm');
  92. $this->assertEquals(
  93. 'File empty.htm (0 bytes) has an unknown file format.'
  94. .' Nothing was imported.',
  95. NetscapeBookmarkUtils::import(null, $files, null, $this->conf, $this->history)
  96. );
  97. $this->assertEquals(0, count($this->linkDb));
  98. }
  99. /**
  100. * Attempt to import bookmarks from a file with no Doctype
  101. */
  102. public function testImportNoDoctype()
  103. {
  104. $files = file2array('no_doctype.htm');
  105. $this->assertEquals(
  106. 'File no_doctype.htm (350 bytes) has an unknown file format. Nothing was imported.',
  107. NetscapeBookmarkUtils::import(null, $files, null, $this->conf, $this->history)
  108. );
  109. $this->assertEquals(0, count($this->linkDb));
  110. }
  111. /**
  112. * Ensure IE dumps are supported
  113. */
  114. public function testImportInternetExplorerEncoding()
  115. {
  116. $files = file2array('internet_explorer_encoding.htm');
  117. $this->assertStringMatchesFormat(
  118. 'File internet_explorer_encoding.htm (356 bytes) was successfully processed in %d seconds:'
  119. .' 1 links imported, 0 links overwritten, 0 links skipped.',
  120. NetscapeBookmarkUtils::import([], $files, $this->linkDb, $this->conf, $this->history)
  121. );
  122. $this->assertEquals(1, count($this->linkDb));
  123. $this->assertEquals(0, count_private($this->linkDb));
  124. $this->assertEquals(
  125. array(
  126. 'id' => 0,
  127. 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160618_203944'),
  128. 'title' => 'Hg Init a Mercurial tutorial by Joel Spolsky',
  129. 'url' => 'http://hginit.com/',
  130. 'description' => '',
  131. 'private' => 0,
  132. 'tags' => '',
  133. 'shorturl' => 'La37cg',
  134. ),
  135. $this->linkDb->getLinkFromUrl('http://hginit.com/')
  136. );
  137. }
  138. /**
  139. * Import bookmarks nested in a folder hierarchy
  140. */
  141. public function testImportNested()
  142. {
  143. $files = file2array('netscape_nested.htm');
  144. $this->assertStringMatchesFormat(
  145. 'File netscape_nested.htm (1337 bytes) was successfully processed in %d seconds:'
  146. .' 8 links imported, 0 links overwritten, 0 links skipped.',
  147. NetscapeBookmarkUtils::import([], $files, $this->linkDb, $this->conf, $this->history)
  148. );
  149. $this->assertEquals(8, count($this->linkDb));
  150. $this->assertEquals(2, count_private($this->linkDb));
  151. $this->assertEquals(
  152. array(
  153. 'id' => 0,
  154. 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160225_235541'),
  155. 'title' => 'Nested 1',
  156. 'url' => 'http://nest.ed/1',
  157. 'description' => '',
  158. 'private' => 0,
  159. 'tags' => 'tag1 tag2',
  160. 'shorturl' => 'KyDNKA',
  161. ),
  162. $this->linkDb->getLinkFromUrl('http://nest.ed/1')
  163. );
  164. $this->assertEquals(
  165. array(
  166. 'id' => 1,
  167. 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160225_235542'),
  168. 'title' => 'Nested 1-1',
  169. 'url' => 'http://nest.ed/1-1',
  170. 'description' => '',
  171. 'private' => 0,
  172. 'tags' => 'folder1 tag1 tag2',
  173. 'shorturl' => 'T2LnXg',
  174. ),
  175. $this->linkDb->getLinkFromUrl('http://nest.ed/1-1')
  176. );
  177. $this->assertEquals(
  178. array(
  179. 'id' => 2,
  180. 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160225_235547'),
  181. 'title' => 'Nested 1-2',
  182. 'url' => 'http://nest.ed/1-2',
  183. 'description' => '',
  184. 'private' => 0,
  185. 'tags' => 'folder1 tag3 tag4',
  186. 'shorturl' => '46SZxA',
  187. ),
  188. $this->linkDb->getLinkFromUrl('http://nest.ed/1-2')
  189. );
  190. $this->assertEquals(
  191. array(
  192. 'id' => 3,
  193. 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160202_202222'),
  194. 'title' => 'Nested 2-1',
  195. 'url' => 'http://nest.ed/2-1',
  196. 'description' => 'First link of the second section',
  197. 'private' => 1,
  198. 'tags' => 'folder2',
  199. 'shorturl' => '4UHOSw',
  200. ),
  201. $this->linkDb->getLinkFromUrl('http://nest.ed/2-1')
  202. );
  203. $this->assertEquals(
  204. array(
  205. 'id' => 4,
  206. 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160119_230227'),
  207. 'title' => 'Nested 2-2',
  208. 'url' => 'http://nest.ed/2-2',
  209. 'description' => 'Second link of the second section',
  210. 'private' => 1,
  211. 'tags' => 'folder2',
  212. 'shorturl' => 'yfzwbw',
  213. ),
  214. $this->linkDb->getLinkFromUrl('http://nest.ed/2-2')
  215. );
  216. $this->assertEquals(
  217. array(
  218. 'id' => 5,
  219. 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160202_202222'),
  220. 'title' => 'Nested 3-1',
  221. 'url' => 'http://nest.ed/3-1',
  222. 'description' => '',
  223. 'private' => 0,
  224. 'tags' => 'folder3 folder3-1 tag3',
  225. 'shorturl' => 'UwxIUQ',
  226. ),
  227. $this->linkDb->getLinkFromUrl('http://nest.ed/3-1')
  228. );
  229. $this->assertEquals(
  230. array(
  231. 'id' => 6,
  232. 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160119_230227'),
  233. 'title' => 'Nested 3-2',
  234. 'url' => 'http://nest.ed/3-2',
  235. 'description' => '',
  236. 'private' => 0,
  237. 'tags' => 'folder3 folder3-1',
  238. 'shorturl' => 'p8dyZg',
  239. ),
  240. $this->linkDb->getLinkFromUrl('http://nest.ed/3-2')
  241. );
  242. $this->assertEquals(
  243. array(
  244. 'id' => 7,
  245. 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160229_111541'),
  246. 'title' => 'Nested 2',
  247. 'url' => 'http://nest.ed/2',
  248. 'description' => '',
  249. 'private' => 0,
  250. 'tags' => 'tag4',
  251. 'shorturl' => 'Gt3Uug',
  252. ),
  253. $this->linkDb->getLinkFromUrl('http://nest.ed/2')
  254. );
  255. }
  256. /**
  257. * Import bookmarks with the default privacy setting (reuse from file)
  258. *
  259. * The $_POST array is not set.
  260. */
  261. public function testImportDefaultPrivacyNoPost()
  262. {
  263. $files = file2array('netscape_basic.htm');
  264. $this->assertStringMatchesFormat(
  265. 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
  266. .' 2 links imported, 0 links overwritten, 0 links skipped.',
  267. NetscapeBookmarkUtils::import([], $files, $this->linkDb, $this->conf, $this->history)
  268. );
  269. $this->assertEquals(2, count($this->linkDb));
  270. $this->assertEquals(1, count_private($this->linkDb));
  271. $this->assertEquals(
  272. array(
  273. 'id' => 0,
  274. // Old link - UTC+4 (note that TZ in the import file is ignored).
  275. 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20001010_135536'),
  276. 'title' => 'Secret stuff',
  277. 'url' => 'https://private.tld',
  278. 'description' => "Super-secret stuff you're not supposed to know about",
  279. 'private' => 1,
  280. 'tags' => 'private secret',
  281. 'shorturl' => 'EokDtA',
  282. ),
  283. $this->linkDb->getLinkFromUrl('https://private.tld')
  284. );
  285. $this->assertEquals(
  286. array(
  287. 'id' => 1,
  288. 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160225_235548'),
  289. 'title' => 'Public stuff',
  290. 'url' => 'http://public.tld',
  291. 'description' => '',
  292. 'private' => 0,
  293. 'tags' => 'public hello world',
  294. 'shorturl' => 'Er9ddA',
  295. ),
  296. $this->linkDb->getLinkFromUrl('http://public.tld')
  297. );
  298. }
  299. /**
  300. * Import bookmarks with the default privacy setting (reuse from file)
  301. */
  302. public function testImportKeepPrivacy()
  303. {
  304. $post = array('privacy' => 'default');
  305. $files = file2array('netscape_basic.htm');
  306. $this->assertStringMatchesFormat(
  307. 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
  308. .' 2 links imported, 0 links overwritten, 0 links skipped.',
  309. NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf, $this->history)
  310. );
  311. $this->assertEquals(2, count($this->linkDb));
  312. $this->assertEquals(1, count_private($this->linkDb));
  313. $this->assertEquals(
  314. array(
  315. 'id' => 0,
  316. // Note that TZ in the import file is ignored.
  317. 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20001010_135536'),
  318. 'title' => 'Secret stuff',
  319. 'url' => 'https://private.tld',
  320. 'description' => "Super-secret stuff you're not supposed to know about",
  321. 'private' => 1,
  322. 'tags' => 'private secret',
  323. 'shorturl' => 'EokDtA',
  324. ),
  325. $this->linkDb->getLinkFromUrl('https://private.tld')
  326. );
  327. $this->assertEquals(
  328. array(
  329. 'id' => 1,
  330. 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160225_235548'),
  331. 'title' => 'Public stuff',
  332. 'url' => 'http://public.tld',
  333. 'description' => '',
  334. 'private' => 0,
  335. 'tags' => 'public hello world',
  336. 'shorturl' => 'Er9ddA',
  337. ),
  338. $this->linkDb->getLinkFromUrl('http://public.tld')
  339. );
  340. }
  341. /**
  342. * Import links as public
  343. */
  344. public function testImportAsPublic()
  345. {
  346. $post = array('privacy' => 'public');
  347. $files = file2array('netscape_basic.htm');
  348. $this->assertStringMatchesFormat(
  349. 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
  350. .' 2 links imported, 0 links overwritten, 0 links skipped.',
  351. NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf, $this->history)
  352. );
  353. $this->assertEquals(2, count($this->linkDb));
  354. $this->assertEquals(0, count_private($this->linkDb));
  355. $this->assertEquals(
  356. 0,
  357. $this->linkDb[0]['private']
  358. );
  359. $this->assertEquals(
  360. 0,
  361. $this->linkDb[1]['private']
  362. );
  363. }
  364. /**
  365. * Import links as private
  366. */
  367. public function testImportAsPrivate()
  368. {
  369. $post = array('privacy' => 'private');
  370. $files = file2array('netscape_basic.htm');
  371. $this->assertStringMatchesFormat(
  372. 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
  373. .' 2 links imported, 0 links overwritten, 0 links skipped.',
  374. NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf, $this->history)
  375. );
  376. $this->assertEquals(2, count($this->linkDb));
  377. $this->assertEquals(2, count_private($this->linkDb));
  378. $this->assertEquals(
  379. 1,
  380. $this->linkDb['0']['private']
  381. );
  382. $this->assertEquals(
  383. 1,
  384. $this->linkDb['1']['private']
  385. );
  386. }
  387. /**
  388. * Overwrite private links so they become public
  389. */
  390. public function testOverwriteAsPublic()
  391. {
  392. $files = file2array('netscape_basic.htm');
  393. // import links as private
  394. $post = array('privacy' => 'private');
  395. $this->assertStringMatchesFormat(
  396. 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
  397. .' 2 links imported, 0 links overwritten, 0 links skipped.',
  398. NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf, $this->history)
  399. );
  400. $this->assertEquals(2, count($this->linkDb));
  401. $this->assertEquals(2, count_private($this->linkDb));
  402. $this->assertEquals(
  403. 1,
  404. $this->linkDb[0]['private']
  405. );
  406. $this->assertEquals(
  407. 1,
  408. $this->linkDb[1]['private']
  409. );
  410. // re-import as public, enable overwriting
  411. $post = array(
  412. 'privacy' => 'public',
  413. 'overwrite' => 'true'
  414. );
  415. $this->assertStringMatchesFormat(
  416. 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
  417. .' 2 links imported, 2 links overwritten, 0 links skipped.',
  418. NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf, $this->history)
  419. );
  420. $this->assertEquals(2, count($this->linkDb));
  421. $this->assertEquals(0, count_private($this->linkDb));
  422. $this->assertEquals(
  423. 0,
  424. $this->linkDb[0]['private']
  425. );
  426. $this->assertEquals(
  427. 0,
  428. $this->linkDb[1]['private']
  429. );
  430. }
  431. /**
  432. * Overwrite public links so they become private
  433. */
  434. public function testOverwriteAsPrivate()
  435. {
  436. $files = file2array('netscape_basic.htm');
  437. // import links as public
  438. $post = array('privacy' => 'public');
  439. $this->assertStringMatchesFormat(
  440. 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
  441. .' 2 links imported, 0 links overwritten, 0 links skipped.',
  442. NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf, $this->history)
  443. );
  444. $this->assertEquals(2, count($this->linkDb));
  445. $this->assertEquals(0, count_private($this->linkDb));
  446. $this->assertEquals(
  447. 0,
  448. $this->linkDb['0']['private']
  449. );
  450. $this->assertEquals(
  451. 0,
  452. $this->linkDb['1']['private']
  453. );
  454. // re-import as private, enable overwriting
  455. $post = array(
  456. 'privacy' => 'private',
  457. 'overwrite' => 'true'
  458. );
  459. $this->assertStringMatchesFormat(
  460. 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
  461. .' 2 links imported, 2 links overwritten, 0 links skipped.',
  462. NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf, $this->history)
  463. );
  464. $this->assertEquals(2, count($this->linkDb));
  465. $this->assertEquals(2, count_private($this->linkDb));
  466. $this->assertEquals(
  467. 1,
  468. $this->linkDb['0']['private']
  469. );
  470. $this->assertEquals(
  471. 1,
  472. $this->linkDb['1']['private']
  473. );
  474. }
  475. /**
  476. * Attept to import the same links twice without enabling overwriting
  477. */
  478. public function testSkipOverwrite()
  479. {
  480. $post = array('privacy' => 'public');
  481. $files = file2array('netscape_basic.htm');
  482. $this->assertStringMatchesFormat(
  483. 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
  484. .' 2 links imported, 0 links overwritten, 0 links skipped.',
  485. NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf, $this->history)
  486. );
  487. $this->assertEquals(2, count($this->linkDb));
  488. $this->assertEquals(0, count_private($this->linkDb));
  489. // re-import as private, DO NOT enable overwriting
  490. $post = array('privacy' => 'private');
  491. $this->assertStringMatchesFormat(
  492. 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
  493. .' 0 links imported, 0 links overwritten, 2 links skipped.',
  494. NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf, $this->history)
  495. );
  496. $this->assertEquals(2, count($this->linkDb));
  497. $this->assertEquals(0, count_private($this->linkDb));
  498. }
  499. /**
  500. * Add user-specified tags to all imported bookmarks
  501. */
  502. public function testSetDefaultTags()
  503. {
  504. $post = array(
  505. 'privacy' => 'public',
  506. 'default_tags' => 'tag1,tag2 tag3'
  507. );
  508. $files = file2array('netscape_basic.htm');
  509. $this->assertStringMatchesFormat(
  510. 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
  511. .' 2 links imported, 0 links overwritten, 0 links skipped.',
  512. NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf, $this->history)
  513. );
  514. $this->assertEquals(2, count($this->linkDb));
  515. $this->assertEquals(0, count_private($this->linkDb));
  516. $this->assertEquals(
  517. 'tag1 tag2 tag3 private secret',
  518. $this->linkDb['0']['tags']
  519. );
  520. $this->assertEquals(
  521. 'tag1 tag2 tag3 public hello world',
  522. $this->linkDb['1']['tags']
  523. );
  524. }
  525. /**
  526. * The user-specified tags contain characters to be escaped
  527. */
  528. public function testSanitizeDefaultTags()
  529. {
  530. $post = array(
  531. 'privacy' => 'public',
  532. 'default_tags' => 'tag1&,tag2 "tag3"'
  533. );
  534. $files = file2array('netscape_basic.htm');
  535. $this->assertStringMatchesFormat(
  536. 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
  537. .' 2 links imported, 0 links overwritten, 0 links skipped.',
  538. NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf, $this->history)
  539. );
  540. $this->assertEquals(2, count($this->linkDb));
  541. $this->assertEquals(0, count_private($this->linkDb));
  542. $this->assertEquals(
  543. 'tag1&amp; tag2 &quot;tag3&quot; private secret',
  544. $this->linkDb['0']['tags']
  545. );
  546. $this->assertEquals(
  547. 'tag1&amp; tag2 &quot;tag3&quot; public hello world',
  548. $this->linkDb['1']['tags']
  549. );
  550. }
  551. /**
  552. * Ensure each imported bookmark has a unique id
  553. *
  554. * See https://github.com/shaarli/Shaarli/issues/351
  555. */
  556. public function testImportSameDate()
  557. {
  558. $files = file2array('same_date.htm');
  559. $this->assertStringMatchesFormat(
  560. 'File same_date.htm (453 bytes) was successfully processed in %d seconds:'
  561. .' 3 links imported, 0 links overwritten, 0 links skipped.',
  562. NetscapeBookmarkUtils::import(array(), $files, $this->linkDb, $this->conf, $this->history)
  563. );
  564. $this->assertEquals(3, count($this->linkDb));
  565. $this->assertEquals(0, count_private($this->linkDb));
  566. $this->assertEquals(
  567. 0,
  568. $this->linkDb[0]['id']
  569. );
  570. $this->assertEquals(
  571. 1,
  572. $this->linkDb[1]['id']
  573. );
  574. $this->assertEquals(
  575. 2,
  576. $this->linkDb[2]['id']
  577. );
  578. }
  579. public function testImportCreateUpdateHistory()
  580. {
  581. $post = [
  582. 'privacy' => 'public',
  583. 'overwrite' => 'true',
  584. ];
  585. $files = file2array('netscape_basic.htm');
  586. NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf, $this->history);
  587. $history = $this->history->getHistory();
  588. $this->assertEquals(1, count($history));
  589. $this->assertEquals(History::IMPORT, $history[0]['event']);
  590. $this->assertTrue(new DateTime('-5 seconds') < $history[0]['datetime']);
  591. // re-import as private, enable overwriting
  592. NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf, $this->history);
  593. $history = $this->history->getHistory();
  594. $this->assertEquals(2, count($history));
  595. $this->assertEquals(History::IMPORT, $history[0]['event']);
  596. $this->assertTrue(new DateTime('-5 seconds') < $history[0]['datetime']);
  597. $this->assertEquals(History::IMPORT, $history[1]['event']);
  598. $this->assertTrue(new DateTime('-5 seconds') < $history[1]['datetime']);
  599. }
  600. }