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