]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Merge pull request #1616 from dimtion/fix-api-redirect
authorArthurHoaro <arthur@hoa.ro>
Thu, 29 Oct 2020 15:03:07 +0000 (16:03 +0100)
committerGitHub <noreply@github.com>
Thu, 29 Oct 2020 15:03:07 +0000 (16:03 +0100)
API postLink: change relative path to absolute path

application/api/controllers/Links.php
tests/api/controllers/links/PostLinkTest.php

index 73a1b84e1727e1a4567e53ec9db6fe1299ce2b39..6bf529e4a570a3ff5f789f2de34045946205cd67 100644 (file)
@@ -131,7 +131,7 @@ class Links extends ApiController
 
         $this->bookmarkService->add($bookmark);
         $out = ApiUtils::formatLink($bookmark, index_url($this->ci['environment']));
-        $redirect = $this->ci->router->relativePathFor('getLink', ['id' => $bookmark->getId()]);
+        $redirect = $this->ci->router->pathFor('getLink', ['id' => $bookmark->getId()]);
         return $response->withAddedHeader('Location', $redirect)
                         ->withJson($out, 201, $this->jsonStyle);
     }
index 7ff92f5c96968c6e12c75098dc164526c0a3224d..e12f803be3ce99004294b926e4e14dd7b98f0ba1 100644 (file)
@@ -92,8 +92,8 @@ class PostLinkTest extends TestCase
 
         $mock = $this->createMock(Router::class);
         $mock->expects($this->any())
-             ->method('relativePathFor')
-             ->willReturn('api/v1/bookmarks/1');
+             ->method('pathFor')
+             ->willReturn('/api/v1/bookmarks/1');
 
         // affect @property-read... seems to work
         $this->controller->getCi()->router = $mock;
@@ -128,7 +128,7 @@ class PostLinkTest extends TestCase
 
         $response = $this->controller->postLink($request, new Response());
         $this->assertEquals(201, $response->getStatusCode());
-        $this->assertEquals('api/v1/bookmarks/1', $response->getHeader('Location')[0]);
+        $this->assertEquals('/api/v1/bookmarks/1', $response->getHeader('Location')[0]);
         $data = json_decode((string) $response->getBody(), true);
         $this->assertEquals(self::NB_FIELDS_LINK, count($data));
         $this->assertEquals(43, $data['id']);
@@ -175,7 +175,7 @@ class PostLinkTest extends TestCase
         $response = $this->controller->postLink($request, new Response());
 
         $this->assertEquals(201, $response->getStatusCode());
-        $this->assertEquals('api/v1/bookmarks/1', $response->getHeader('Location')[0]);
+        $this->assertEquals('/api/v1/bookmarks/1', $response->getHeader('Location')[0]);
         $data = json_decode((string) $response->getBody(), true);
         $this->assertEquals(self::NB_FIELDS_LINK, count($data));
         $this->assertEquals(43, $data['id']);