diff options
author | Jeremy Benoist <jeremy.benoist@gmail.com> | 2017-06-30 16:54:26 +0200 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2017-07-03 13:45:04 +0200 |
commit | a05b61159e147776f63baee731b5026796e5f7ae (patch) | |
tree | 80dae1ea169f3fb072a7aa2072f24507e10e91ed /tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | |
parent | 71e1cbc8eb5928d393b0772055d6b711e90a09b3 (diff) | |
download | wallabag-a05b61159e147776f63baee731b5026796e5f7ae.tar.gz wallabag-a05b61159e147776f63baee731b5026796e5f7ae.tar.zst wallabag-a05b61159e147776f63baee731b5026796e5f7ae.zip |
Fix PATCH method
The PATCH method for the entry should only update what user sent to us and not the whole entry as it was before.
Also, sending tags when patching an entry will now remove all current tags & assocatied new ones.
Diffstat (limited to 'tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php')
-rw-r--r-- | tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | 68 |
1 files changed, 58 insertions, 10 deletions
diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index ae4af4cd..0647bb23 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | |||
@@ -519,10 +519,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
519 | $this->markTestSkipped('No content found in db.'); | 519 | $this->markTestSkipped('No content found in db.'); |
520 | } | 520 | } |
521 | 521 | ||
522 | // hydrate the tags relations | 522 | $this->client->request('PATCH', '/api/entries/'.$entry->getId().'.json', [ |
523 | $nbTags = count($entry->getTags()); | ||
524 | |||
525 | $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [ | ||
526 | 'title' => 'New awesome title', | 523 | 'title' => 'New awesome title', |
527 | 'tags' => 'new tag ' . uniqid(), | 524 | 'tags' => 'new tag ' . uniqid(), |
528 | 'starred' => '1', | 525 | 'starred' => '1', |
@@ -532,6 +529,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
532 | 'authors' => 'bob,sponge', | 529 | 'authors' => 'bob,sponge', |
533 | 'content' => 'awesome', | 530 | 'content' => 'awesome', |
534 | 'public' => 0, | 531 | 'public' => 0, |
532 | 'published_at' => 1488833381, | ||
535 | ]); | 533 | ]); |
536 | 534 | ||
537 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); | 535 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); |
@@ -541,7 +539,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
541 | $this->assertSame($entry->getId(), $content['id']); | 539 | $this->assertSame($entry->getId(), $content['id']); |
542 | $this->assertSame($entry->getUrl(), $content['url']); | 540 | $this->assertSame($entry->getUrl(), $content['url']); |
543 | $this->assertSame('New awesome title', $content['title']); | 541 | $this->assertSame('New awesome title', $content['title']); |
544 | $this->assertGreaterThan($nbTags, count($content['tags'])); | 542 | $this->assertGreaterThanOrEqual(1, count($content['tags']), 'We force only one tag'); |
545 | $this->assertSame(1, $content['user_id']); | 543 | $this->assertSame(1, $content['user_id']); |
546 | $this->assertSame('de_AT', $content['language']); | 544 | $this->assertSame('de_AT', $content['language']); |
547 | $this->assertSame('http://preview.io/picture.jpg', $content['preview_picture']); | 545 | $this->assertSame('http://preview.io/picture.jpg', $content['preview_picture']); |
@@ -549,6 +547,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
549 | $this->assertContains('bob', $content['published_by']); | 547 | $this->assertContains('bob', $content['published_by']); |
550 | $this->assertSame('awesome', $content['content']); | 548 | $this->assertSame('awesome', $content['content']); |
551 | $this->assertFalse($content['is_public'], 'Entry is no more shared'); | 549 | $this->assertFalse($content['is_public'], 'Entry is no more shared'); |
550 | $this->assertContains('2017-03-06', $content['published_at']); | ||
552 | } | 551 | } |
553 | 552 | ||
554 | public function testPatchEntryWithoutQuotes() | 553 | public function testPatchEntryWithoutQuotes() |
@@ -562,8 +561,8 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
562 | $this->markTestSkipped('No content found in db.'); | 561 | $this->markTestSkipped('No content found in db.'); |
563 | } | 562 | } |
564 | 563 | ||
565 | // hydrate the tags relations | 564 | $previousContent = $entry->getContent(); |
566 | $nbTags = count($entry->getTags()); | 565 | $previousLanguage = $entry->getLanguage(); |
567 | 566 | ||
568 | $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [ | 567 | $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [ |
569 | 'title' => 'New awesome title', | 568 | 'title' => 'New awesome title', |
@@ -579,9 +578,11 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
579 | 578 | ||
580 | $this->assertSame($entry->getId(), $content['id']); | 579 | $this->assertSame($entry->getId(), $content['id']); |
581 | $this->assertSame($entry->getUrl(), $content['url']); | 580 | $this->assertSame($entry->getUrl(), $content['url']); |
582 | $this->assertSame('New awesome title', $content['title']); | 581 | $this->assertGreaterThanOrEqual(1, count($content['tags']), 'We force only one tag'); |
583 | $this->assertGreaterThan($nbTags, count($content['tags'])); | 582 | $this->assertGreaterThan($nbTags, count($content['tags'])); |
584 | $this->assertEmpty($content['published_by'], 'Authors were not saved because of an array instead of a string'); | 583 | $this->assertEmpty($content['published_by'], 'Authors were not saved because of an array instead of a string'); |
584 | $this->assertEquals($previousContent, $content['content'], 'Ensure content has not moved'); | ||
585 | $this->assertEquals($previousLanguage, $content['language'], 'Ensure language has not moved'); | ||
585 | } | 586 | } |
586 | 587 | ||
587 | public function testGetTagsEntry() | 588 | public function testGetTagsEntry() |
@@ -727,8 +728,10 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
727 | $this->markTestSkipped('No content found in db.'); | 728 | $this->markTestSkipped('No content found in db.'); |
728 | } | 729 | } |
729 | 730 | ||
730 | $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [ | 731 | $previousTitle = $entry->getTitle(); |
731 | 'title' => $entry->getTitle() . '++', | 732 | |
733 | $this->client->request('PATCH', '/api/entries/'.$entry->getId().'.json', [ | ||
734 | 'title' => $entry->getTitle().'++', | ||
732 | ]); | 735 | ]); |
733 | 736 | ||
734 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); | 737 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); |
@@ -736,6 +739,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
736 | $content = json_decode($this->client->getResponse()->getContent(), true); | 739 | $content = json_decode($this->client->getResponse()->getContent(), true); |
737 | 740 | ||
738 | $this->assertSame(1, $content['is_archived']); | 741 | $this->assertSame(1, $content['is_archived']); |
742 | $this->assertEquals($previousTitle.'++', $content['title']); | ||
739 | } | 743 | } |
740 | 744 | ||
741 | public function testSaveIsStarredAfterPatch() | 745 | public function testSaveIsStarredAfterPatch() |
@@ -907,6 +911,17 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
907 | $this->assertCount(4, $tags); | 911 | $this->assertCount(4, $tags); |
908 | } | 912 | } |
909 | 913 | ||
914 | public function testPostEntriesTagsListActionNoList() | ||
915 | { | ||
916 | $this->client->request('POST', '/api/entries/tags/lists?list='.json_encode([])); | ||
917 | |||
918 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
919 | |||
920 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
921 | |||
922 | $this->assertEmpty($content); | ||
923 | } | ||
924 | |||
910 | public function testDeleteEntriesTagsListAction() | 925 | public function testDeleteEntriesTagsListAction() |
911 | { | 926 | { |
912 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); | 927 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); |
@@ -933,6 +948,17 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
933 | $this->assertCount(0, $entry->getTags()); | 948 | $this->assertCount(0, $entry->getTags()); |
934 | } | 949 | } |
935 | 950 | ||
951 | public function testDeleteEntriesTagsListActionNoList() | ||
952 | { | ||
953 | $this->client->request('DELETE', '/api/entries/tags/list?list='.json_encode([])); | ||
954 | |||
955 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
956 | |||
957 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
958 | |||
959 | $this->assertEmpty($content); | ||
960 | } | ||
961 | |||
936 | public function testPostEntriesListAction() | 962 | public function testPostEntriesListAction() |
937 | { | 963 | { |
938 | $list = [ | 964 | $list = [ |
@@ -953,6 +979,17 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
953 | $this->assertSame('http://0.0.0.0/entry2', $content[1]['url']); | 979 | $this->assertSame('http://0.0.0.0/entry2', $content[1]['url']); |
954 | } | 980 | } |
955 | 981 | ||
982 | public function testPostEntriesListActionWithNoUrls() | ||
983 | { | ||
984 | $this->client->request('POST', '/api/entries/lists?urls='.json_encode([])); | ||
985 | |||
986 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
987 | |||
988 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
989 | |||
990 | $this->assertEmpty($content); | ||
991 | } | ||
992 | |||
956 | public function testDeleteEntriesListAction() | 993 | public function testDeleteEntriesListAction() |
957 | { | 994 | { |
958 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); | 995 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); |
@@ -978,6 +1015,17 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
978 | $this->assertSame('http://0.0.0.0/test-entry-not-exist', $content[1]['url']); | 1015 | $this->assertSame('http://0.0.0.0/test-entry-not-exist', $content[1]['url']); |
979 | } | 1016 | } |
980 | 1017 | ||
1018 | public function testDeleteEntriesListActionWithNoUrls() | ||
1019 | { | ||
1020 | $this->client->request('DELETE', '/api/entries/list?urls='.json_encode([])); | ||
1021 | |||
1022 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
1023 | |||
1024 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
1025 | |||
1026 | $this->assertEmpty($content); | ||
1027 | } | ||
1028 | |||
981 | public function testLimitBulkAction() | 1029 | public function testLimitBulkAction() |
982 | { | 1030 | { |
983 | $list = [ | 1031 | $list = [ |