diff options
author | Loïc Carr <zizou.xena@gmail.com> | 2020-10-28 19:57:40 -0700 |
---|---|---|
committer | Loïc Carr <zizou.xena@gmail.com> | 2020-10-28 20:08:18 -0700 |
commit | b37ca790729125fa0df956220a4062f1d34c57e7 (patch) | |
tree | 15c758ef4acc7a6dff56a4cae28ce94fc0d3543e | |
parent | 78c2f122e067f8bab62deb7ef758708721f4a9ba (diff) | |
download | Shaarli-b37ca790729125fa0df956220a4062f1d34c57e7.tar.gz Shaarli-b37ca790729125fa0df956220a4062f1d34c57e7.tar.zst Shaarli-b37ca790729125fa0df956220a4062f1d34c57e7.zip |
postLink: change relative path to absolute path
-rw-r--r-- | application/api/controllers/Links.php | 2 | ||||
-rw-r--r-- | tests/api/controllers/links/PostLinkTest.php | 8 |
2 files changed, 5 insertions, 5 deletions
diff --git a/application/api/controllers/Links.php b/application/api/controllers/Links.php index 29247950..16fc8688 100644 --- a/application/api/controllers/Links.php +++ b/application/api/controllers/Links.php | |||
@@ -130,7 +130,7 @@ class Links extends ApiController | |||
130 | 130 | ||
131 | $this->bookmarkService->add($bookmark); | 131 | $this->bookmarkService->add($bookmark); |
132 | $out = ApiUtils::formatLink($bookmark, index_url($this->ci['environment'])); | 132 | $out = ApiUtils::formatLink($bookmark, index_url($this->ci['environment'])); |
133 | $redirect = $this->ci->router->relativePathFor('getLink', ['id' => $bookmark->getId()]); | 133 | $redirect = $this->ci->router->pathFor('getLink', ['id' => $bookmark->getId()]); |
134 | return $response->withAddedHeader('Location', $redirect) | 134 | return $response->withAddedHeader('Location', $redirect) |
135 | ->withJson($out, 201, $this->jsonStyle); | 135 | ->withJson($out, 201, $this->jsonStyle); |
136 | } | 136 | } |
diff --git a/tests/api/controllers/links/PostLinkTest.php b/tests/api/controllers/links/PostLinkTest.php index b2dd09eb..969b9fd9 100644 --- a/tests/api/controllers/links/PostLinkTest.php +++ b/tests/api/controllers/links/PostLinkTest.php | |||
@@ -90,8 +90,8 @@ class PostLinkTest extends TestCase | |||
90 | 90 | ||
91 | $mock = $this->createMock(Router::class); | 91 | $mock = $this->createMock(Router::class); |
92 | $mock->expects($this->any()) | 92 | $mock->expects($this->any()) |
93 | ->method('relativePathFor') | 93 | ->method('pathFor') |
94 | ->willReturn('api/v1/bookmarks/1'); | 94 | ->willReturn('/api/v1/bookmarks/1'); |
95 | 95 | ||
96 | // affect @property-read... seems to work | 96 | // affect @property-read... seems to work |
97 | $this->controller->getCi()->router = $mock; | 97 | $this->controller->getCi()->router = $mock; |
@@ -126,7 +126,7 @@ class PostLinkTest extends TestCase | |||
126 | 126 | ||
127 | $response = $this->controller->postLink($request, new Response()); | 127 | $response = $this->controller->postLink($request, new Response()); |
128 | $this->assertEquals(201, $response->getStatusCode()); | 128 | $this->assertEquals(201, $response->getStatusCode()); |
129 | $this->assertEquals('api/v1/bookmarks/1', $response->getHeader('Location')[0]); | 129 | $this->assertEquals('/api/v1/bookmarks/1', $response->getHeader('Location')[0]); |
130 | $data = json_decode((string) $response->getBody(), true); | 130 | $data = json_decode((string) $response->getBody(), true); |
131 | $this->assertEquals(self::NB_FIELDS_LINK, count($data)); | 131 | $this->assertEquals(self::NB_FIELDS_LINK, count($data)); |
132 | $this->assertEquals(43, $data['id']); | 132 | $this->assertEquals(43, $data['id']); |
@@ -171,7 +171,7 @@ class PostLinkTest extends TestCase | |||
171 | $response = $this->controller->postLink($request, new Response()); | 171 | $response = $this->controller->postLink($request, new Response()); |
172 | 172 | ||
173 | $this->assertEquals(201, $response->getStatusCode()); | 173 | $this->assertEquals(201, $response->getStatusCode()); |
174 | $this->assertEquals('api/v1/bookmarks/1', $response->getHeader('Location')[0]); | 174 | $this->assertEquals('/api/v1/bookmarks/1', $response->getHeader('Location')[0]); |
175 | $data = json_decode((string) $response->getBody(), true); | 175 | $data = json_decode((string) $response->getBody(), true); |
176 | $this->assertEquals(self::NB_FIELDS_LINK, count($data)); | 176 | $this->assertEquals(self::NB_FIELDS_LINK, count($data)); |
177 | $this->assertEquals(43, $data['id']); | 177 | $this->assertEquals(43, $data['id']); |