aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/bookmark/BookmarkTest.php44
-rw-r--r--tests/front/controller/admin/ManageShaareControllerTest/DisplayCreateFormTest.php10
-rw-r--r--tests/front/controller/admin/ManageShaareControllerTest/SaveBookmarkTest.php55
-rw-r--r--tests/front/controller/visitor/BookmarkListControllerTest.php57
4 files changed, 158 insertions, 8 deletions
diff --git a/tests/bookmark/BookmarkTest.php b/tests/bookmark/BookmarkTest.php
index 4c7ae4c0..4c1ae25d 100644
--- a/tests/bookmark/BookmarkTest.php
+++ b/tests/bookmark/BookmarkTest.php
@@ -347,4 +347,48 @@ class BookmarkTest extends TestCase
347 $bookmark->deleteTag('nope'); 347 $bookmark->deleteTag('nope');
348 $this->assertEquals(['tag1', 'tag2', 'chair'], $bookmark->getTags()); 348 $this->assertEquals(['tag1', 'tag2', 'chair'], $bookmark->getTags());
349 } 349 }
350
351 /**
352 * Test shouldUpdateThumbnail() with bookmarks needing an update.
353 */
354 public function testShouldUpdateThumbnail(): void
355 {
356 $bookmark = (new Bookmark())->setUrl('http://domain.tld/with-image');
357
358 static::assertTrue($bookmark->shouldUpdateThumbnail());
359
360 $bookmark = (new Bookmark())
361 ->setUrl('http://domain.tld/with-image')
362 ->setThumbnail('unknown file')
363 ;
364
365 static::assertTrue($bookmark->shouldUpdateThumbnail());
366 }
367
368 /**
369 * Test shouldUpdateThumbnail() with bookmarks that should not update.
370 */
371 public function testShouldNotUpdateThumbnail(): void
372 {
373 $bookmark = (new Bookmark());
374
375 static::assertFalse($bookmark->shouldUpdateThumbnail());
376
377 $bookmark = (new Bookmark())
378 ->setUrl('ftp://domain.tld/other-protocol', ['ftp'])
379 ;
380
381 static::assertFalse($bookmark->shouldUpdateThumbnail());
382
383 $bookmark = (new Bookmark())
384 ->setUrl('http://domain.tld/with-image')
385 ->setThumbnail(__FILE__)
386 ;
387
388 static::assertFalse($bookmark->shouldUpdateThumbnail());
389
390 $bookmark = (new Bookmark())->setUrl('/shaare/abcdef');
391
392 static::assertFalse($bookmark->shouldUpdateThumbnail());
393 }
350} 394}
diff --git a/tests/front/controller/admin/ManageShaareControllerTest/DisplayCreateFormTest.php b/tests/front/controller/admin/ManageShaareControllerTest/DisplayCreateFormTest.php
index 4fd88480..eafa54eb 100644
--- a/tests/front/controller/admin/ManageShaareControllerTest/DisplayCreateFormTest.php
+++ b/tests/front/controller/admin/ManageShaareControllerTest/DisplayCreateFormTest.php
@@ -144,12 +144,14 @@ class DisplayCreateFormTest extends TestCase
144 144
145 // Make sure that PluginManager hook is triggered 145 // Make sure that PluginManager hook is triggered
146 $this->container->pluginManager 146 $this->container->pluginManager
147 ->expects(static::at(0)) 147 ->expects(static::atLeastOnce())
148 ->method('executeHooks') 148 ->method('executeHooks')
149 ->withConsecutive(['render_editlink'], ['render_includes'])
149 ->willReturnCallback(function (string $hook, array $data): array { 150 ->willReturnCallback(function (string $hook, array $data): array {
150 static::assertSame('render_editlink', $hook); 151 if ('render_editlink' === $hook) {
151 static::assertSame('', $data['link']['title']); 152 static::assertSame('', $data['link']['title']);
152 static::assertSame('', $data['link']['description']); 153 static::assertSame('', $data['link']['description']);
154 }
153 155
154 return $data; 156 return $data;
155 }) 157 })
diff --git a/tests/front/controller/admin/ManageShaareControllerTest/SaveBookmarkTest.php b/tests/front/controller/admin/ManageShaareControllerTest/SaveBookmarkTest.php
index 37542c26..1adeef5a 100644
--- a/tests/front/controller/admin/ManageShaareControllerTest/SaveBookmarkTest.php
+++ b/tests/front/controller/admin/ManageShaareControllerTest/SaveBookmarkTest.php
@@ -209,7 +209,7 @@ class SaveBookmarkTest extends TestCase
209 /** 209 /**
210 * Test save a bookmark - try to retrieve the thumbnail 210 * Test save a bookmark - try to retrieve the thumbnail
211 */ 211 */
212 public function testSaveBookmarkWithThumbnail(): void 212 public function testSaveBookmarkWithThumbnailSync(): void
213 { 213 {
214 $parameters = ['lf_url' => 'http://url.tld/other?part=3#hash']; 214 $parameters = ['lf_url' => 'http://url.tld/other?part=3#hash'];
215 215
@@ -224,7 +224,13 @@ class SaveBookmarkTest extends TestCase
224 224
225 $this->container->conf = $this->createMock(ConfigManager::class); 225 $this->container->conf = $this->createMock(ConfigManager::class);
226 $this->container->conf->method('get')->willReturnCallback(function (string $key, $default) { 226 $this->container->conf->method('get')->willReturnCallback(function (string $key, $default) {
227 return $key === 'thumbnails.mode' ? Thumbnailer::MODE_ALL : $default; 227 if ($key === 'thumbnails.mode') {
228 return Thumbnailer::MODE_ALL;
229 } elseif ($key === 'general.enable_async_metadata') {
230 return false;
231 }
232
233 return $default;
228 }); 234 });
229 235
230 $this->container->thumbnailer = $this->createMock(Thumbnailer::class); 236 $this->container->thumbnailer = $this->createMock(Thumbnailer::class);
@@ -275,6 +281,51 @@ class SaveBookmarkTest extends TestCase
275 } 281 }
276 282
277 /** 283 /**
284 * Test save a bookmark - do not attempt to retrieve thumbnails if async mode is enabled.
285 */
286 public function testSaveBookmarkWithThumbnailAsync(): void
287 {
288 $parameters = ['lf_url' => 'http://url.tld/other?part=3#hash'];
289
290 $request = $this->createMock(Request::class);
291 $request
292 ->method('getParam')
293 ->willReturnCallback(function (string $key) use ($parameters): ?string {
294 return $parameters[$key] ?? null;
295 })
296 ;
297 $response = new Response();
298
299 $this->container->conf = $this->createMock(ConfigManager::class);
300 $this->container->conf->method('get')->willReturnCallback(function (string $key, $default) {
301 if ($key === 'thumbnails.mode') {
302 return Thumbnailer::MODE_ALL;
303 } elseif ($key === 'general.enable_async_metadata') {
304 return true;
305 }
306
307 return $default;
308 });
309
310 $this->container->thumbnailer = $this->createMock(Thumbnailer::class);
311 $this->container->thumbnailer->expects(static::never())->method('get');
312
313 $this->container->bookmarkService
314 ->expects(static::once())
315 ->method('addOrSet')
316 ->willReturnCallback(function (Bookmark $bookmark): Bookmark {
317 static::assertNull($bookmark->getThumbnail());
318
319 return $bookmark;
320 })
321 ;
322
323 $result = $this->controller->save($request, $response);
324
325 static::assertSame(302, $result->getStatusCode());
326 }
327
328 /**
278 * Change the password with a wrong existing password 329 * Change the password with a wrong existing password
279 */ 330 */
280 public function testSaveBookmarkFromBookmarklet(): void 331 public function testSaveBookmarkFromBookmarklet(): void
diff --git a/tests/front/controller/visitor/BookmarkListControllerTest.php b/tests/front/controller/visitor/BookmarkListControllerTest.php
index 0c95df97..5ca92507 100644
--- a/tests/front/controller/visitor/BookmarkListControllerTest.php
+++ b/tests/front/controller/visitor/BookmarkListControllerTest.php
@@ -307,7 +307,13 @@ class BookmarkListControllerTest extends TestCase
307 $this->container->conf 307 $this->container->conf
308 ->method('get') 308 ->method('get')
309 ->willReturnCallback(function (string $key, $default) { 309 ->willReturnCallback(function (string $key, $default) {
310 return $key === 'thumbnails.mode' ? Thumbnailer::MODE_ALL : $default; 310 if ($key === 'thumbnails.mode') {
311 return Thumbnailer::MODE_ALL;
312 } elseif ($key === 'general.enable_async_metadata') {
313 return false;
314 }
315
316 return $default;
311 }) 317 })
312 ; 318 ;
313 319
@@ -357,7 +363,13 @@ class BookmarkListControllerTest extends TestCase
357 $this->container->conf 363 $this->container->conf
358 ->method('get') 364 ->method('get')
359 ->willReturnCallback(function (string $key, $default) { 365 ->willReturnCallback(function (string $key, $default) {
360 return $key === 'thumbnails.mode' ? Thumbnailer::MODE_ALL : $default; 366 if ($key === 'thumbnails.mode') {
367 return Thumbnailer::MODE_ALL;
368 } elseif ($key === 'general.enable_async_metadata') {
369 return false;
370 }
371
372 return $default;
361 }) 373 })
362 ; 374 ;
363 375
@@ -379,6 +391,47 @@ class BookmarkListControllerTest extends TestCase
379 } 391 }
380 392
381 /** 393 /**
394 * Test getting a permalink with thumbnail update with async setting: no update should run.
395 */
396 public function testThumbnailUpdateFromPermalinkAsync(): void
397 {
398 $request = $this->createMock(Request::class);
399 $response = new Response();
400
401 $this->container->loginManager = $this->createMock(LoginManager::class);
402 $this->container->loginManager->method('isLoggedIn')->willReturn(true);
403
404 $this->container->conf = $this->createMock(ConfigManager::class);
405 $this->container->conf
406 ->method('get')
407 ->willReturnCallback(function (string $key, $default) {
408 if ($key === 'thumbnails.mode') {
409 return Thumbnailer::MODE_ALL;
410 } elseif ($key === 'general.enable_async_metadata') {
411 return true;
412 }
413
414 return $default;
415 })
416 ;
417
418 $this->container->thumbnailer = $this->createMock(Thumbnailer::class);
419 $this->container->thumbnailer->expects(static::never())->method('get');
420
421 $this->container->bookmarkService
422 ->expects(static::once())
423 ->method('findByHash')
424 ->willReturn((new Bookmark())->setId(2)->setUrl('https://url.tld')->setTitle('Title 1'))
425 ;
426 $this->container->bookmarkService->expects(static::never())->method('set');
427 $this->container->bookmarkService->expects(static::never())->method('save');
428
429 $result = $this->controller->permalink($request, $response, ['hash' => 'abc']);
430
431 static::assertSame(200, $result->getStatusCode());
432 }
433
434 /**
382 * Trigger legacy controller in link list controller: permalink 435 * Trigger legacy controller in link list controller: permalink
383 */ 436 */
384 public function testLegacyControllerPermalink(): void 437 public function testLegacyControllerPermalink(): void