aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-10-02 14:24:07 +0200
committerGitHub <noreply@github.com>2020-10-02 14:24:07 +0200
commit1db2ebbd79bb82e9e40a7093bbf1bfc50d06b077 (patch)
tree4a4a525faf76f9bed412d7ad25a28c54af82b750
parent95158e7565b8f091e0781d30ef48d369c42e37c7 (diff)
parent80a3efe11677b1420a7bc45d9b623c2df24cdd79 (diff)
downloadShaarli-1db2ebbd79bb82e9e40a7093bbf1bfc50d06b077.tar.gz
Shaarli-1db2ebbd79bb82e9e40a7093bbf1bfc50d06b077.tar.zst
Shaarli-1db2ebbd79bb82e9e40a7093bbf1bfc50d06b077.zip
Merge pull request #1577 from ArthurHoaro/fix/edit-zero
Fix a bug preventing to edit bookmark with ID #0
-rw-r--r--application/front/controller/admin/ManageShaareController.php2
-rw-r--r--tests/front/controller/admin/ManageShaareControllerTest/SaveBookmarkTest.php24
2 files changed, 25 insertions, 1 deletions
diff --git a/application/front/controller/admin/ManageShaareController.php b/application/front/controller/admin/ManageShaareController.php
index ffb0dae4..59ba2de9 100644
--- a/application/front/controller/admin/ManageShaareController.php
+++ b/application/front/controller/admin/ManageShaareController.php
@@ -127,7 +127,7 @@ class ManageShaareController extends ShaarliAdminController
127 $this->checkToken($request); 127 $this->checkToken($request);
128 128
129 // lf_id should only be present if the link exists. 129 // lf_id should only be present if the link exists.
130 $id = $request->getParam('lf_id') ? intval(escape($request->getParam('lf_id'))) : null; 130 $id = $request->getParam('lf_id') !== null ? intval(escape($request->getParam('lf_id'))) : null;
131 if (null !== $id && true === $this->container->bookmarkService->exists($id)) { 131 if (null !== $id && true === $this->container->bookmarkService->exists($id)) {
132 // Edit 132 // Edit
133 $bookmark = $this->container->bookmarkService->get($id); 133 $bookmark = $this->container->bookmarkService->get($id);
diff --git a/tests/front/controller/admin/ManageShaareControllerTest/SaveBookmarkTest.php b/tests/front/controller/admin/ManageShaareControllerTest/SaveBookmarkTest.php
index 58eaaa9b..a5e2dbc5 100644
--- a/tests/front/controller/admin/ManageShaareControllerTest/SaveBookmarkTest.php
+++ b/tests/front/controller/admin/ManageShaareControllerTest/SaveBookmarkTest.php
@@ -239,6 +239,30 @@ class SaveBookmarkTest extends TestCase
239 } 239 }
240 240
241 /** 241 /**
242 * Test save a bookmark - with ID #0
243 */
244 public function testSaveBookmarkWithIdZero(): void
245 {
246 $parameters = ['lf_id' => '0'];
247
248 $request = $this->createMock(Request::class);
249 $request
250 ->method('getParam')
251 ->willReturnCallback(function (string $key) use ($parameters): ?string {
252 return $parameters[$key] ?? null;
253 })
254 ;
255 $response = new Response();
256
257 $this->container->bookmarkService->expects(static::once())->method('exists')->with(0)->willReturn(true);
258 $this->container->bookmarkService->expects(static::once())->method('get')->with(0)->willReturn(new Bookmark());
259
260 $result = $this->controller->save($request, $response);
261
262 static::assertSame(302, $result->getStatusCode());
263 }
264
265 /**
242 * Change the password with a wrong existing password 266 * Change the password with a wrong existing password
243 */ 267 */
244 public function testSaveBookmarkFromBookmarklet(): void 268 public function testSaveBookmarkFromBookmarklet(): void