]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Fix a bug preventing to edit bookmark with ID #0 1577/head
authorArthurHoaro <arthur@hoa.ro>
Wed, 30 Sep 2020 13:31:34 +0000 (15:31 +0200)
committerArthurHoaro <arthur@hoa.ro>
Wed, 30 Sep 2020 13:31:34 +0000 (15:31 +0200)
application/front/controller/admin/ManageShaareController.php
tests/front/controller/admin/ManageShaareControllerTest/SaveBookmarkTest.php

index ffb0dae430ca69ec2929b14a323add0f554d562e..59ba2de9547b3abf09ee55f0880d489b35f2c1cf 100644 (file)
@@ -127,7 +127,7 @@ class ManageShaareController extends ShaarliAdminController
         $this->checkToken($request);
 
         // lf_id should only be present if the link exists.
-        $id = $request->getParam('lf_id') ? intval(escape($request->getParam('lf_id'))) : null;
+        $id = $request->getParam('lf_id') !== null ? intval(escape($request->getParam('lf_id'))) : null;
         if (null !== $id && true === $this->container->bookmarkService->exists($id)) {
             // Edit
             $bookmark = $this->container->bookmarkService->get($id);
index 58eaaa9b6816fdb67cd4c0f2ed8407a509ab3364..a5e2dbc56c959bda171cd5677e2adbaadb97d409 100644 (file)
@@ -238,6 +238,30 @@ class SaveBookmarkTest extends TestCase
         static::assertSame(302, $result->getStatusCode());
     }
 
+    /**
+     * Test save a bookmark - with ID #0
+     */
+    public function testSaveBookmarkWithIdZero(): void
+    {
+        $parameters = ['lf_id' => '0'];
+
+        $request = $this->createMock(Request::class);
+        $request
+            ->method('getParam')
+            ->willReturnCallback(function (string $key) use ($parameters): ?string {
+                return $parameters[$key] ?? null;
+            })
+        ;
+        $response = new Response();
+
+        $this->container->bookmarkService->expects(static::once())->method('exists')->with(0)->willReturn(true);
+        $this->container->bookmarkService->expects(static::once())->method('get')->with(0)->willReturn(new Bookmark());
+
+        $result = $this->controller->save($request, $response);
+
+        static::assertSame(302, $result->getStatusCode());
+    }
+
     /**
      * Change the password with a wrong existing password
      */