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