]> git.immae.eu Git - github/shaarli/Shaarli.git/blame - tests/netscape/BookmarkExportTest.php
namespacing: \Shaarli\Netscape\NetscapeBookmarkUtils
[github/shaarli/Shaarli.git] / tests / netscape / BookmarkExportTest.php
CommitLineData
cd5327be 1<?php
349b0144 2namespace Shaarli\Netscape;
cd5327be 3
f24896b2
V
4use Shaarli\Bookmark\LinkDB;
5
349b0144 6require_once 'tests/utils/ReferenceLinkDB.php';
cd5327be
V
7
8/**
a973afea 9 * Netscape bookmark export
cd5327be 10 */
349b0144 11class BookmarkExportTest extends \PHPUnit\Framework\TestCase
cd5327be
V
12{
13 /**
14 * @var string datastore to test write operations
15 */
16 protected static $testDatastore = 'sandbox/datastore.php';
17
18 /**
349b0144 19 * @var \ReferenceLinkDB instance.
cd5327be
V
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 {
349b0144 33 self::$refDb = new \ReferenceLinkDB();
cd5327be
V
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 {
bb4a23aa 45 NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'derp', false, '');
cd5327be
V
46 }
47
48 /**
49 * Prepare all links for export
50 */
51 public function testFilterAndFormatAll()
52 {
bb4a23aa 53 $links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'all', false, '');
cd5327be
V
54 $this->assertEquals(self::$refDb->countLinks(), sizeof($links));
55 foreach ($links as $link) {
c3dfd899 56 $date = $link['created'];
cd5327be
V
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 {
bb4a23aa 73 $links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'private', false, '');
cd5327be
V
74 $this->assertEquals(self::$refDb->countPrivateLinks(), sizeof($links));
75 foreach ($links as $link) {
c3dfd899 76 $date = $link['created'];
cd5327be
V
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 {
bb4a23aa 93 $links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'public', false, '');
cd5327be
V
94 $this->assertEquals(self::$refDb->countPublicLinks(), sizeof($links));
95 foreach ($links as $link) {
c3dfd899 96 $date = $link['created'];
cd5327be
V
97 $this->assertEquals(
98 $date->getTimestamp(),
99 $link['timestamp']
100 );
101 $this->assertEquals(
102 str_replace(' ', ',', $link['tags']),
103 $link['taglist']
104 );
105 }
106 }
bb4a23aa
V
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',
4154c25b 116 $links[2]['url']
bb4a23aa
V
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',
4154c25b 134 $links[2]['url']
bb4a23aa
V
135 );
136 }
cd5327be 137}