diff options
Diffstat (limited to 'tests/netscape/BookmarkExportTest.php')
-rw-r--r-- | tests/netscape/BookmarkExportTest.php | 69 |
1 files changed, 44 insertions, 25 deletions
diff --git a/tests/netscape/BookmarkExportTest.php b/tests/netscape/BookmarkExportTest.php index 6c948bba..509da51d 100644 --- a/tests/netscape/BookmarkExportTest.php +++ b/tests/netscape/BookmarkExportTest.php | |||
@@ -1,11 +1,12 @@ | |||
1 | <?php | 1 | <?php |
2 | |||
2 | namespace Shaarli\Netscape; | 3 | namespace Shaarli\Netscape; |
3 | 4 | ||
5 | use PHPUnit\Framework\TestCase; | ||
4 | use Shaarli\Bookmark\BookmarkFileService; | 6 | use Shaarli\Bookmark\BookmarkFileService; |
5 | use Shaarli\Bookmark\LinkDB; | ||
6 | use Shaarli\Config\ConfigManager; | 7 | use Shaarli\Config\ConfigManager; |
7 | use Shaarli\Formatter\FormatterFactory; | ||
8 | use Shaarli\Formatter\BookmarkFormatter; | 8 | use Shaarli\Formatter\BookmarkFormatter; |
9 | use Shaarli\Formatter\FormatterFactory; | ||
9 | use Shaarli\History; | 10 | use Shaarli\History; |
10 | 11 | ||
11 | require_once 'tests/utils/ReferenceLinkDB.php'; | 12 | require_once 'tests/utils/ReferenceLinkDB.php'; |
@@ -13,7 +14,7 @@ require_once 'tests/utils/ReferenceLinkDB.php'; | |||
13 | /** | 14 | /** |
14 | * Netscape bookmark export | 15 | * Netscape bookmark export |
15 | */ | 16 | */ |
16 | class BookmarkExportTest extends \PHPUnit\Framework\TestCase | 17 | class BookmarkExportTest extends TestCase |
17 | { | 18 | { |
18 | /** | 19 | /** |
19 | * @var string datastore to test write operations | 20 | * @var string datastore to test write operations |
@@ -21,6 +22,11 @@ class BookmarkExportTest extends \PHPUnit\Framework\TestCase | |||
21 | protected static $testDatastore = 'sandbox/datastore.php'; | 22 | protected static $testDatastore = 'sandbox/datastore.php'; |
22 | 23 | ||
23 | /** | 24 | /** |
25 | * @var ConfigManager instance. | ||
26 | */ | ||
27 | protected static $conf; | ||
28 | |||
29 | /** | ||
24 | * @var \ReferenceLinkDB instance. | 30 | * @var \ReferenceLinkDB instance. |
25 | */ | 31 | */ |
26 | protected static $refDb = null; | 32 | protected static $refDb = null; |
@@ -36,18 +42,37 @@ class BookmarkExportTest extends \PHPUnit\Framework\TestCase | |||
36 | protected static $formatter; | 42 | protected static $formatter; |
37 | 43 | ||
38 | /** | 44 | /** |
45 | * @var History instance | ||
46 | */ | ||
47 | protected static $history; | ||
48 | |||
49 | /** | ||
50 | * @var NetscapeBookmarkUtils | ||
51 | */ | ||
52 | protected $netscapeBookmarkUtils; | ||
53 | |||
54 | /** | ||
39 | * Instantiate reference data | 55 | * Instantiate reference data |
40 | */ | 56 | */ |
41 | public static function setUpBeforeClass() | 57 | public static function setUpBeforeClass() |
42 | { | 58 | { |
43 | $conf = new ConfigManager('tests/utils/config/configJson'); | 59 | static::$conf = new ConfigManager('tests/utils/config/configJson'); |
44 | $conf->set('resource.datastore', self::$testDatastore); | 60 | static::$conf->set('resource.datastore', static::$testDatastore); |
45 | self::$refDb = new \ReferenceLinkDB(); | 61 | static::$refDb = new \ReferenceLinkDB(); |
46 | self::$refDb->write(self::$testDatastore); | 62 | static::$refDb->write(static::$testDatastore); |
47 | $history = new History('sandbox/history.php'); | 63 | static::$history = new History('sandbox/history.php'); |
48 | self::$bookmarkService = new BookmarkFileService($conf, $history, true); | 64 | static::$bookmarkService = new BookmarkFileService(static::$conf, static::$history, true); |
49 | $factory = new FormatterFactory($conf, true); | 65 | $factory = new FormatterFactory(static::$conf, true); |
50 | self::$formatter = $factory->getFormatter('raw'); | 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 | ); | ||
51 | } | 76 | } |
52 | 77 | ||
53 | /** | 78 | /** |
@@ -57,8 +82,7 @@ class BookmarkExportTest extends \PHPUnit\Framework\TestCase | |||
57 | */ | 82 | */ |
58 | public function testFilterAndFormatInvalid() | 83 | public function testFilterAndFormatInvalid() |
59 | { | 84 | { |
60 | NetscapeBookmarkUtils::filterAndFormat( | 85 | $this->netscapeBookmarkUtils->filterAndFormat( |
61 | self::$bookmarkService, | ||
62 | self::$formatter, | 86 | self::$formatter, |
63 | 'derp', | 87 | 'derp', |
64 | false, | 88 | false, |
@@ -71,8 +95,7 @@ class BookmarkExportTest extends \PHPUnit\Framework\TestCase | |||
71 | */ | 95 | */ |
72 | public function testFilterAndFormatAll() | 96 | public function testFilterAndFormatAll() |
73 | { | 97 | { |
74 | $links = NetscapeBookmarkUtils::filterAndFormat( | 98 | $links = $this->netscapeBookmarkUtils->filterAndFormat( |
75 | self::$bookmarkService, | ||
76 | self::$formatter, | 99 | self::$formatter, |
77 | 'all', | 100 | 'all', |
78 | false, | 101 | false, |
@@ -97,8 +120,7 @@ class BookmarkExportTest extends \PHPUnit\Framework\TestCase | |||
97 | */ | 120 | */ |
98 | public function testFilterAndFormatPrivate() | 121 | public function testFilterAndFormatPrivate() |
99 | { | 122 | { |
100 | $links = NetscapeBookmarkUtils::filterAndFormat( | 123 | $links = $this->netscapeBookmarkUtils->filterAndFormat( |
101 | self::$bookmarkService, | ||
102 | self::$formatter, | 124 | self::$formatter, |
103 | 'private', | 125 | 'private', |
104 | false, | 126 | false, |
@@ -123,8 +145,7 @@ class BookmarkExportTest extends \PHPUnit\Framework\TestCase | |||
123 | */ | 145 | */ |
124 | public function testFilterAndFormatPublic() | 146 | public function testFilterAndFormatPublic() |
125 | { | 147 | { |
126 | $links = NetscapeBookmarkUtils::filterAndFormat( | 148 | $links = $this->netscapeBookmarkUtils->filterAndFormat( |
127 | self::$bookmarkService, | ||
128 | self::$formatter, | 149 | self::$formatter, |
129 | 'public', | 150 | 'public', |
130 | false, | 151 | false, |
@@ -149,15 +170,14 @@ class BookmarkExportTest extends \PHPUnit\Framework\TestCase | |||
149 | */ | 170 | */ |
150 | public function testFilterAndFormatDoNotPrependNoteUrl() | 171 | public function testFilterAndFormatDoNotPrependNoteUrl() |
151 | { | 172 | { |
152 | $links = NetscapeBookmarkUtils::filterAndFormat( | 173 | $links = $this->netscapeBookmarkUtils->filterAndFormat( |
153 | self::$bookmarkService, | ||
154 | self::$formatter, | 174 | self::$formatter, |
155 | 'public', | 175 | 'public', |
156 | false, | 176 | false, |
157 | '' | 177 | '' |
158 | ); | 178 | ); |
159 | $this->assertEquals( | 179 | $this->assertEquals( |
160 | '?WDWyig', | 180 | '/shaare/WDWyig', |
161 | $links[2]['url'] | 181 | $links[2]['url'] |
162 | ); | 182 | ); |
163 | } | 183 | } |
@@ -168,15 +188,14 @@ class BookmarkExportTest extends \PHPUnit\Framework\TestCase | |||
168 | public function testFilterAndFormatPrependNoteUrl() | 188 | public function testFilterAndFormatPrependNoteUrl() |
169 | { | 189 | { |
170 | $indexUrl = 'http://localhost:7469/shaarli/'; | 190 | $indexUrl = 'http://localhost:7469/shaarli/'; |
171 | $links = NetscapeBookmarkUtils::filterAndFormat( | 191 | $links = $this->netscapeBookmarkUtils->filterAndFormat( |
172 | self::$bookmarkService, | ||
173 | self::$formatter, | 192 | self::$formatter, |
174 | 'public', | 193 | 'public', |
175 | true, | 194 | true, |
176 | $indexUrl | 195 | $indexUrl |
177 | ); | 196 | ); |
178 | $this->assertEquals( | 197 | $this->assertEquals( |
179 | $indexUrl . '?WDWyig', | 198 | $indexUrl . 'shaare/WDWyig', |
180 | $links[2]['url'] | 199 | $links[2]['url'] |
181 | ); | 200 | ); |
182 | } | 201 | } |