diff options
Diffstat (limited to 'tests/Wallabag/ApiBundle/Controller')
-rw-r--r-- | tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | 126 | ||||
-rw-r--r-- | tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php | 30 |
2 files changed, 147 insertions, 9 deletions
diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 0a65f9ce..bf7d373a 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | |||
@@ -315,7 +315,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
315 | $entry = $this->client->getContainer() | 315 | $entry = $this->client->getContainer() |
316 | ->get('doctrine.orm.entity_manager') | 316 | ->get('doctrine.orm.entity_manager') |
317 | ->getRepository('WallabagCoreBundle:Entry') | 317 | ->getRepository('WallabagCoreBundle:Entry') |
318 | ->findOneByUser(1); | 318 | ->findOneByUser(1, ['id' => 'asc']); |
319 | 319 | ||
320 | if (!$entry) { | 320 | if (!$entry) { |
321 | $this->markTestSkipped('No content found in db.'); | 321 | $this->markTestSkipped('No content found in db.'); |
@@ -354,7 +354,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
354 | $this->assertEquals(false, $content['is_starred']); | 354 | $this->assertEquals(false, $content['is_starred']); |
355 | $this->assertEquals('New title for my article', $content['title']); | 355 | $this->assertEquals('New title for my article', $content['title']); |
356 | $this->assertEquals(1, $content['user_id']); | 356 | $this->assertEquals(1, $content['user_id']); |
357 | $this->assertCount(1, $content['tags']); | 357 | $this->assertCount(2, $content['tags']); |
358 | } | 358 | } |
359 | 359 | ||
360 | public function testPostSameEntry() | 360 | public function testPostSameEntry() |
@@ -373,7 +373,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
373 | $this->assertEquals('http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html', $content['url']); | 373 | $this->assertEquals('http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html', $content['url']); |
374 | $this->assertEquals(true, $content['is_archived']); | 374 | $this->assertEquals(true, $content['is_archived']); |
375 | $this->assertEquals(false, $content['is_starred']); | 375 | $this->assertEquals(false, $content['is_starred']); |
376 | $this->assertCount(2, $content['tags']); | 376 | $this->assertCount(3, $content['tags']); |
377 | } | 377 | } |
378 | 378 | ||
379 | public function testPostEntryWhenFetchContentFails() | 379 | public function testPostEntryWhenFetchContentFails() |
@@ -692,7 +692,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
692 | 692 | ||
693 | $content = json_decode($this->client->getResponse()->getContent(), true); | 693 | $content = json_decode($this->client->getResponse()->getContent(), true); |
694 | 694 | ||
695 | $this->assertEquals(true, $content['exists']); | 695 | $this->assertEquals(2, $content['exists']); |
696 | } | 696 | } |
697 | 697 | ||
698 | public function testGetEntriesExistsWithManyUrls() | 698 | public function testGetEntriesExistsWithManyUrls() |
@@ -707,7 +707,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
707 | 707 | ||
708 | $this->assertArrayHasKey($url1, $content); | 708 | $this->assertArrayHasKey($url1, $content); |
709 | $this->assertArrayHasKey($url2, $content); | 709 | $this->assertArrayHasKey($url2, $content); |
710 | $this->assertEquals(true, $content[$url1]); | 710 | $this->assertEquals(2, $content[$url1]); |
711 | $this->assertEquals(false, $content[$url2]); | 711 | $this->assertEquals(false, $content[$url2]); |
712 | } | 712 | } |
713 | 713 | ||
@@ -764,4 +764,120 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
764 | 764 | ||
765 | $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); | 765 | $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); |
766 | } | 766 | } |
767 | |||
768 | public function testPostEntriesTagsListAction() | ||
769 | { | ||
770 | $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') | ||
771 | ->getRepository('WallabagCoreBundle:Entry') | ||
772 | ->findByUrlAndUserId('http://0.0.0.0/entry4', 1); | ||
773 | |||
774 | $tags = $entry->getTags(); | ||
775 | |||
776 | $this->assertCount(2, $tags); | ||
777 | |||
778 | $list = [ | ||
779 | [ | ||
780 | 'url' => 'http://0.0.0.0/entry4', | ||
781 | 'tags' => 'new tag 1, new tag 2', | ||
782 | ], | ||
783 | ]; | ||
784 | |||
785 | $this->client->request('POST', '/api/entries/tags/lists?list='.json_encode($list)); | ||
786 | |||
787 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
788 | |||
789 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
790 | |||
791 | $this->assertInternalType('int', $content[0]['entry']); | ||
792 | $this->assertEquals('http://0.0.0.0/entry4', $content[0]['url']); | ||
793 | |||
794 | $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') | ||
795 | ->getRepository('WallabagCoreBundle:Entry') | ||
796 | ->findByUrlAndUserId('http://0.0.0.0/entry4', 1); | ||
797 | |||
798 | $tags = $entry->getTags(); | ||
799 | $this->assertCount(4, $tags); | ||
800 | } | ||
801 | |||
802 | public function testDeleteEntriesTagsListAction() | ||
803 | { | ||
804 | $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') | ||
805 | ->getRepository('WallabagCoreBundle:Entry') | ||
806 | ->findByUrlAndUserId('http://0.0.0.0/entry4', 1); | ||
807 | |||
808 | $tags = $entry->getTags(); | ||
809 | |||
810 | $this->assertCount(4, $tags); | ||
811 | |||
812 | $list = [ | ||
813 | [ | ||
814 | 'url' => 'http://0.0.0.0/entry4', | ||
815 | 'tags' => 'new tag 1, new tag 2', | ||
816 | ], | ||
817 | ]; | ||
818 | |||
819 | $this->client->request('DELETE', '/api/entries/tags/list?list='.json_encode($list)); | ||
820 | } | ||
821 | |||
822 | public function testPostEntriesListAction() | ||
823 | { | ||
824 | $list = [ | ||
825 | 'http://www.lemonde.fr/musiques/article/2017/04/23/loin-de-la-politique-le-printemps-de-bourges-retombe-en-enfance_5115862_1654986.html', | ||
826 | 'http://0.0.0.0/entry2', | ||
827 | ]; | ||
828 | |||
829 | $this->client->request('POST', '/api/entries/lists?urls='.json_encode($list)); | ||
830 | |||
831 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
832 | |||
833 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
834 | |||
835 | $this->assertInternalType('int', $content[0]['entry']); | ||
836 | $this->assertEquals('http://www.lemonde.fr/musiques/article/2017/04/23/loin-de-la-politique-le-printemps-de-bourges-retombe-en-enfance_5115862_1654986.html', $content[0]['url']); | ||
837 | |||
838 | $this->assertInternalType('int', $content[1]['entry']); | ||
839 | $this->assertEquals('http://0.0.0.0/entry2', $content[1]['url']); | ||
840 | } | ||
841 | |||
842 | public function testDeleteEntriesListAction() | ||
843 | { | ||
844 | $list = [ | ||
845 | 'http://www.lemonde.fr/musiques/article/2017/04/23/loin-de-la-politique-le-printemps-de-bourges-retombe-en-enfance_5115862_1654986.html', | ||
846 | 'http://0.0.0.0/entry3', | ||
847 | ]; | ||
848 | |||
849 | $this->client->request('DELETE', '/api/entries/list?urls='.json_encode($list)); | ||
850 | |||
851 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
852 | |||
853 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
854 | |||
855 | $this->assertTrue($content[0]['entry']); | ||
856 | $this->assertEquals('http://www.lemonde.fr/musiques/article/2017/04/23/loin-de-la-politique-le-printemps-de-bourges-retombe-en-enfance_5115862_1654986.html', $content[0]['url']); | ||
857 | |||
858 | $this->assertFalse($content[1]['entry']); | ||
859 | $this->assertEquals('http://0.0.0.0/entry3', $content[1]['url']); | ||
860 | } | ||
861 | |||
862 | public function testLimitBulkAction() | ||
863 | { | ||
864 | $list = [ | ||
865 | 'http://0.0.0.0/entry1', | ||
866 | 'http://0.0.0.0/entry1', | ||
867 | 'http://0.0.0.0/entry1', | ||
868 | 'http://0.0.0.0/entry1', | ||
869 | 'http://0.0.0.0/entry1', | ||
870 | 'http://0.0.0.0/entry1', | ||
871 | 'http://0.0.0.0/entry1', | ||
872 | 'http://0.0.0.0/entry1', | ||
873 | 'http://0.0.0.0/entry1', | ||
874 | 'http://0.0.0.0/entry1', | ||
875 | 'http://0.0.0.0/entry1', | ||
876 | ]; | ||
877 | |||
878 | $this->client->request('POST', '/api/entries/lists?urls='.json_encode($list)); | ||
879 | |||
880 | $this->assertEquals(400, $this->client->getResponse()->getStatusCode()); | ||
881 | $this->assertContains('API limit reached', $this->client->getResponse()->getContent()); | ||
882 | } | ||
767 | } | 883 | } |
diff --git a/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php index bde5251f..90b132eb 100644 --- a/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php | |||
@@ -54,7 +54,18 @@ class TagRestControllerTest extends WallabagApiTestCase | |||
54 | $this->assertNull($tag, $tagName.' was removed because it begun an orphan tag'); | 54 | $this->assertNull($tag, $tagName.' was removed because it begun an orphan tag'); |
55 | } | 55 | } |
56 | 56 | ||
57 | public function testDeleteTagByLabel() | 57 | public function dataForDeletingTagByLabel() |
58 | { | ||
59 | return [ | ||
60 | 'by_query' => [true], | ||
61 | 'by_body' => [false], | ||
62 | ]; | ||
63 | } | ||
64 | |||
65 | /** | ||
66 | * @dataProvider dataForDeletingTagByLabel | ||
67 | */ | ||
68 | public function testDeleteTagByLabel($useQueryString) | ||
58 | { | 69 | { |
59 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); | 70 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); |
60 | $entry = $this->client->getContainer() | 71 | $entry = $this->client->getContainer() |
@@ -73,7 +84,11 @@ class TagRestControllerTest extends WallabagApiTestCase | |||
73 | $em->persist($entry); | 84 | $em->persist($entry); |
74 | $em->flush(); | 85 | $em->flush(); |
75 | 86 | ||
76 | $this->client->request('DELETE', '/api/tag/label.json', ['tag' => $tag->getLabel()]); | 87 | if ($useQueryString) { |
88 | $this->client->request('DELETE', '/api/tag/label.json?tag='.$tag->getLabel()); | ||
89 | } else { | ||
90 | $this->client->request('DELETE', '/api/tag/label.json', ['tag' => $tag->getLabel()]); | ||
91 | } | ||
77 | 92 | ||
78 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | 93 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
79 | 94 | ||
@@ -98,7 +113,10 @@ class TagRestControllerTest extends WallabagApiTestCase | |||
98 | $this->assertEquals(404, $this->client->getResponse()->getStatusCode()); | 113 | $this->assertEquals(404, $this->client->getResponse()->getStatusCode()); |
99 | } | 114 | } |
100 | 115 | ||
101 | public function testDeleteTagsByLabel() | 116 | /** |
117 | * @dataProvider dataForDeletingTagByLabel | ||
118 | */ | ||
119 | public function testDeleteTagsByLabel($useQueryString) | ||
102 | { | 120 | { |
103 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); | 121 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); |
104 | $entry = $this->client->getContainer() | 122 | $entry = $this->client->getContainer() |
@@ -122,7 +140,11 @@ class TagRestControllerTest extends WallabagApiTestCase | |||
122 | $em->persist($entry); | 140 | $em->persist($entry); |
123 | $em->flush(); | 141 | $em->flush(); |
124 | 142 | ||
125 | $this->client->request('DELETE', '/api/tags/label.json', ['tags' => $tag->getLabel().','.$tag2->getLabel()]); | 143 | if ($useQueryString) { |
144 | $this->client->request('DELETE', '/api/tags/label.json?tags='.$tag->getLabel().','.$tag2->getLabel()); | ||
145 | } else { | ||
146 | $this->client->request('DELETE', '/api/tags/label.json', ['tags' => $tag->getLabel().','.$tag2->getLabel()]); | ||
147 | } | ||
126 | 148 | ||
127 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | 149 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
128 | 150 | ||