diff options
author | yude <yudesleepy@gmail.com> | 2021-01-04 18:51:10 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-04 18:51:10 +0900 |
commit | e6754f2154a79abd8e5e64bd923f6984aa9ad44b (patch) | |
tree | f074119530bb59ef155938ea367f719f1e4b70f1 /tests/api/controllers | |
parent | 5256b4287021342a9f8868967b2a77e481314331 (diff) | |
parent | ed4ee8f0297941ac83300389b7de6a293312d20e (diff) | |
download | Shaarli-e6754f2154a79abd8e5e64bd923f6984aa9ad44b.tar.gz Shaarli-e6754f2154a79abd8e5e64bd923f6984aa9ad44b.tar.zst Shaarli-e6754f2154a79abd8e5e64bd923f6984aa9ad44b.zip |
Merge pull request #2 from shaarli/master
Merge fork source
Diffstat (limited to 'tests/api/controllers')
-rw-r--r-- | tests/api/controllers/links/PostLinkTest.php | 56 | ||||
-rw-r--r-- | tests/api/controllers/links/PutLinkTest.php | 48 |
2 files changed, 100 insertions, 4 deletions
diff --git a/tests/api/controllers/links/PostLinkTest.php b/tests/api/controllers/links/PostLinkTest.php index 7ff92f5c..f755e2d2 100644 --- a/tests/api/controllers/links/PostLinkTest.php +++ b/tests/api/controllers/links/PostLinkTest.php | |||
@@ -92,8 +92,8 @@ class PostLinkTest extends TestCase | |||
92 | 92 | ||
93 | $mock = $this->createMock(Router::class); | 93 | $mock = $this->createMock(Router::class); |
94 | $mock->expects($this->any()) | 94 | $mock->expects($this->any()) |
95 | ->method('relativePathFor') | 95 | ->method('pathFor') |
96 | ->willReturn('api/v1/bookmarks/1'); | 96 | ->willReturn('/api/v1/bookmarks/1'); |
97 | 97 | ||
98 | // affect @property-read... seems to work | 98 | // affect @property-read... seems to work |
99 | $this->controller->getCi()->router = $mock; | 99 | $this->controller->getCi()->router = $mock; |
@@ -128,7 +128,7 @@ class PostLinkTest extends TestCase | |||
128 | 128 | ||
129 | $response = $this->controller->postLink($request, new Response()); | 129 | $response = $this->controller->postLink($request, new Response()); |
130 | $this->assertEquals(201, $response->getStatusCode()); | 130 | $this->assertEquals(201, $response->getStatusCode()); |
131 | $this->assertEquals('api/v1/bookmarks/1', $response->getHeader('Location')[0]); | 131 | $this->assertEquals('/api/v1/bookmarks/1', $response->getHeader('Location')[0]); |
132 | $data = json_decode((string) $response->getBody(), true); | 132 | $data = json_decode((string) $response->getBody(), true); |
133 | $this->assertEquals(self::NB_FIELDS_LINK, count($data)); | 133 | $this->assertEquals(self::NB_FIELDS_LINK, count($data)); |
134 | $this->assertEquals(43, $data['id']); | 134 | $this->assertEquals(43, $data['id']); |
@@ -175,7 +175,7 @@ class PostLinkTest extends TestCase | |||
175 | $response = $this->controller->postLink($request, new Response()); | 175 | $response = $this->controller->postLink($request, new Response()); |
176 | 176 | ||
177 | $this->assertEquals(201, $response->getStatusCode()); | 177 | $this->assertEquals(201, $response->getStatusCode()); |
178 | $this->assertEquals('api/v1/bookmarks/1', $response->getHeader('Location')[0]); | 178 | $this->assertEquals('/api/v1/bookmarks/1', $response->getHeader('Location')[0]); |
179 | $data = json_decode((string) $response->getBody(), true); | 179 | $data = json_decode((string) $response->getBody(), true); |
180 | $this->assertEquals(self::NB_FIELDS_LINK, count($data)); | 180 | $this->assertEquals(self::NB_FIELDS_LINK, count($data)); |
181 | $this->assertEquals(43, $data['id']); | 181 | $this->assertEquals(43, $data['id']); |
@@ -229,4 +229,52 @@ class PostLinkTest extends TestCase | |||
229 | \DateTime::createFromFormat(\DateTime::ATOM, $data['updated']) | 229 | \DateTime::createFromFormat(\DateTime::ATOM, $data['updated']) |
230 | ); | 230 | ); |
231 | } | 231 | } |
232 | |||
233 | /** | ||
234 | * Test link creation with a tag string provided | ||
235 | */ | ||
236 | public function testPostLinkWithTagString(): void | ||
237 | { | ||
238 | $link = [ | ||
239 | 'tags' => 'one two', | ||
240 | ]; | ||
241 | $env = Environment::mock([ | ||
242 | 'REQUEST_METHOD' => 'POST', | ||
243 | 'CONTENT_TYPE' => 'application/json' | ||
244 | ]); | ||
245 | |||
246 | $request = Request::createFromEnvironment($env); | ||
247 | $request = $request->withParsedBody($link); | ||
248 | $response = $this->controller->postLink($request, new Response()); | ||
249 | |||
250 | $this->assertEquals(201, $response->getStatusCode()); | ||
251 | $this->assertEquals('/api/v1/bookmarks/1', $response->getHeader('Location')[0]); | ||
252 | $data = json_decode((string) $response->getBody(), true); | ||
253 | $this->assertEquals(self::NB_FIELDS_LINK, count($data)); | ||
254 | $this->assertEquals(['one', 'two'], $data['tags']); | ||
255 | } | ||
256 | |||
257 | /** | ||
258 | * Test link creation with a tag string provided | ||
259 | */ | ||
260 | public function testPostLinkWithTagString2(): void | ||
261 | { | ||
262 | $link = [ | ||
263 | 'tags' => ['one two'], | ||
264 | ]; | ||
265 | $env = Environment::mock([ | ||
266 | 'REQUEST_METHOD' => 'POST', | ||
267 | 'CONTENT_TYPE' => 'application/json' | ||
268 | ]); | ||
269 | |||
270 | $request = Request::createFromEnvironment($env); | ||
271 | $request = $request->withParsedBody($link); | ||
272 | $response = $this->controller->postLink($request, new Response()); | ||
273 | |||
274 | $this->assertEquals(201, $response->getStatusCode()); | ||
275 | $this->assertEquals('/api/v1/bookmarks/1', $response->getHeader('Location')[0]); | ||
276 | $data = json_decode((string) $response->getBody(), true); | ||
277 | $this->assertEquals(self::NB_FIELDS_LINK, count($data)); | ||
278 | $this->assertEquals(['one', 'two'], $data['tags']); | ||
279 | } | ||
232 | } | 280 | } |
diff --git a/tests/api/controllers/links/PutLinkTest.php b/tests/api/controllers/links/PutLinkTest.php index 240ee323..fe24f2eb 100644 --- a/tests/api/controllers/links/PutLinkTest.php +++ b/tests/api/controllers/links/PutLinkTest.php | |||
@@ -233,4 +233,52 @@ class PutLinkTest extends \Shaarli\TestCase | |||
233 | 233 | ||
234 | $this->controller->putLink($request, new Response(), ['id' => -1]); | 234 | $this->controller->putLink($request, new Response(), ['id' => -1]); |
235 | } | 235 | } |
236 | |||
237 | /** | ||
238 | * Test link creation with a tag string provided | ||
239 | */ | ||
240 | public function testPutLinkWithTagString(): void | ||
241 | { | ||
242 | $link = [ | ||
243 | 'tags' => 'one two', | ||
244 | ]; | ||
245 | $id = '41'; | ||
246 | $env = Environment::mock([ | ||
247 | 'REQUEST_METHOD' => 'PUT', | ||
248 | 'CONTENT_TYPE' => 'application/json' | ||
249 | ]); | ||
250 | |||
251 | $request = Request::createFromEnvironment($env); | ||
252 | $request = $request->withParsedBody($link); | ||
253 | $response = $this->controller->putLink($request, new Response(), ['id' => $id]); | ||
254 | |||
255 | $this->assertEquals(200, $response->getStatusCode()); | ||
256 | $data = json_decode((string) $response->getBody(), true); | ||
257 | $this->assertEquals(self::NB_FIELDS_LINK, count($data)); | ||
258 | $this->assertEquals(['one', 'two'], $data['tags']); | ||
259 | } | ||
260 | |||
261 | /** | ||
262 | * Test link creation with a tag string provided | ||
263 | */ | ||
264 | public function testPutLinkWithTagString2(): void | ||
265 | { | ||
266 | $link = [ | ||
267 | 'tags' => ['one two'], | ||
268 | ]; | ||
269 | $id = '41'; | ||
270 | $env = Environment::mock([ | ||
271 | 'REQUEST_METHOD' => 'PUT', | ||
272 | 'CONTENT_TYPE' => 'application/json' | ||
273 | ]); | ||
274 | |||
275 | $request = Request::createFromEnvironment($env); | ||
276 | $request = $request->withParsedBody($link); | ||
277 | $response = $this->controller->putLink($request, new Response(), ['id' => $id]); | ||
278 | |||
279 | $this->assertEquals(200, $response->getStatusCode()); | ||
280 | $data = json_decode((string) $response->getBody(), true); | ||
281 | $this->assertEquals(self::NB_FIELDS_LINK, count($data)); | ||
282 | $this->assertEquals(['one', 'two'], $data['tags']); | ||
283 | } | ||
236 | } | 284 | } |