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