aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2021-01-19 12:44:48 +0100
committerArthurHoaro <arthur@hoa.ro>2021-01-19 12:54:34 +0100
commit93175b6e9d5cfa4d4319bd58b9de01824d596288 (patch)
treea09a4d05273d5d615508cc469b8155f6fcebd4b7 /tests
parentffa39719a17982e6a6cac9bc3f758aa12fa69973 (diff)
downloadShaarli-93175b6e9d5cfa4d4319bd58b9de01824d596288.tar.gz
Shaarli-93175b6e9d5cfa4d4319bd58b9de01824d596288.tar.zst
Shaarli-93175b6e9d5cfa4d4319bd58b9de01824d596288.zip
Fix: bulk add - delete existing link
Do not send redirect response in bookmark delete controller if the request comes from bulk creation page. Fixes #1683
Diffstat (limited to 'tests')
-rw-r--r--tests/front/controller/admin/ShaareManageControllerTest/DeleteBookmarkTest.php45
1 files changed, 44 insertions, 1 deletions
diff --git a/tests/front/controller/admin/ShaareManageControllerTest/DeleteBookmarkTest.php b/tests/front/controller/admin/ShaareManageControllerTest/DeleteBookmarkTest.php
index a276d988..42d0c0d6 100644
--- a/tests/front/controller/admin/ShaareManageControllerTest/DeleteBookmarkTest.php
+++ b/tests/front/controller/admin/ShaareManageControllerTest/DeleteBookmarkTest.php
@@ -363,6 +363,7 @@ class DeleteBookmarkTest extends TestCase
363 $this->container->bookmarkService->method('get')->with('123')->willReturn( 363 $this->container->bookmarkService->method('get')->with('123')->willReturn(
364 (new Bookmark())->setId(123)->setUrl('http://domain.tld')->setTitle('Title 123') 364 (new Bookmark())->setId(123)->setUrl('http://domain.tld')->setTitle('Title 123')
365 ); 365 );
366 $this->container->bookmarkService->expects(static::once())->method('remove');
366 367
367 $this->container->formatterFactory = $this->createMock(FormatterFactory::class); 368 $this->container->formatterFactory = $this->createMock(FormatterFactory::class);
368 $this->container->formatterFactory 369 $this->container->formatterFactory
@@ -379,6 +380,48 @@ class DeleteBookmarkTest extends TestCase
379 $result = $this->controller->deleteBookmark($request, $response); 380 $result = $this->controller->deleteBookmark($request, $response);
380 381
381 static::assertSame(200, $result->getStatusCode()); 382 static::assertSame(200, $result->getStatusCode());
382 static::assertSame('<script>self.close();</script>', (string) $result->getBody('location')); 383 static::assertSame('<script>self.close();</script>', (string) $result->getBody());
384 }
385
386 /**
387 * Delete bookmark - from batch view
388 */
389 public function testDeleteBookmarkFromBatch(): void
390 {
391 $parameters = [
392 'id' => '123',
393 'source' => 'batch',
394 ];
395
396 $request = $this->createMock(Request::class);
397 $request
398 ->method('getParam')
399 ->willReturnCallback(function (string $key) use ($parameters): ?string {
400 return $parameters[$key] ?? null;
401 })
402 ;
403 $response = new Response();
404
405 $this->container->bookmarkService->method('get')->with('123')->willReturn(
406 (new Bookmark())->setId(123)->setUrl('http://domain.tld')->setTitle('Title 123')
407 );
408 $this->container->bookmarkService->expects(static::once())->method('remove');
409
410 $this->container->formatterFactory = $this->createMock(FormatterFactory::class);
411 $this->container->formatterFactory
412 ->expects(static::once())
413 ->method('getFormatter')
414 ->willReturnCallback(function (): BookmarkFormatter {
415 $formatter = $this->createMock(BookmarkFormatter::class);
416 $formatter->method('format')->willReturn(['formatted']);
417
418 return $formatter;
419 })
420 ;
421
422 $result = $this->controller->deleteBookmark($request, $response);
423
424 static::assertSame(204, $result->getStatusCode());
425 static::assertEmpty((string) $result->getBody());
383 } 426 }
384} 427}