diff options
3 files changed, 55 insertions, 4 deletions
diff --git a/application/front/controller/admin/ShaareManageController.php b/application/front/controller/admin/ShaareManageController.php index 35837baa..9633cd51 100644 --- a/application/front/controller/admin/ShaareManageController.php +++ b/application/front/controller/admin/ShaareManageController.php | |||
@@ -66,6 +66,10 @@ class ShaareManageController extends ShaarliAdminController | |||
66 | return $response->write('<script>self.close();</script>'); | 66 | return $response->write('<script>self.close();</script>'); |
67 | } | 67 | } |
68 | 68 | ||
69 | if ($request->getParam('source') === 'batch') { | ||
70 | return $response->withStatus(204); | ||
71 | } | ||
72 | |||
69 | // Don't redirect to permalink after deletion. | 73 | // Don't redirect to permalink after deletion. |
70 | return $this->redirectFromReferer($request, $response, ['shaare/']); | 74 | return $this->redirectFromReferer($request, $response, ['shaare/']); |
71 | } | 75 | } |
diff --git a/assets/common/js/shaare-batch.js b/assets/common/js/shaare-batch.js index 557325ee..4a1fdb2e 100644 --- a/assets/common/js/shaare-batch.js +++ b/assets/common/js/shaare-batch.js | |||
@@ -4,7 +4,11 @@ const sendBookmarkForm = (basePath, formElement) => { | |||
4 | 4 | ||
5 | const formData = new FormData(); | 5 | const formData = new FormData(); |
6 | [...inputs].forEach((input) => { | 6 | [...inputs].forEach((input) => { |
7 | formData.append(input.getAttribute('name'), input.value); | 7 | if (input.getAttribute('type') === 'checkbox') { |
8 | formData.append(input.getAttribute('name'), input.checked); | ||
9 | } else { | ||
10 | formData.append(input.getAttribute('name'), input.value); | ||
11 | } | ||
8 | }); | 12 | }); |
9 | 13 | ||
10 | return new Promise((resolve, reject) => { | 14 | return new Promise((resolve, reject) => { |
@@ -26,9 +30,9 @@ const sendBookmarkForm = (basePath, formElement) => { | |||
26 | const sendBookmarkDelete = (buttonElement, formElement) => ( | 30 | const sendBookmarkDelete = (buttonElement, formElement) => ( |
27 | new Promise((resolve, reject) => { | 31 | new Promise((resolve, reject) => { |
28 | const xhr = new XMLHttpRequest(); | 32 | const xhr = new XMLHttpRequest(); |
29 | xhr.open('GET', buttonElement.href); | 33 | xhr.open('GET', `${buttonElement.href}&source=batch`); |
30 | xhr.onload = () => { | 34 | xhr.onload = () => { |
31 | if (xhr.status !== 200) { | 35 | if (xhr.status !== 204) { |
32 | alert(`An error occurred. Return code: ${xhr.status}`); | 36 | alert(`An error occurred. Return code: ${xhr.status}`); |
33 | reject(); | 37 | reject(); |
34 | } else { | 38 | } else { |
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 | } |