aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/netscape/BookmarkExportTest.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-01-17 21:34:12 +0100
committerArthurHoaro <arthur@hoa.ro>2020-01-18 09:56:32 +0100
commite26e2060f5470ce8bf4c5973284bae07b8af170a (patch)
treeadf8512f93f5559ba87d0c9931969ae4ebea7133 /tests/netscape/BookmarkExportTest.php
parentcf92b4dd1521241eefc58eaf6dcd202cd83969d8 (diff)
downloadShaarli-e26e2060f5470ce8bf4c5973284bae07b8af170a.tar.gz
Shaarli-e26e2060f5470ce8bf4c5973284bae07b8af170a.tar.zst
Shaarli-e26e2060f5470ce8bf4c5973284bae07b8af170a.zip
Add and update unit test for the new system (Bookmark + Service)
See #1307
Diffstat (limited to 'tests/netscape/BookmarkExportTest.php')
-rw-r--r--tests/netscape/BookmarkExportTest.php70
1 files changed, 58 insertions, 12 deletions
diff --git a/tests/netscape/BookmarkExportTest.php b/tests/netscape/BookmarkExportTest.php
index 6de9876d..011d19ac 100644
--- a/tests/netscape/BookmarkExportTest.php
+++ b/tests/netscape/BookmarkExportTest.php
@@ -1,7 +1,12 @@
1<?php 1<?php
2namespace Shaarli\Netscape; 2namespace Shaarli\Netscape;
3 3
4use Shaarli\Bookmark\BookmarkFileService;
4use Shaarli\Bookmark\LinkDB; 5use Shaarli\Bookmark\LinkDB;
6use Shaarli\Config\ConfigManager;
7use Shaarli\Formatter\FormatterFactory;
8use Shaarli\Formatter\BookmarkFormatter;
9use Shaarli\History;
5 10
6require_once 'tests/utils/ReferenceLinkDB.php'; 11require_once 'tests/utils/ReferenceLinkDB.php';
7 12
@@ -21,18 +26,28 @@ class BookmarkExportTest extends \PHPUnit\Framework\TestCase
21 protected static $refDb = null; 26 protected static $refDb = null;
22 27
23 /** 28 /**
24 * @var LinkDB private LinkDB instance. 29 * @var BookmarkFileService private instance.
25 */ 30 */
26 protected static $linkDb = null; 31 protected static $bookmarkService = null;
32
33 /**
34 * @var BookmarkFormatter instance
35 */
36 protected static $formatter;
27 37
28 /** 38 /**
29 * Instantiate reference data 39 * Instantiate reference data
30 */ 40 */
31 public static function setUpBeforeClass() 41 public static function setUpBeforeClass()
32 { 42 {
43 $conf = new ConfigManager('tests/utils/config/configJson');
44 $conf->set('resource.datastore', self::$testDatastore);
33 self::$refDb = new \ReferenceLinkDB(); 45 self::$refDb = new \ReferenceLinkDB();
34 self::$refDb->write(self::$testDatastore); 46 self::$refDb->write(self::$testDatastore);
35 self::$linkDb = new LinkDB(self::$testDatastore, true, false); 47 $history = new History('sandbox/history.php');
48 self::$bookmarkService = new BookmarkFileService($conf, $history, true);
49 $factory = new FormatterFactory($conf);
50 self::$formatter = $factory->getFormatter('raw');
36 } 51 }
37 52
38 /** 53 /**
@@ -42,15 +57,27 @@ class BookmarkExportTest extends \PHPUnit\Framework\TestCase
42 */ 57 */
43 public function testFilterAndFormatInvalid() 58 public function testFilterAndFormatInvalid()
44 { 59 {
45 NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'derp', false, ''); 60 NetscapeBookmarkUtils::filterAndFormat(
61 self::$bookmarkService,
62 self::$formatter,
63 'derp',
64 false,
65 ''
66 );
46 } 67 }
47 68
48 /** 69 /**
49 * Prepare all links for export 70 * Prepare all bookmarks for export
50 */ 71 */
51 public function testFilterAndFormatAll() 72 public function testFilterAndFormatAll()
52 { 73 {
53 $links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'all', false, ''); 74 $links = NetscapeBookmarkUtils::filterAndFormat(
75 self::$bookmarkService,
76 self::$formatter,
77 'all',
78 false,
79 ''
80 );
54 $this->assertEquals(self::$refDb->countLinks(), sizeof($links)); 81 $this->assertEquals(self::$refDb->countLinks(), sizeof($links));
55 foreach ($links as $link) { 82 foreach ($links as $link) {
56 $date = $link['created']; 83 $date = $link['created'];
@@ -66,11 +93,17 @@ class BookmarkExportTest extends \PHPUnit\Framework\TestCase
66 } 93 }
67 94
68 /** 95 /**
69 * Prepare private links for export 96 * Prepare private bookmarks for export
70 */ 97 */
71 public function testFilterAndFormatPrivate() 98 public function testFilterAndFormatPrivate()
72 { 99 {
73 $links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'private', false, ''); 100 $links = NetscapeBookmarkUtils::filterAndFormat(
101 self::$bookmarkService,
102 self::$formatter,
103 'private',
104 false,
105 ''
106 );
74 $this->assertEquals(self::$refDb->countPrivateLinks(), sizeof($links)); 107 $this->assertEquals(self::$refDb->countPrivateLinks(), sizeof($links));
75 foreach ($links as $link) { 108 foreach ($links as $link) {
76 $date = $link['created']; 109 $date = $link['created'];
@@ -86,11 +119,17 @@ class BookmarkExportTest extends \PHPUnit\Framework\TestCase
86 } 119 }
87 120
88 /** 121 /**
89 * Prepare public links for export 122 * Prepare public bookmarks for export
90 */ 123 */
91 public function testFilterAndFormatPublic() 124 public function testFilterAndFormatPublic()
92 { 125 {
93 $links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'public', false, ''); 126 $links = NetscapeBookmarkUtils::filterAndFormat(
127 self::$bookmarkService,
128 self::$formatter,
129 'public',
130 false,
131 ''
132 );
94 $this->assertEquals(self::$refDb->countPublicLinks(), sizeof($links)); 133 $this->assertEquals(self::$refDb->countPublicLinks(), sizeof($links));
95 foreach ($links as $link) { 134 foreach ($links as $link) {
96 $date = $link['created']; 135 $date = $link['created'];
@@ -110,7 +149,13 @@ class BookmarkExportTest extends \PHPUnit\Framework\TestCase
110 */ 149 */
111 public function testFilterAndFormatDoNotPrependNoteUrl() 150 public function testFilterAndFormatDoNotPrependNoteUrl()
112 { 151 {
113 $links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'public', false, ''); 152 $links = NetscapeBookmarkUtils::filterAndFormat(
153 self::$bookmarkService,
154 self::$formatter,
155 'public',
156 false,
157 ''
158 );
114 $this->assertEquals( 159 $this->assertEquals(
115 '?WDWyig', 160 '?WDWyig',
116 $links[2]['url'] 161 $links[2]['url']
@@ -124,7 +169,8 @@ class BookmarkExportTest extends \PHPUnit\Framework\TestCase
124 { 169 {
125 $indexUrl = 'http://localhost:7469/shaarli/'; 170 $indexUrl = 'http://localhost:7469/shaarli/';
126 $links = NetscapeBookmarkUtils::filterAndFormat( 171 $links = NetscapeBookmarkUtils::filterAndFormat(
127 self::$linkDb, 172 self::$bookmarkService,
173 self::$formatter,
128 'public', 174 'public',
129 true, 175 true,
130 $indexUrl 176 $indexUrl