aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/netscape/BookmarkExportTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/netscape/BookmarkExportTest.php')
-rw-r--r--tests/netscape/BookmarkExportTest.php137
1 files changed, 137 insertions, 0 deletions
diff --git a/tests/netscape/BookmarkExportTest.php b/tests/netscape/BookmarkExportTest.php
new file mode 100644
index 00000000..6de9876d
--- /dev/null
+++ b/tests/netscape/BookmarkExportTest.php
@@ -0,0 +1,137 @@
1<?php
2namespace Shaarli\Netscape;
3
4use Shaarli\Bookmark\LinkDB;
5
6require_once 'tests/utils/ReferenceLinkDB.php';
7
8/**
9 * Netscape bookmark export
10 */
11class BookmarkExportTest extends \PHPUnit\Framework\TestCase
12{
13 /**
14 * @var string datastore to test write operations
15 */
16 protected static $testDatastore = 'sandbox/datastore.php';
17
18 /**
19 * @var \ReferenceLinkDB instance.
20 */
21 protected static $refDb = null;
22
23 /**
24 * @var LinkDB private LinkDB instance.
25 */
26 protected static $linkDb = null;
27
28 /**
29 * Instantiate reference data
30 */
31 public static function setUpBeforeClass()
32 {
33 self::$refDb = new \ReferenceLinkDB();
34 self::$refDb->write(self::$testDatastore);
35 self::$linkDb = new LinkDB(self::$testDatastore, true, false);
36 }
37
38 /**
39 * Attempt to export an invalid link selection
40 * @expectedException Exception
41 * @expectedExceptionMessageRegExp /Invalid export selection/
42 */
43 public function testFilterAndFormatInvalid()
44 {
45 NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'derp', false, '');
46 }
47
48 /**
49 * Prepare all links for export
50 */
51 public function testFilterAndFormatAll()
52 {
53 $links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'all', false, '');
54 $this->assertEquals(self::$refDb->countLinks(), sizeof($links));
55 foreach ($links as $link) {
56 $date = $link['created'];
57 $this->assertEquals(
58 $date->getTimestamp(),
59 $link['timestamp']
60 );
61 $this->assertEquals(
62 str_replace(' ', ',', $link['tags']),
63 $link['taglist']
64 );
65 }
66 }
67
68 /**
69 * Prepare private links for export
70 */
71 public function testFilterAndFormatPrivate()
72 {
73 $links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'private', false, '');
74 $this->assertEquals(self::$refDb->countPrivateLinks(), sizeof($links));
75 foreach ($links as $link) {
76 $date = $link['created'];
77 $this->assertEquals(
78 $date->getTimestamp(),
79 $link['timestamp']
80 );
81 $this->assertEquals(
82 str_replace(' ', ',', $link['tags']),
83 $link['taglist']
84 );
85 }
86 }
87
88 /**
89 * Prepare public links for export
90 */
91 public function testFilterAndFormatPublic()
92 {
93 $links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'public', false, '');
94 $this->assertEquals(self::$refDb->countPublicLinks(), sizeof($links));
95 foreach ($links as $link) {
96 $date = $link['created'];
97 $this->assertEquals(
98 $date->getTimestamp(),
99 $link['timestamp']
100 );
101 $this->assertEquals(
102 str_replace(' ', ',', $link['tags']),
103 $link['taglist']
104 );
105 }
106 }
107
108 /**
109 * Do not prepend notes with the Shaarli index's URL
110 */
111 public function testFilterAndFormatDoNotPrependNoteUrl()
112 {
113 $links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'public', false, '');
114 $this->assertEquals(
115 '?WDWyig',
116 $links[2]['url']
117 );
118 }
119
120 /**
121 * Prepend notes with the Shaarli index's URL
122 */
123 public function testFilterAndFormatPrependNoteUrl()
124 {
125 $indexUrl = 'http://localhost:7469/shaarli/';
126 $links = NetscapeBookmarkUtils::filterAndFormat(
127 self::$linkDb,
128 'public',
129 true,
130 $indexUrl
131 );
132 $this->assertEquals(
133 $indexUrl . '?WDWyig',
134 $links[2]['url']
135 );
136 }
137}