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.php110
1 files changed, 88 insertions, 22 deletions
diff --git a/tests/netscape/BookmarkExportTest.php b/tests/netscape/BookmarkExportTest.php
index 6de9876d..9b95ccc9 100644
--- a/tests/netscape/BookmarkExportTest.php
+++ b/tests/netscape/BookmarkExportTest.php
@@ -1,14 +1,20 @@
1<?php 1<?php
2
2namespace Shaarli\Netscape; 3namespace Shaarli\Netscape;
3 4
4use Shaarli\Bookmark\LinkDB; 5use Shaarli\Bookmark\BookmarkFileService;
6use Shaarli\Config\ConfigManager;
7use Shaarli\Formatter\BookmarkFormatter;
8use Shaarli\Formatter\FormatterFactory;
9use Shaarli\History;
10use Shaarli\TestCase;
5 11
6require_once 'tests/utils/ReferenceLinkDB.php'; 12require_once 'tests/utils/ReferenceLinkDB.php';
7 13
8/** 14/**
9 * Netscape bookmark export 15 * Netscape bookmark export
10 */ 16 */
11class BookmarkExportTest extends \PHPUnit\Framework\TestCase 17class BookmarkExportTest extends TestCase
12{ 18{
13 /** 19 /**
14 * @var string datastore to test write operations 20 * @var string datastore to test write operations
@@ -16,41 +22,86 @@ class BookmarkExportTest extends \PHPUnit\Framework\TestCase
16 protected static $testDatastore = 'sandbox/datastore.php'; 22 protected static $testDatastore = 'sandbox/datastore.php';
17 23
18 /** 24 /**
25 * @var ConfigManager instance.
26 */
27 protected static $conf;
28
29 /**
19 * @var \ReferenceLinkDB instance. 30 * @var \ReferenceLinkDB instance.
20 */ 31 */
21 protected static $refDb = null; 32 protected static $refDb = null;
22 33
23 /** 34 /**
24 * @var LinkDB private LinkDB instance. 35 * @var BookmarkFileService private instance.
36 */
37 protected static $bookmarkService = null;
38
39 /**
40 * @var BookmarkFormatter instance
41 */
42 protected static $formatter;
43
44 /**
45 * @var History instance
46 */
47 protected static $history;
48
49 /**
50 * @var NetscapeBookmarkUtils
25 */ 51 */
26 protected static $linkDb = null; 52 protected $netscapeBookmarkUtils;
27 53
28 /** 54 /**
29 * Instantiate reference data 55 * Instantiate reference data
30 */ 56 */
31 public static function setUpBeforeClass() 57 public static function setUpBeforeClass(): void
32 { 58 {
33 self::$refDb = new \ReferenceLinkDB(); 59 static::$conf = new ConfigManager('tests/utils/config/configJson');
34 self::$refDb->write(self::$testDatastore); 60 static::$conf->set('resource.datastore', static::$testDatastore);
35 self::$linkDb = new LinkDB(self::$testDatastore, true, false); 61 static::$refDb = new \ReferenceLinkDB();
62 static::$refDb->write(static::$testDatastore);
63 static::$history = new History('sandbox/history.php');
64 static::$bookmarkService = new BookmarkFileService(static::$conf, static::$history, true);
65 $factory = new FormatterFactory(static::$conf, true);
66 static::$formatter = $factory->getFormatter('raw');
67 }
68
69 public function setUp(): void
70 {
71 $this->netscapeBookmarkUtils = new NetscapeBookmarkUtils(
72 static::$bookmarkService,
73 static::$conf,
74 static::$history
75 );
36 } 76 }
37 77
38 /** 78 /**
39 * Attempt to export an invalid link selection 79 * Attempt to export an invalid link selection
40 * @expectedException Exception
41 * @expectedExceptionMessageRegExp /Invalid export selection/
42 */ 80 */
43 public function testFilterAndFormatInvalid() 81 public function testFilterAndFormatInvalid()
44 { 82 {
45 NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'derp', false, ''); 83 $this->expectException(\Exception::class);
84 $this->expectExceptionMessageRegExp('/Invalid export selection/');
85
86 $this->netscapeBookmarkUtils->filterAndFormat(
87 self::$formatter,
88 'derp',
89 false,
90 ''
91 );
46 } 92 }
47 93
48 /** 94 /**
49 * Prepare all links for export 95 * Prepare all bookmarks for export
50 */ 96 */
51 public function testFilterAndFormatAll() 97 public function testFilterAndFormatAll()
52 { 98 {
53 $links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'all', false, ''); 99 $links = $this->netscapeBookmarkUtils->filterAndFormat(
100 self::$formatter,
101 'all',
102 false,
103 ''
104 );
54 $this->assertEquals(self::$refDb->countLinks(), sizeof($links)); 105 $this->assertEquals(self::$refDb->countLinks(), sizeof($links));
55 foreach ($links as $link) { 106 foreach ($links as $link) {
56 $date = $link['created']; 107 $date = $link['created'];
@@ -66,11 +117,16 @@ class BookmarkExportTest extends \PHPUnit\Framework\TestCase
66 } 117 }
67 118
68 /** 119 /**
69 * Prepare private links for export 120 * Prepare private bookmarks for export
70 */ 121 */
71 public function testFilterAndFormatPrivate() 122 public function testFilterAndFormatPrivate()
72 { 123 {
73 $links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'private', false, ''); 124 $links = $this->netscapeBookmarkUtils->filterAndFormat(
125 self::$formatter,
126 'private',
127 false,
128 ''
129 );
74 $this->assertEquals(self::$refDb->countPrivateLinks(), sizeof($links)); 130 $this->assertEquals(self::$refDb->countPrivateLinks(), sizeof($links));
75 foreach ($links as $link) { 131 foreach ($links as $link) {
76 $date = $link['created']; 132 $date = $link['created'];
@@ -86,11 +142,16 @@ class BookmarkExportTest extends \PHPUnit\Framework\TestCase
86 } 142 }
87 143
88 /** 144 /**
89 * Prepare public links for export 145 * Prepare public bookmarks for export
90 */ 146 */
91 public function testFilterAndFormatPublic() 147 public function testFilterAndFormatPublic()
92 { 148 {
93 $links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'public', false, ''); 149 $links = $this->netscapeBookmarkUtils->filterAndFormat(
150 self::$formatter,
151 'public',
152 false,
153 ''
154 );
94 $this->assertEquals(self::$refDb->countPublicLinks(), sizeof($links)); 155 $this->assertEquals(self::$refDb->countPublicLinks(), sizeof($links));
95 foreach ($links as $link) { 156 foreach ($links as $link) {
96 $date = $link['created']; 157 $date = $link['created'];
@@ -110,9 +171,14 @@ class BookmarkExportTest extends \PHPUnit\Framework\TestCase
110 */ 171 */
111 public function testFilterAndFormatDoNotPrependNoteUrl() 172 public function testFilterAndFormatDoNotPrependNoteUrl()
112 { 173 {
113 $links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'public', false, ''); 174 $links = $this->netscapeBookmarkUtils->filterAndFormat(
175 self::$formatter,
176 'public',
177 false,
178 ''
179 );
114 $this->assertEquals( 180 $this->assertEquals(
115 '?WDWyig', 181 '/shaare/WDWyig',
116 $links[2]['url'] 182 $links[2]['url']
117 ); 183 );
118 } 184 }
@@ -123,14 +189,14 @@ class BookmarkExportTest extends \PHPUnit\Framework\TestCase
123 public function testFilterAndFormatPrependNoteUrl() 189 public function testFilterAndFormatPrependNoteUrl()
124 { 190 {
125 $indexUrl = 'http://localhost:7469/shaarli/'; 191 $indexUrl = 'http://localhost:7469/shaarli/';
126 $links = NetscapeBookmarkUtils::filterAndFormat( 192 $links = $this->netscapeBookmarkUtils->filterAndFormat(
127 self::$linkDb, 193 self::$formatter,
128 'public', 194 'public',
129 true, 195 true,
130 $indexUrl 196 $indexUrl
131 ); 197 );
132 $this->assertEquals( 198 $this->assertEquals(
133 $indexUrl . '?WDWyig', 199 $indexUrl . 'shaare/WDWyig',
134 $links[2]['url'] 200 $links[2]['url']
135 ); 201 );
136 } 202 }