aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/api/controllers/links/PutLinkTest.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-12-29 12:50:23 +0100
committerArthurHoaro <arthur@hoa.ro>2020-12-29 13:01:04 +0100
commit0640c1a6db6d9a13e5d0079f0bf42497010edbc7 (patch)
tree17002fc6a277d21f728f103434bd8a70561affa5 /tests/api/controllers/links/PutLinkTest.php
parentfe58bdcd9e0ddca8a2a99142dc9eaee8845efa67 (diff)
downloadShaarli-0640c1a6db6d9a13e5d0079f0bf42497010edbc7.tar.gz
Shaarli-0640c1a6db6d9a13e5d0079f0bf42497010edbc7.tar.zst
Shaarli-0640c1a6db6d9a13e5d0079f0bf42497010edbc7.zip
API: POST/PUT Link - properly parse tags string
Even though the documentation specify that tags should be passed as an array, tags string is actually allowed. So this adds a proper parsing with configured separator. Related to #1651
Diffstat (limited to 'tests/api/controllers/links/PutLinkTest.php')
-rw-r--r--tests/api/controllers/links/PutLinkTest.php48
1 files changed, 48 insertions, 0 deletions
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}