aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/NetscapeBookmarkUtilsTest.php
diff options
context:
space:
mode:
authorVirtualTam <virtualtam@flibidi.net>2016-04-10 17:34:07 +0200
committerVirtualTam <virtualtam@flibidi.net>2016-04-10 21:28:04 +0200
commitcd5327bee83f3e9467d786752bbd447963b941f7 (patch)
tree7abb6d242fc551b33b1d5b9f066fdabf4ef64c4d /tests/NetscapeBookmarkUtilsTest.php
parent745304c842e6e1234aac41a3f1c496c4522f32c5 (diff)
downloadShaarli-cd5327bee83f3e9467d786752bbd447963b941f7.tar.gz
Shaarli-cd5327bee83f3e9467d786752bbd447963b941f7.tar.zst
Shaarli-cd5327bee83f3e9467d786752bbd447963b941f7.zip
Refactor Netscape bookmark exporting
Relates to https://github.com/shaarli/netscape-bookmark-parser/issues/5 Fixes: - respect the Netscape bookmark format "specification" Modifications: - [application] introduce the NetscapeBookmarkUtils class - [template] export - improve formatting, rename export selection parameter - [template] export.bookmarks - template for Netscape exports - [tests] bookmark filtering, additional field generation Signed-off-by: VirtualTam <virtualtam@flibidi.net>
Diffstat (limited to 'tests/NetscapeBookmarkUtilsTest.php')
-rw-r--r--tests/NetscapeBookmarkUtilsTest.php104
1 files changed, 104 insertions, 0 deletions
diff --git a/tests/NetscapeBookmarkUtilsTest.php b/tests/NetscapeBookmarkUtilsTest.php
new file mode 100644
index 00000000..b7472d92
--- /dev/null
+++ b/tests/NetscapeBookmarkUtilsTest.php
@@ -0,0 +1,104 @@
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');
43 }
44
45 /**
46 * Prepare all links for export
47 */
48 public function testFilterAndFormatAll()
49 {
50 $links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'all');
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');
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');
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}