diff options
author | ArthurHoaro <arthur@hoa.ro> | 2017-05-07 15:55:38 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-07 15:55:38 +0200 |
commit | 77de24876ff542e3770aa2845e993c58f87e37df (patch) | |
tree | 9eca13b3718eeba2d69fe262a8b6b35ba2596ea5 /tests/api/ApiUtilsTest.php | |
parent | eb6e729808e1c3d9787ad1183aa61ab2e375a537 (diff) | |
parent | cf9181dddf8b6113b1b017e4bcb21fac0a0b1c83 (diff) | |
download | Shaarli-77de24876ff542e3770aa2845e993c58f87e37df.tar.gz Shaarli-77de24876ff542e3770aa2845e993c58f87e37df.tar.zst Shaarli-77de24876ff542e3770aa2845e993c58f87e37df.zip |
Merge pull request #840 from ArthurHoaro/api/putLink
REST API: implement PUT method
Diffstat (limited to 'tests/api/ApiUtilsTest.php')
-rw-r--r-- | tests/api/ApiUtilsTest.php | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/tests/api/ApiUtilsTest.php b/tests/api/ApiUtilsTest.php index b4431d1b..62baf4c5 100644 --- a/tests/api/ApiUtilsTest.php +++ b/tests/api/ApiUtilsTest.php | |||
@@ -271,4 +271,82 @@ class ApiUtilsTest extends \PHPUnit_Framework_TestCase | |||
271 | 271 | ||
272 | $this->assertEquals($expected, ApiUtils::formatLink($link, $indexUrl)); | 272 | $this->assertEquals($expected, ApiUtils::formatLink($link, $indexUrl)); |
273 | } | 273 | } |
274 | |||
275 | /** | ||
276 | * Test updateLink with valid data, and also unnecessary fields. | ||
277 | */ | ||
278 | public function testUpdateLink() | ||
279 | { | ||
280 | $created = \DateTime::createFromFormat('Ymd_His', '20170107_160102'); | ||
281 | $old = [ | ||
282 | 'id' => 12, | ||
283 | 'url' => '?abc', | ||
284 | 'shorturl' => 'abc', | ||
285 | 'title' => 'Note', | ||
286 | 'description' => '', | ||
287 | 'tags' => '', | ||
288 | 'private' => '', | ||
289 | 'created' => $created, | ||
290 | ]; | ||
291 | |||
292 | $new = [ | ||
293 | 'id' => 13, | ||
294 | 'shorturl' => 'nope', | ||
295 | 'url' => 'http://somewhere.else', | ||
296 | 'title' => 'Le Cid', | ||
297 | 'description' => 'Percé jusques au fond du cœur [...]', | ||
298 | 'tags' => 'corneille rodrigue', | ||
299 | 'private' => true, | ||
300 | 'created' => 'creation', | ||
301 | 'updated' => 'updation', | ||
302 | ]; | ||
303 | |||
304 | $result = ApiUtils::updateLink($old, $new); | ||
305 | $this->assertEquals(12, $result['id']); | ||
306 | $this->assertEquals('http://somewhere.else', $result['url']); | ||
307 | $this->assertEquals('abc', $result['shorturl']); | ||
308 | $this->assertEquals('Le Cid', $result['title']); | ||
309 | $this->assertEquals('Percé jusques au fond du cœur [...]', $result['description']); | ||
310 | $this->assertEquals('corneille rodrigue', $result['tags']); | ||
311 | $this->assertEquals(true, $result['private']); | ||
312 | $this->assertEquals($created, $result['created']); | ||
313 | $this->assertTrue(new \DateTime('5 seconds ago') < $result['updated']); | ||
314 | } | ||
315 | |||
316 | /** | ||
317 | * Test updateLink with minimal data. | ||
318 | */ | ||
319 | public function testUpdateLinkMinimal() | ||
320 | { | ||
321 | $created = \DateTime::createFromFormat('Ymd_His', '20170107_160102'); | ||
322 | $old = [ | ||
323 | 'id' => 12, | ||
324 | 'url' => '?abc', | ||
325 | 'shorturl' => 'abc', | ||
326 | 'title' => 'Note', | ||
327 | 'description' => 'Interesting description!', | ||
328 | 'tags' => 'doggo', | ||
329 | 'private' => true, | ||
330 | 'created' => $created, | ||
331 | ]; | ||
332 | |||
333 | $new = [ | ||
334 | 'url' => '', | ||
335 | 'title' => '', | ||
336 | 'description' => '', | ||
337 | 'tags' => '', | ||
338 | 'private' => false, | ||
339 | ]; | ||
340 | |||
341 | $result = ApiUtils::updateLink($old, $new); | ||
342 | $this->assertEquals(12, $result['id']); | ||
343 | $this->assertEquals('?abc', $result['url']); | ||
344 | $this->assertEquals('abc', $result['shorturl']); | ||
345 | $this->assertEquals('?abc', $result['title']); | ||
346 | $this->assertEquals('', $result['description']); | ||
347 | $this->assertEquals('', $result['tags']); | ||
348 | $this->assertEquals(false, $result['private']); | ||
349 | $this->assertEquals($created, $result['created']); | ||
350 | $this->assertTrue(new \DateTime('5 seconds ago') < $result['updated']); | ||
351 | } | ||
274 | } | 352 | } |