aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/NetscapeBookmarkUtilsTest.php
diff options
context:
space:
mode:
authorVirtualTam <virtualtam@flibidi.net>2016-07-28 22:54:33 +0200
committerVirtualTam <virtualtam@flibidi.net>2016-08-10 01:42:44 +0200
commita973afeac7b7399d35b881920f0afc1947765ccd (patch)
tree4a13ddf32779cb8f02600d7cc20d23f692c9068c /tests/NetscapeBookmarkUtilsTest.php
parent085157c5cb6bd0df928c7875fb7997683418f1fb (diff)
downloadShaarli-a973afeac7b7399d35b881920f0afc1947765ccd.tar.gz
Shaarli-a973afeac7b7399d35b881920f0afc1947765ccd.tar.zst
Shaarli-a973afeac7b7399d35b881920f0afc1947765ccd.zip
Refactor bookmark import using a generic Netscape parser
Relates to #607 Relates to #608 Relates to #493 (abandoned) Additions: - use Composer's autoload to load 3rd-party dependencies under vendor/ Modifications: - [import] replace the current parser with a generic, stable parser - move code to application/NetscapeBookmarkUtils - improve status report after parsing - [router] use the same endpoint for both bookmark upload and import dialog - [template] update bookmark import options - allow adding tags to all imported links - allow selecting the visibility (privacy) of imported links - [tests] ensure bookmarks are properly parsed and imported in the LinkDB - reuse reference input from the parser's test data See: - https://github.com/shaarli/netscape-bookmark-parser - https://getcomposer.org/doc/01-basic-usage.md#autoloading Signed-off-by: VirtualTam <virtualtam@flibidi.net>
Diffstat (limited to 'tests/NetscapeBookmarkUtilsTest.php')
-rw-r--r--tests/NetscapeBookmarkUtilsTest.php134
1 files changed, 0 insertions, 134 deletions
diff --git a/tests/NetscapeBookmarkUtilsTest.php b/tests/NetscapeBookmarkUtilsTest.php
deleted file mode 100644
index 41e6d84c..00000000
--- a/tests/NetscapeBookmarkUtilsTest.php
+++ /dev/null
@@ -1,134 +0,0 @@
1<?php
2
3require_once 'application/NetscapeBookmarkUtils.php';
4
5/**
6 * Netscape bookmark import and export
7 */
8class NetscapeBookmarkUtilsTest 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 = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']);
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 = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']);
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 = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']);
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[0]['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[0]['url']
132 );
133 }
134}