]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
postLink: change relative path to absolute path 1616/head
authorLoïc Carr <zizou.xena@gmail.com>
Thu, 29 Oct 2020 02:57:40 +0000 (19:57 -0700)
committerLoïc Carr <zizou.xena@gmail.com>
Thu, 29 Oct 2020 03:08:18 +0000 (20:08 -0700)
application/api/controllers/Links.php
tests/api/controllers/links/PostLinkTest.php

index 2924795012d4c1cd037a008ecfd9f6fdb091ad49..16fc8688887e44af1d4c6c07e8f17f12f12182d4 100644 (file)
@@ -130,7 +130,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 b2dd09eb0e780d3e8d80cdde82ae848e8d50e8b2..969b9fd9a3cbbb1a51fa0297294eaffa4dabf80e 100644 (file)
@@ -90,8 +90,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;
@@ -126,7 +126,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']);
@@ -171,7 +171,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']);