diff options
Diffstat (limited to 'tests/netscape/BookmarkImportTest.php')
-rw-r--r-- | tests/netscape/BookmarkImportTest.php | 570 |
1 files changed, 260 insertions, 310 deletions
diff --git a/tests/netscape/BookmarkImportTest.php b/tests/netscape/BookmarkImportTest.php index ccafc161..fef7f6d1 100644 --- a/tests/netscape/BookmarkImportTest.php +++ b/tests/netscape/BookmarkImportTest.php | |||
@@ -2,6 +2,9 @@ | |||
2 | namespace Shaarli\Netscape; | 2 | namespace Shaarli\Netscape; |
3 | 3 | ||
4 | use DateTime; | 4 | use DateTime; |
5 | use Shaarli\Bookmark\Bookmark; | ||
6 | use Shaarli\Bookmark\BookmarkFilter; | ||
7 | use Shaarli\Bookmark\BookmarkFileService; | ||
5 | use Shaarli\Bookmark\LinkDB; | 8 | use Shaarli\Bookmark\LinkDB; |
6 | use Shaarli\Config\ConfigManager; | 9 | use Shaarli\Config\ConfigManager; |
7 | use Shaarli\History; | 10 | use Shaarli\History; |
@@ -41,9 +44,9 @@ class BookmarkImportTest extends \PHPUnit\Framework\TestCase | |||
41 | protected static $historyFilePath = 'sandbox/history.php'; | 44 | protected static $historyFilePath = 'sandbox/history.php'; |
42 | 45 | ||
43 | /** | 46 | /** |
44 | * @var LinkDB private LinkDB instance | 47 | * @var BookmarkFileService private LinkDB instance |
45 | */ | 48 | */ |
46 | protected $linkDb = null; | 49 | protected $bookmarkService = null; |
47 | 50 | ||
48 | /** | 51 | /** |
49 | * @var string Dummy page cache | 52 | * @var string Dummy page cache |
@@ -82,10 +85,12 @@ class BookmarkImportTest extends \PHPUnit\Framework\TestCase | |||
82 | } | 85 | } |
83 | // start with an empty datastore | 86 | // start with an empty datastore |
84 | file_put_contents(self::$testDatastore, '<?php /* S7QysKquBQA= */ ?>'); | 87 | file_put_contents(self::$testDatastore, '<?php /* S7QysKquBQA= */ ?>'); |
85 | $this->linkDb = new LinkDB(self::$testDatastore, true, false); | 88 | |
86 | $this->conf = new ConfigManager('tests/utils/config/configJson'); | 89 | $this->conf = new ConfigManager('tests/utils/config/configJson'); |
87 | $this->conf->set('resource.page_cache', $this->pagecache); | 90 | $this->conf->set('resource.page_cache', $this->pagecache); |
91 | $this->conf->set('resource.datastore', self::$testDatastore); | ||
88 | $this->history = new History(self::$historyFilePath); | 92 | $this->history = new History(self::$historyFilePath); |
93 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); | ||
89 | } | 94 | } |
90 | 95 | ||
91 | /** | 96 | /** |
@@ -112,7 +117,7 @@ class BookmarkImportTest extends \PHPUnit\Framework\TestCase | |||
112 | .' Nothing was imported.', | 117 | .' Nothing was imported.', |
113 | NetscapeBookmarkUtils::import(null, $files, null, $this->conf, $this->history) | 118 | NetscapeBookmarkUtils::import(null, $files, null, $this->conf, $this->history) |
114 | ); | 119 | ); |
115 | $this->assertEquals(0, count($this->linkDb)); | 120 | $this->assertEquals(0, $this->bookmarkService->count()); |
116 | } | 121 | } |
117 | 122 | ||
118 | /** | 123 | /** |
@@ -125,7 +130,7 @@ class BookmarkImportTest extends \PHPUnit\Framework\TestCase | |||
125 | 'File no_doctype.htm (350 bytes) has an unknown file format. Nothing was imported.', | 130 | 'File no_doctype.htm (350 bytes) has an unknown file format. Nothing was imported.', |
126 | NetscapeBookmarkUtils::import(null, $files, null, $this->conf, $this->history) | 131 | NetscapeBookmarkUtils::import(null, $files, null, $this->conf, $this->history) |
127 | ); | 132 | ); |
128 | $this->assertEquals(0, count($this->linkDb)); | 133 | $this->assertEquals(0, $this->bookmarkService->count()); |
129 | } | 134 | } |
130 | 135 | ||
131 | /** | 136 | /** |
@@ -136,10 +141,10 @@ class BookmarkImportTest extends \PHPUnit\Framework\TestCase | |||
136 | $files = file2array('lowercase_doctype.htm'); | 141 | $files = file2array('lowercase_doctype.htm'); |
137 | $this->assertStringMatchesFormat( | 142 | $this->assertStringMatchesFormat( |
138 | 'File lowercase_doctype.htm (386 bytes) was successfully processed in %d seconds:' | 143 | 'File lowercase_doctype.htm (386 bytes) was successfully processed in %d seconds:' |
139 | .' 2 links imported, 0 links overwritten, 0 links skipped.', | 144 | .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.', |
140 | NetscapeBookmarkUtils::import(null, $files, $this->linkDb, $this->conf, $this->history) | 145 | NetscapeBookmarkUtils::import(null, $files, $this->bookmarkService, $this->conf, $this->history) |
141 | ); | 146 | ); |
142 | $this->assertEquals(2, count($this->linkDb)); | 147 | $this->assertEquals(2, $this->bookmarkService->count()); |
143 | } | 148 | } |
144 | 149 | ||
145 | 150 | ||
@@ -151,25 +156,24 @@ class BookmarkImportTest extends \PHPUnit\Framework\TestCase | |||
151 | $files = file2array('internet_explorer_encoding.htm'); | 156 | $files = file2array('internet_explorer_encoding.htm'); |
152 | $this->assertStringMatchesFormat( | 157 | $this->assertStringMatchesFormat( |
153 | 'File internet_explorer_encoding.htm (356 bytes) was successfully processed in %d seconds:' | 158 | 'File internet_explorer_encoding.htm (356 bytes) was successfully processed in %d seconds:' |
154 | .' 1 links imported, 0 links overwritten, 0 links skipped.', | 159 | .' 1 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.', |
155 | NetscapeBookmarkUtils::import([], $files, $this->linkDb, $this->conf, $this->history) | 160 | NetscapeBookmarkUtils::import([], $files, $this->bookmarkService, $this->conf, $this->history) |
156 | ); | 161 | ); |
157 | $this->assertEquals(1, count($this->linkDb)); | 162 | $this->assertEquals(1, $this->bookmarkService->count()); |
158 | $this->assertEquals(0, count_private($this->linkDb)); | 163 | $this->assertEquals(0, $this->bookmarkService->count(BookmarkFilter::$PRIVATE)); |
159 | 164 | ||
165 | $bookmark = $this->bookmarkService->findByUrl('http://hginit.com/'); | ||
166 | $this->assertEquals(0, $bookmark->getId()); | ||
160 | $this->assertEquals( | 167 | $this->assertEquals( |
161 | array( | 168 | DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20160618_203944'), |
162 | 'id' => 0, | 169 | $bookmark->getCreated() |
163 | 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160618_203944'), | ||
164 | 'title' => 'Hg Init a Mercurial tutorial by Joel Spolsky', | ||
165 | 'url' => 'http://hginit.com/', | ||
166 | 'description' => '', | ||
167 | 'private' => 0, | ||
168 | 'tags' => '', | ||
169 | 'shorturl' => 'La37cg', | ||
170 | ), | ||
171 | $this->linkDb->getLinkFromUrl('http://hginit.com/') | ||
172 | ); | 170 | ); |
171 | $this->assertEquals('Hg Init a Mercurial tutorial by Joel Spolsky', $bookmark->getTitle()); | ||
172 | $this->assertEquals('http://hginit.com/', $bookmark->getUrl()); | ||
173 | $this->assertEquals('', $bookmark->getDescription()); | ||
174 | $this->assertFalse($bookmark->isPrivate()); | ||
175 | $this->assertEquals('', $bookmark->getTagsString()); | ||
176 | $this->assertEquals('La37cg', $bookmark->getShortUrl()); | ||
173 | } | 177 | } |
174 | 178 | ||
175 | /** | 179 | /** |
@@ -180,116 +184,115 @@ class BookmarkImportTest extends \PHPUnit\Framework\TestCase | |||
180 | $files = file2array('netscape_nested.htm'); | 184 | $files = file2array('netscape_nested.htm'); |
181 | $this->assertStringMatchesFormat( | 185 | $this->assertStringMatchesFormat( |
182 | 'File netscape_nested.htm (1337 bytes) was successfully processed in %d seconds:' | 186 | 'File netscape_nested.htm (1337 bytes) was successfully processed in %d seconds:' |
183 | .' 8 links imported, 0 links overwritten, 0 links skipped.', | 187 | .' 8 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.', |
184 | NetscapeBookmarkUtils::import([], $files, $this->linkDb, $this->conf, $this->history) | 188 | NetscapeBookmarkUtils::import([], $files, $this->bookmarkService, $this->conf, $this->history) |
185 | ); | ||
186 | $this->assertEquals(8, count($this->linkDb)); | ||
187 | $this->assertEquals(2, count_private($this->linkDb)); | ||
188 | |||
189 | $this->assertEquals( | ||
190 | array( | ||
191 | 'id' => 0, | ||
192 | 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160225_235541'), | ||
193 | 'title' => 'Nested 1', | ||
194 | 'url' => 'http://nest.ed/1', | ||
195 | 'description' => '', | ||
196 | 'private' => 0, | ||
197 | 'tags' => 'tag1 tag2', | ||
198 | 'shorturl' => 'KyDNKA', | ||
199 | ), | ||
200 | $this->linkDb->getLinkFromUrl('http://nest.ed/1') | ||
201 | ); | ||
202 | $this->assertEquals( | ||
203 | array( | ||
204 | 'id' => 1, | ||
205 | 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160225_235542'), | ||
206 | 'title' => 'Nested 1-1', | ||
207 | 'url' => 'http://nest.ed/1-1', | ||
208 | 'description' => '', | ||
209 | 'private' => 0, | ||
210 | 'tags' => 'folder1 tag1 tag2', | ||
211 | 'shorturl' => 'T2LnXg', | ||
212 | ), | ||
213 | $this->linkDb->getLinkFromUrl('http://nest.ed/1-1') | ||
214 | ); | ||
215 | $this->assertEquals( | ||
216 | array( | ||
217 | 'id' => 2, | ||
218 | 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160225_235547'), | ||
219 | 'title' => 'Nested 1-2', | ||
220 | 'url' => 'http://nest.ed/1-2', | ||
221 | 'description' => '', | ||
222 | 'private' => 0, | ||
223 | 'tags' => 'folder1 tag3 tag4', | ||
224 | 'shorturl' => '46SZxA', | ||
225 | ), | ||
226 | $this->linkDb->getLinkFromUrl('http://nest.ed/1-2') | ||
227 | ); | ||
228 | $this->assertEquals( | ||
229 | array( | ||
230 | 'id' => 3, | ||
231 | 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160202_202222'), | ||
232 | 'title' => 'Nested 2-1', | ||
233 | 'url' => 'http://nest.ed/2-1', | ||
234 | 'description' => 'First link of the second section', | ||
235 | 'private' => 1, | ||
236 | 'tags' => 'folder2', | ||
237 | 'shorturl' => '4UHOSw', | ||
238 | ), | ||
239 | $this->linkDb->getLinkFromUrl('http://nest.ed/2-1') | ||
240 | ); | ||
241 | $this->assertEquals( | ||
242 | array( | ||
243 | 'id' => 4, | ||
244 | 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160119_230227'), | ||
245 | 'title' => 'Nested 2-2', | ||
246 | 'url' => 'http://nest.ed/2-2', | ||
247 | 'description' => 'Second link of the second section', | ||
248 | 'private' => 1, | ||
249 | 'tags' => 'folder2', | ||
250 | 'shorturl' => 'yfzwbw', | ||
251 | ), | ||
252 | $this->linkDb->getLinkFromUrl('http://nest.ed/2-2') | ||
253 | ); | ||
254 | $this->assertEquals( | ||
255 | array( | ||
256 | 'id' => 5, | ||
257 | 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160202_202222'), | ||
258 | 'title' => 'Nested 3-1', | ||
259 | 'url' => 'http://nest.ed/3-1', | ||
260 | 'description' => '', | ||
261 | 'private' => 0, | ||
262 | 'tags' => 'folder3 folder3-1 tag3', | ||
263 | 'shorturl' => 'UwxIUQ', | ||
264 | ), | ||
265 | $this->linkDb->getLinkFromUrl('http://nest.ed/3-1') | ||
266 | ); | ||
267 | $this->assertEquals( | ||
268 | array( | ||
269 | 'id' => 6, | ||
270 | 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160119_230227'), | ||
271 | 'title' => 'Nested 3-2', | ||
272 | 'url' => 'http://nest.ed/3-2', | ||
273 | 'description' => '', | ||
274 | 'private' => 0, | ||
275 | 'tags' => 'folder3 folder3-1', | ||
276 | 'shorturl' => 'p8dyZg', | ||
277 | ), | ||
278 | $this->linkDb->getLinkFromUrl('http://nest.ed/3-2') | ||
279 | ); | ||
280 | $this->assertEquals( | ||
281 | array( | ||
282 | 'id' => 7, | ||
283 | 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160229_111541'), | ||
284 | 'title' => 'Nested 2', | ||
285 | 'url' => 'http://nest.ed/2', | ||
286 | 'description' => '', | ||
287 | 'private' => 0, | ||
288 | 'tags' => 'tag4', | ||
289 | 'shorturl' => 'Gt3Uug', | ||
290 | ), | ||
291 | $this->linkDb->getLinkFromUrl('http://nest.ed/2') | ||
292 | ); | 189 | ); |
190 | $this->assertEquals(8, $this->bookmarkService->count()); | ||
191 | $this->assertEquals(2, $this->bookmarkService->count(BookmarkFilter::$PRIVATE)); | ||
192 | |||
193 | $bookmark = $this->bookmarkService->findByUrl('http://nest.ed/1'); | ||
194 | $this->assertEquals(0, $bookmark->getId()); | ||
195 | $this->assertEquals( | ||
196 | DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20160225_235541'), | ||
197 | $bookmark->getCreated() | ||
198 | ); | ||
199 | $this->assertEquals('Nested 1', $bookmark->getTitle()); | ||
200 | $this->assertEquals('http://nest.ed/1', $bookmark->getUrl()); | ||
201 | $this->assertEquals('', $bookmark->getDescription()); | ||
202 | $this->assertFalse($bookmark->isPrivate()); | ||
203 | $this->assertEquals('tag1 tag2', $bookmark->getTagsString()); | ||
204 | $this->assertEquals('KyDNKA', $bookmark->getShortUrl()); | ||
205 | |||
206 | $bookmark = $this->bookmarkService->findByUrl('http://nest.ed/1-1'); | ||
207 | $this->assertEquals(1, $bookmark->getId()); | ||
208 | $this->assertEquals( | ||
209 | DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20160225_235542'), | ||
210 | $bookmark->getCreated() | ||
211 | ); | ||
212 | $this->assertEquals('Nested 1-1', $bookmark->getTitle()); | ||
213 | $this->assertEquals('http://nest.ed/1-1', $bookmark->getUrl()); | ||
214 | $this->assertEquals('', $bookmark->getDescription()); | ||
215 | $this->assertFalse($bookmark->isPrivate()); | ||
216 | $this->assertEquals('folder1 tag1 tag2', $bookmark->getTagsString()); | ||
217 | $this->assertEquals('T2LnXg', $bookmark->getShortUrl()); | ||
218 | |||
219 | $bookmark = $this->bookmarkService->findByUrl('http://nest.ed/1-2'); | ||
220 | $this->assertEquals(2, $bookmark->getId()); | ||
221 | $this->assertEquals( | ||
222 | DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20160225_235547'), | ||
223 | $bookmark->getCreated() | ||
224 | ); | ||
225 | $this->assertEquals('Nested 1-2', $bookmark->getTitle()); | ||
226 | $this->assertEquals('http://nest.ed/1-2', $bookmark->getUrl()); | ||
227 | $this->assertEquals('', $bookmark->getDescription()); | ||
228 | $this->assertFalse($bookmark->isPrivate()); | ||
229 | $this->assertEquals('folder1 tag3 tag4', $bookmark->getTagsString()); | ||
230 | $this->assertEquals('46SZxA', $bookmark->getShortUrl()); | ||
231 | |||
232 | $bookmark = $this->bookmarkService->findByUrl('http://nest.ed/2-1'); | ||
233 | $this->assertEquals(3, $bookmark->getId()); | ||
234 | $this->assertEquals( | ||
235 | DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20160202_202222'), | ||
236 | $bookmark->getCreated() | ||
237 | ); | ||
238 | $this->assertEquals('Nested 2-1', $bookmark->getTitle()); | ||
239 | $this->assertEquals('http://nest.ed/2-1', $bookmark->getUrl()); | ||
240 | $this->assertEquals('First link of the second section', $bookmark->getDescription()); | ||
241 | $this->assertTrue($bookmark->isPrivate()); | ||
242 | $this->assertEquals('folder2', $bookmark->getTagsString()); | ||
243 | $this->assertEquals('4UHOSw', $bookmark->getShortUrl()); | ||
244 | |||
245 | $bookmark = $this->bookmarkService->findByUrl('http://nest.ed/2-2'); | ||
246 | $this->assertEquals(4, $bookmark->getId()); | ||
247 | $this->assertEquals( | ||
248 | DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20160119_230227'), | ||
249 | $bookmark->getCreated() | ||
250 | ); | ||
251 | $this->assertEquals('Nested 2-2', $bookmark->getTitle()); | ||
252 | $this->assertEquals('http://nest.ed/2-2', $bookmark->getUrl()); | ||
253 | $this->assertEquals('Second link of the second section', $bookmark->getDescription()); | ||
254 | $this->assertTrue($bookmark->isPrivate()); | ||
255 | $this->assertEquals('folder2', $bookmark->getTagsString()); | ||
256 | $this->assertEquals('yfzwbw', $bookmark->getShortUrl()); | ||
257 | |||
258 | $bookmark = $this->bookmarkService->findByUrl('http://nest.ed/3-1'); | ||
259 | $this->assertEquals(5, $bookmark->getId()); | ||
260 | $this->assertEquals( | ||
261 | DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20160202_202222'), | ||
262 | $bookmark->getCreated() | ||
263 | ); | ||
264 | $this->assertEquals('Nested 3-1', $bookmark->getTitle()); | ||
265 | $this->assertEquals('http://nest.ed/3-1', $bookmark->getUrl()); | ||
266 | $this->assertEquals('', $bookmark->getDescription()); | ||
267 | $this->assertFalse($bookmark->isPrivate()); | ||
268 | $this->assertEquals('folder3 folder3-1 tag3', $bookmark->getTagsString()); | ||
269 | $this->assertEquals('UwxIUQ', $bookmark->getShortUrl()); | ||
270 | |||
271 | $bookmark = $this->bookmarkService->findByUrl('http://nest.ed/3-2'); | ||
272 | $this->assertEquals(6, $bookmark->getId()); | ||
273 | $this->assertEquals( | ||
274 | DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20160119_230227'), | ||
275 | $bookmark->getCreated() | ||
276 | ); | ||
277 | $this->assertEquals('Nested 3-2', $bookmark->getTitle()); | ||
278 | $this->assertEquals('http://nest.ed/3-2', $bookmark->getUrl()); | ||
279 | $this->assertEquals('', $bookmark->getDescription()); | ||
280 | $this->assertFalse($bookmark->isPrivate()); | ||
281 | $this->assertEquals('folder3 folder3-1', $bookmark->getTagsString()); | ||
282 | $this->assertEquals('p8dyZg', $bookmark->getShortUrl()); | ||
283 | |||
284 | $bookmark = $this->bookmarkService->findByUrl('http://nest.ed/2'); | ||
285 | $this->assertEquals(7, $bookmark->getId()); | ||
286 | $this->assertEquals( | ||
287 | DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20160229_111541'), | ||
288 | $bookmark->getCreated() | ||
289 | ); | ||
290 | $this->assertEquals('Nested 2', $bookmark->getTitle()); | ||
291 | $this->assertEquals('http://nest.ed/2', $bookmark->getUrl()); | ||
292 | $this->assertEquals('', $bookmark->getDescription()); | ||
293 | $this->assertFalse($bookmark->isPrivate()); | ||
294 | $this->assertEquals('tag4', $bookmark->getTagsString()); | ||
295 | $this->assertEquals('Gt3Uug', $bookmark->getShortUrl()); | ||
293 | } | 296 | } |
294 | 297 | ||
295 | /** | 298 | /** |
@@ -302,40 +305,38 @@ class BookmarkImportTest extends \PHPUnit\Framework\TestCase | |||
302 | $files = file2array('netscape_basic.htm'); | 305 | $files = file2array('netscape_basic.htm'); |
303 | $this->assertStringMatchesFormat( | 306 | $this->assertStringMatchesFormat( |
304 | 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:' | 307 | 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:' |
305 | .' 2 links imported, 0 links overwritten, 0 links skipped.', | 308 | .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.', |
306 | NetscapeBookmarkUtils::import([], $files, $this->linkDb, $this->conf, $this->history) | 309 | NetscapeBookmarkUtils::import([], $files, $this->bookmarkService, $this->conf, $this->history) |
307 | ); | 310 | ); |
308 | 311 | ||
309 | $this->assertEquals(2, count($this->linkDb)); | 312 | $this->assertEquals(2, $this->bookmarkService->count()); |
310 | $this->assertEquals(1, count_private($this->linkDb)); | 313 | $this->assertEquals(1, $this->bookmarkService->count(BookmarkFilter::$PRIVATE)); |
311 | 314 | ||
315 | $bookmark = $this->bookmarkService->findByUrl('https://private.tld'); | ||
316 | $this->assertEquals(0, $bookmark->getId()); | ||
312 | $this->assertEquals( | 317 | $this->assertEquals( |
313 | array( | 318 | DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20001010_135536'), |
314 | 'id' => 0, | 319 | $bookmark->getCreated() |
315 | // Old link - UTC+4 (note that TZ in the import file is ignored). | ||
316 | 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20001010_135536'), | ||
317 | 'title' => 'Secret stuff', | ||
318 | 'url' => 'https://private.tld', | ||
319 | 'description' => "Super-secret stuff you're not supposed to know about", | ||
320 | 'private' => 1, | ||
321 | 'tags' => 'private secret', | ||
322 | 'shorturl' => 'EokDtA', | ||
323 | ), | ||
324 | $this->linkDb->getLinkFromUrl('https://private.tld') | ||
325 | ); | 320 | ); |
321 | $this->assertEquals('Secret stuff', $bookmark->getTitle()); | ||
322 | $this->assertEquals('https://private.tld', $bookmark->getUrl()); | ||
323 | $this->assertEquals('Super-secret stuff you\'re not supposed to know about', $bookmark->getDescription()); | ||
324 | $this->assertTrue($bookmark->isPrivate()); | ||
325 | $this->assertEquals('private secret', $bookmark->getTagsString()); | ||
326 | $this->assertEquals('EokDtA', $bookmark->getShortUrl()); | ||
327 | |||
328 | $bookmark = $this->bookmarkService->findByUrl('http://public.tld'); | ||
329 | $this->assertEquals(1, $bookmark->getId()); | ||
326 | $this->assertEquals( | 330 | $this->assertEquals( |
327 | array( | 331 | DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20160225_235548'), |
328 | 'id' => 1, | 332 | $bookmark->getCreated() |
329 | 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160225_235548'), | ||
330 | 'title' => 'Public stuff', | ||
331 | 'url' => 'http://public.tld', | ||
332 | 'description' => '', | ||
333 | 'private' => 0, | ||
334 | 'tags' => 'public hello world', | ||
335 | 'shorturl' => 'Er9ddA', | ||
336 | ), | ||
337 | $this->linkDb->getLinkFromUrl('http://public.tld') | ||
338 | ); | 333 | ); |
334 | $this->assertEquals('Public stuff', $bookmark->getTitle()); | ||
335 | $this->assertEquals('http://public.tld', $bookmark->getUrl()); | ||
336 | $this->assertEquals('', $bookmark->getDescription()); | ||
337 | $this->assertFalse($bookmark->isPrivate()); | ||
338 | $this->assertEquals('public hello world', $bookmark->getTagsString()); | ||
339 | $this->assertEquals('Er9ddA', $bookmark->getShortUrl()); | ||
339 | } | 340 | } |
340 | 341 | ||
341 | /** | 342 | /** |
@@ -347,43 +348,42 @@ class BookmarkImportTest extends \PHPUnit\Framework\TestCase | |||
347 | $files = file2array('netscape_basic.htm'); | 348 | $files = file2array('netscape_basic.htm'); |
348 | $this->assertStringMatchesFormat( | 349 | $this->assertStringMatchesFormat( |
349 | 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:' | 350 | 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:' |
350 | .' 2 links imported, 0 links overwritten, 0 links skipped.', | 351 | .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.', |
351 | NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf, $this->history) | 352 | NetscapeBookmarkUtils::import($post, $files, $this->bookmarkService, $this->conf, $this->history) |
352 | ); | 353 | ); |
353 | $this->assertEquals(2, count($this->linkDb)); | ||
354 | $this->assertEquals(1, count_private($this->linkDb)); | ||
355 | 354 | ||
355 | $this->assertEquals(2, $this->bookmarkService->count()); | ||
356 | $this->assertEquals(1, $this->bookmarkService->count(BookmarkFilter::$PRIVATE)); | ||
357 | |||
358 | $bookmark = $this->bookmarkService->findByUrl('https://private.tld'); | ||
359 | $this->assertEquals(0, $bookmark->getId()); | ||
356 | $this->assertEquals( | 360 | $this->assertEquals( |
357 | array( | 361 | DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20001010_135536'), |
358 | 'id' => 0, | 362 | $bookmark->getCreated() |
359 | // Note that TZ in the import file is ignored. | ||
360 | 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20001010_135536'), | ||
361 | 'title' => 'Secret stuff', | ||
362 | 'url' => 'https://private.tld', | ||
363 | 'description' => "Super-secret stuff you're not supposed to know about", | ||
364 | 'private' => 1, | ||
365 | 'tags' => 'private secret', | ||
366 | 'shorturl' => 'EokDtA', | ||
367 | ), | ||
368 | $this->linkDb->getLinkFromUrl('https://private.tld') | ||
369 | ); | 363 | ); |
364 | $this->assertEquals('Secret stuff', $bookmark->getTitle()); | ||
365 | $this->assertEquals('https://private.tld', $bookmark->getUrl()); | ||
366 | $this->assertEquals('Super-secret stuff you\'re not supposed to know about', $bookmark->getDescription()); | ||
367 | $this->assertTrue($bookmark->isPrivate()); | ||
368 | $this->assertEquals('private secret', $bookmark->getTagsString()); | ||
369 | $this->assertEquals('EokDtA', $bookmark->getShortUrl()); | ||
370 | |||
371 | $bookmark = $this->bookmarkService->findByUrl('http://public.tld'); | ||
372 | $this->assertEquals(1, $bookmark->getId()); | ||
370 | $this->assertEquals( | 373 | $this->assertEquals( |
371 | array( | 374 | DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20160225_235548'), |
372 | 'id' => 1, | 375 | $bookmark->getCreated() |
373 | 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160225_235548'), | ||
374 | 'title' => 'Public stuff', | ||
375 | 'url' => 'http://public.tld', | ||
376 | 'description' => '', | ||
377 | 'private' => 0, | ||
378 | 'tags' => 'public hello world', | ||
379 | 'shorturl' => 'Er9ddA', | ||
380 | ), | ||
381 | $this->linkDb->getLinkFromUrl('http://public.tld') | ||
382 | ); | 376 | ); |
377 | $this->assertEquals('Public stuff', $bookmark->getTitle()); | ||
378 | $this->assertEquals('http://public.tld', $bookmark->getUrl()); | ||
379 | $this->assertEquals('', $bookmark->getDescription()); | ||
380 | $this->assertFalse($bookmark->isPrivate()); | ||
381 | $this->assertEquals('public hello world', $bookmark->getTagsString()); | ||
382 | $this->assertEquals('Er9ddA', $bookmark->getShortUrl()); | ||
383 | } | 383 | } |
384 | 384 | ||
385 | /** | 385 | /** |
386 | * Import links as public | 386 | * Import bookmarks as public |
387 | */ | 387 | */ |
388 | public function testImportAsPublic() | 388 | public function testImportAsPublic() |
389 | { | 389 | { |
@@ -391,23 +391,17 @@ class BookmarkImportTest extends \PHPUnit\Framework\TestCase | |||
391 | $files = file2array('netscape_basic.htm'); | 391 | $files = file2array('netscape_basic.htm'); |
392 | $this->assertStringMatchesFormat( | 392 | $this->assertStringMatchesFormat( |
393 | 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:' | 393 | 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:' |
394 | .' 2 links imported, 0 links overwritten, 0 links skipped.', | 394 | .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.', |
395 | NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf, $this->history) | 395 | NetscapeBookmarkUtils::import($post, $files, $this->bookmarkService, $this->conf, $this->history) |
396 | ); | ||
397 | $this->assertEquals(2, count($this->linkDb)); | ||
398 | $this->assertEquals(0, count_private($this->linkDb)); | ||
399 | $this->assertEquals( | ||
400 | 0, | ||
401 | $this->linkDb[0]['private'] | ||
402 | ); | ||
403 | $this->assertEquals( | ||
404 | 0, | ||
405 | $this->linkDb[1]['private'] | ||
406 | ); | 396 | ); |
397 | $this->assertEquals(2, $this->bookmarkService->count()); | ||
398 | $this->assertEquals(0, $this->bookmarkService->count(BookmarkFilter::$PRIVATE)); | ||
399 | $this->assertFalse($this->bookmarkService->get(0)->isPrivate()); | ||
400 | $this->assertFalse($this->bookmarkService->get(1)->isPrivate()); | ||
407 | } | 401 | } |
408 | 402 | ||
409 | /** | 403 | /** |
410 | * Import links as private | 404 | * Import bookmarks as private |
411 | */ | 405 | */ |
412 | public function testImportAsPrivate() | 406 | public function testImportAsPrivate() |
413 | { | 407 | { |
@@ -415,45 +409,34 @@ class BookmarkImportTest extends \PHPUnit\Framework\TestCase | |||
415 | $files = file2array('netscape_basic.htm'); | 409 | $files = file2array('netscape_basic.htm'); |
416 | $this->assertStringMatchesFormat( | 410 | $this->assertStringMatchesFormat( |
417 | 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:' | 411 | 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:' |
418 | .' 2 links imported, 0 links overwritten, 0 links skipped.', | 412 | .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.', |
419 | NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf, $this->history) | 413 | NetscapeBookmarkUtils::import($post, $files, $this->bookmarkService, $this->conf, $this->history) |
420 | ); | ||
421 | $this->assertEquals(2, count($this->linkDb)); | ||
422 | $this->assertEquals(2, count_private($this->linkDb)); | ||
423 | $this->assertEquals( | ||
424 | 1, | ||
425 | $this->linkDb['0']['private'] | ||
426 | ); | ||
427 | $this->assertEquals( | ||
428 | 1, | ||
429 | $this->linkDb['1']['private'] | ||
430 | ); | 414 | ); |
415 | $this->assertEquals(2, $this->bookmarkService->count()); | ||
416 | $this->assertEquals(2, $this->bookmarkService->count(BookmarkFilter::$PRIVATE)); | ||
417 | $this->assertTrue($this->bookmarkService->get(0)->isPrivate()); | ||
418 | $this->assertTrue($this->bookmarkService->get(1)->isPrivate()); | ||
431 | } | 419 | } |
432 | 420 | ||
433 | /** | 421 | /** |
434 | * Overwrite private links so they become public | 422 | * Overwrite private bookmarks so they become public |
435 | */ | 423 | */ |
436 | public function testOverwriteAsPublic() | 424 | public function testOverwriteAsPublic() |
437 | { | 425 | { |
438 | $files = file2array('netscape_basic.htm'); | 426 | $files = file2array('netscape_basic.htm'); |
439 | 427 | ||
440 | // import links as private | 428 | // import bookmarks as private |
441 | $post = array('privacy' => 'private'); | 429 | $post = array('privacy' => 'private'); |
442 | $this->assertStringMatchesFormat( | 430 | $this->assertStringMatchesFormat( |
443 | 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:' | 431 | 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:' |
444 | .' 2 links imported, 0 links overwritten, 0 links skipped.', | 432 | .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.', |
445 | NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf, $this->history) | 433 | NetscapeBookmarkUtils::import($post, $files, $this->bookmarkService, $this->conf, $this->history) |
446 | ); | ||
447 | $this->assertEquals(2, count($this->linkDb)); | ||
448 | $this->assertEquals(2, count_private($this->linkDb)); | ||
449 | $this->assertEquals( | ||
450 | 1, | ||
451 | $this->linkDb[0]['private'] | ||
452 | ); | ||
453 | $this->assertEquals( | ||
454 | 1, | ||
455 | $this->linkDb[1]['private'] | ||
456 | ); | 434 | ); |
435 | $this->assertEquals(2, $this->bookmarkService->count()); | ||
436 | $this->assertEquals(2, $this->bookmarkService->count(BookmarkFilter::$PRIVATE)); | ||
437 | $this->assertTrue($this->bookmarkService->get(0)->isPrivate()); | ||
438 | $this->assertTrue($this->bookmarkService->get(1)->isPrivate()); | ||
439 | |||
457 | // re-import as public, enable overwriting | 440 | // re-import as public, enable overwriting |
458 | $post = array( | 441 | $post = array( |
459 | 'privacy' => 'public', | 442 | 'privacy' => 'public', |
@@ -461,45 +444,33 @@ class BookmarkImportTest extends \PHPUnit\Framework\TestCase | |||
461 | ); | 444 | ); |
462 | $this->assertStringMatchesFormat( | 445 | $this->assertStringMatchesFormat( |
463 | 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:' | 446 | 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:' |
464 | .' 2 links imported, 2 links overwritten, 0 links skipped.', | 447 | .' 2 bookmarks imported, 2 bookmarks overwritten, 0 bookmarks skipped.', |
465 | NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf, $this->history) | 448 | NetscapeBookmarkUtils::import($post, $files, $this->bookmarkService, $this->conf, $this->history) |
466 | ); | ||
467 | $this->assertEquals(2, count($this->linkDb)); | ||
468 | $this->assertEquals(0, count_private($this->linkDb)); | ||
469 | $this->assertEquals( | ||
470 | 0, | ||
471 | $this->linkDb[0]['private'] | ||
472 | ); | ||
473 | $this->assertEquals( | ||
474 | 0, | ||
475 | $this->linkDb[1]['private'] | ||
476 | ); | 449 | ); |
450 | $this->assertEquals(2, $this->bookmarkService->count()); | ||
451 | $this->assertEquals(0, $this->bookmarkService->count(BookmarkFilter::$PRIVATE)); | ||
452 | $this->assertFalse($this->bookmarkService->get(0)->isPrivate()); | ||
453 | $this->assertFalse($this->bookmarkService->get(1)->isPrivate()); | ||
477 | } | 454 | } |
478 | 455 | ||
479 | /** | 456 | /** |
480 | * Overwrite public links so they become private | 457 | * Overwrite public bookmarks so they become private |
481 | */ | 458 | */ |
482 | public function testOverwriteAsPrivate() | 459 | public function testOverwriteAsPrivate() |
483 | { | 460 | { |
484 | $files = file2array('netscape_basic.htm'); | 461 | $files = file2array('netscape_basic.htm'); |
485 | 462 | ||
486 | // import links as public | 463 | // import bookmarks as public |
487 | $post = array('privacy' => 'public'); | 464 | $post = array('privacy' => 'public'); |
488 | $this->assertStringMatchesFormat( | 465 | $this->assertStringMatchesFormat( |
489 | 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:' | 466 | 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:' |
490 | .' 2 links imported, 0 links overwritten, 0 links skipped.', | 467 | .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.', |
491 | NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf, $this->history) | 468 | NetscapeBookmarkUtils::import($post, $files, $this->bookmarkService, $this->conf, $this->history) |
492 | ); | ||
493 | $this->assertEquals(2, count($this->linkDb)); | ||
494 | $this->assertEquals(0, count_private($this->linkDb)); | ||
495 | $this->assertEquals( | ||
496 | 0, | ||
497 | $this->linkDb['0']['private'] | ||
498 | ); | ||
499 | $this->assertEquals( | ||
500 | 0, | ||
501 | $this->linkDb['1']['private'] | ||
502 | ); | 469 | ); |
470 | $this->assertEquals(2, $this->bookmarkService->count()); | ||
471 | $this->assertEquals(0, $this->bookmarkService->count(BookmarkFilter::$PRIVATE)); | ||
472 | $this->assertFalse($this->bookmarkService->get(0)->isPrivate()); | ||
473 | $this->assertFalse($this->bookmarkService->get(1)->isPrivate()); | ||
503 | 474 | ||
504 | // re-import as private, enable overwriting | 475 | // re-import as private, enable overwriting |
505 | $post = array( | 476 | $post = array( |
@@ -508,23 +479,17 @@ class BookmarkImportTest extends \PHPUnit\Framework\TestCase | |||
508 | ); | 479 | ); |
509 | $this->assertStringMatchesFormat( | 480 | $this->assertStringMatchesFormat( |
510 | 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:' | 481 | 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:' |
511 | .' 2 links imported, 2 links overwritten, 0 links skipped.', | 482 | .' 2 bookmarks imported, 2 bookmarks overwritten, 0 bookmarks skipped.', |
512 | NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf, $this->history) | 483 | NetscapeBookmarkUtils::import($post, $files, $this->bookmarkService, $this->conf, $this->history) |
513 | ); | ||
514 | $this->assertEquals(2, count($this->linkDb)); | ||
515 | $this->assertEquals(2, count_private($this->linkDb)); | ||
516 | $this->assertEquals( | ||
517 | 1, | ||
518 | $this->linkDb['0']['private'] | ||
519 | ); | ||
520 | $this->assertEquals( | ||
521 | 1, | ||
522 | $this->linkDb['1']['private'] | ||
523 | ); | 484 | ); |
485 | $this->assertEquals(2, $this->bookmarkService->count()); | ||
486 | $this->assertEquals(2, $this->bookmarkService->count(BookmarkFilter::$PRIVATE)); | ||
487 | $this->assertTrue($this->bookmarkService->get(0)->isPrivate()); | ||
488 | $this->assertTrue($this->bookmarkService->get(1)->isPrivate()); | ||
524 | } | 489 | } |
525 | 490 | ||
526 | /** | 491 | /** |
527 | * Attept to import the same links twice without enabling overwriting | 492 | * Attept to import the same bookmarks twice without enabling overwriting |
528 | */ | 493 | */ |
529 | public function testSkipOverwrite() | 494 | public function testSkipOverwrite() |
530 | { | 495 | { |
@@ -532,21 +497,21 @@ class BookmarkImportTest extends \PHPUnit\Framework\TestCase | |||
532 | $files = file2array('netscape_basic.htm'); | 497 | $files = file2array('netscape_basic.htm'); |
533 | $this->assertStringMatchesFormat( | 498 | $this->assertStringMatchesFormat( |
534 | 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:' | 499 | 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:' |
535 | .' 2 links imported, 0 links overwritten, 0 links skipped.', | 500 | .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.', |
536 | NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf, $this->history) | 501 | NetscapeBookmarkUtils::import($post, $files, $this->bookmarkService, $this->conf, $this->history) |
537 | ); | 502 | ); |
538 | $this->assertEquals(2, count($this->linkDb)); | 503 | $this->assertEquals(2, $this->bookmarkService->count()); |
539 | $this->assertEquals(0, count_private($this->linkDb)); | 504 | $this->assertEquals(0, $this->bookmarkService->count(BookmarkFilter::$PRIVATE)); |
540 | 505 | ||
541 | // re-import as private, DO NOT enable overwriting | 506 | // re-import as private, DO NOT enable overwriting |
542 | $post = array('privacy' => 'private'); | 507 | $post = array('privacy' => 'private'); |
543 | $this->assertStringMatchesFormat( | 508 | $this->assertStringMatchesFormat( |
544 | 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:' | 509 | 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:' |
545 | .' 0 links imported, 0 links overwritten, 2 links skipped.', | 510 | .' 0 bookmarks imported, 0 bookmarks overwritten, 2 bookmarks skipped.', |
546 | NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf, $this->history) | 511 | NetscapeBookmarkUtils::import($post, $files, $this->bookmarkService, $this->conf, $this->history) |
547 | ); | 512 | ); |
548 | $this->assertEquals(2, count($this->linkDb)); | 513 | $this->assertEquals(2, $this->bookmarkService->count()); |
549 | $this->assertEquals(0, count_private($this->linkDb)); | 514 | $this->assertEquals(0, $this->bookmarkService->count(BookmarkFilter::$PRIVATE)); |
550 | } | 515 | } |
551 | 516 | ||
552 | /** | 517 | /** |
@@ -561,19 +526,13 @@ class BookmarkImportTest extends \PHPUnit\Framework\TestCase | |||
561 | $files = file2array('netscape_basic.htm'); | 526 | $files = file2array('netscape_basic.htm'); |
562 | $this->assertStringMatchesFormat( | 527 | $this->assertStringMatchesFormat( |
563 | 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:' | 528 | 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:' |
564 | .' 2 links imported, 0 links overwritten, 0 links skipped.', | 529 | .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.', |
565 | NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf, $this->history) | 530 | NetscapeBookmarkUtils::import($post, $files, $this->bookmarkService, $this->conf, $this->history) |
566 | ); | ||
567 | $this->assertEquals(2, count($this->linkDb)); | ||
568 | $this->assertEquals(0, count_private($this->linkDb)); | ||
569 | $this->assertEquals( | ||
570 | 'tag1 tag2 tag3 private secret', | ||
571 | $this->linkDb['0']['tags'] | ||
572 | ); | ||
573 | $this->assertEquals( | ||
574 | 'tag1 tag2 tag3 public hello world', | ||
575 | $this->linkDb['1']['tags'] | ||
576 | ); | 531 | ); |
532 | $this->assertEquals(2, $this->bookmarkService->count()); | ||
533 | $this->assertEquals(0, $this->bookmarkService->count(BookmarkFilter::$PRIVATE)); | ||
534 | $this->assertEquals('tag1 tag2 tag3 private secret', $this->bookmarkService->get(0)->getTagsString()); | ||
535 | $this->assertEquals('tag1 tag2 tag3 public hello world', $this->bookmarkService->get(1)->getTagsString()); | ||
577 | } | 536 | } |
578 | 537 | ||
579 | /** | 538 | /** |
@@ -588,18 +547,18 @@ class BookmarkImportTest extends \PHPUnit\Framework\TestCase | |||
588 | $files = file2array('netscape_basic.htm'); | 547 | $files = file2array('netscape_basic.htm'); |
589 | $this->assertStringMatchesFormat( | 548 | $this->assertStringMatchesFormat( |
590 | 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:' | 549 | 'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:' |
591 | .' 2 links imported, 0 links overwritten, 0 links skipped.', | 550 | .' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.', |
592 | NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf, $this->history) | 551 | NetscapeBookmarkUtils::import($post, $files, $this->bookmarkService, $this->conf, $this->history) |
593 | ); | 552 | ); |
594 | $this->assertEquals(2, count($this->linkDb)); | 553 | $this->assertEquals(2, $this->bookmarkService->count()); |
595 | $this->assertEquals(0, count_private($this->linkDb)); | 554 | $this->assertEquals(0, $this->bookmarkService->count(BookmarkFilter::$PRIVATE)); |
596 | $this->assertEquals( | 555 | $this->assertEquals( |
597 | 'tag1& tag2 "tag3" private secret', | 556 | 'tag1& tag2 "tag3" private secret', |
598 | $this->linkDb['0']['tags'] | 557 | $this->bookmarkService->get(0)->getTagsString() |
599 | ); | 558 | ); |
600 | $this->assertEquals( | 559 | $this->assertEquals( |
601 | 'tag1& tag2 "tag3" public hello world', | 560 | 'tag1& tag2 "tag3" public hello world', |
602 | $this->linkDb['1']['tags'] | 561 | $this->bookmarkService->get(1)->getTagsString() |
603 | ); | 562 | ); |
604 | } | 563 | } |
605 | 564 | ||
@@ -613,23 +572,14 @@ class BookmarkImportTest extends \PHPUnit\Framework\TestCase | |||
613 | $files = file2array('same_date.htm'); | 572 | $files = file2array('same_date.htm'); |
614 | $this->assertStringMatchesFormat( | 573 | $this->assertStringMatchesFormat( |
615 | 'File same_date.htm (453 bytes) was successfully processed in %d seconds:' | 574 | 'File same_date.htm (453 bytes) was successfully processed in %d seconds:' |
616 | .' 3 links imported, 0 links overwritten, 0 links skipped.', | 575 | .' 3 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.', |
617 | NetscapeBookmarkUtils::import(array(), $files, $this->linkDb, $this->conf, $this->history) | 576 | NetscapeBookmarkUtils::import(array(), $files, $this->bookmarkService, $this->conf, $this->history) |
618 | ); | 577 | ); |
619 | $this->assertEquals(3, count($this->linkDb)); | 578 | $this->assertEquals(3, $this->bookmarkService->count()); |
620 | $this->assertEquals(0, count_private($this->linkDb)); | 579 | $this->assertEquals(0, $this->bookmarkService->count(BookmarkFilter::$PRIVATE)); |
621 | $this->assertEquals( | 580 | $this->assertEquals(0, $this->bookmarkService->get(0)->getId()); |
622 | 0, | 581 | $this->assertEquals(1, $this->bookmarkService->get(1)->getId()); |
623 | $this->linkDb[0]['id'] | 582 | $this->assertEquals(2, $this->bookmarkService->get(2)->getId()); |
624 | ); | ||
625 | $this->assertEquals( | ||
626 | 1, | ||
627 | $this->linkDb[1]['id'] | ||
628 | ); | ||
629 | $this->assertEquals( | ||
630 | 2, | ||
631 | $this->linkDb[2]['id'] | ||
632 | ); | ||
633 | } | 583 | } |
634 | 584 | ||
635 | public function testImportCreateUpdateHistory() | 585 | public function testImportCreateUpdateHistory() |
@@ -639,14 +589,14 @@ class BookmarkImportTest extends \PHPUnit\Framework\TestCase | |||
639 | 'overwrite' => 'true', | 589 | 'overwrite' => 'true', |
640 | ]; | 590 | ]; |
641 | $files = file2array('netscape_basic.htm'); | 591 | $files = file2array('netscape_basic.htm'); |
642 | NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf, $this->history); | 592 | NetscapeBookmarkUtils::import($post, $files, $this->bookmarkService, $this->conf, $this->history); |
643 | $history = $this->history->getHistory(); | 593 | $history = $this->history->getHistory(); |
644 | $this->assertEquals(1, count($history)); | 594 | $this->assertEquals(1, count($history)); |
645 | $this->assertEquals(History::IMPORT, $history[0]['event']); | 595 | $this->assertEquals(History::IMPORT, $history[0]['event']); |
646 | $this->assertTrue(new DateTime('-5 seconds') < $history[0]['datetime']); | 596 | $this->assertTrue(new DateTime('-5 seconds') < $history[0]['datetime']); |
647 | 597 | ||
648 | // re-import as private, enable overwriting | 598 | // re-import as private, enable overwriting |
649 | NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf, $this->history); | 599 | NetscapeBookmarkUtils::import($post, $files, $this->bookmarkService, $this->conf, $this->history); |
650 | $history = $this->history->getHistory(); | 600 | $history = $this->history->getHistory(); |
651 | $this->assertEquals(2, count($history)); | 601 | $this->assertEquals(2, count($history)); |
652 | $this->assertEquals(History::IMPORT, $history[0]['event']); | 602 | $this->assertEquals(History::IMPORT, $history[0]['event']); |