diff options
Diffstat (limited to 'tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php')
-rw-r--r-- | tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | 126 |
1 files changed, 121 insertions, 5 deletions
diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 63d70bd9..4f49f040 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | |||
@@ -314,7 +314,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
314 | $entry = $this->client->getContainer() | 314 | $entry = $this->client->getContainer() |
315 | ->get('doctrine.orm.entity_manager') | 315 | ->get('doctrine.orm.entity_manager') |
316 | ->getRepository('WallabagCoreBundle:Entry') | 316 | ->getRepository('WallabagCoreBundle:Entry') |
317 | ->findOneByUser(1); | 317 | ->findOneByUser(1, ['id' => 'asc']); |
318 | 318 | ||
319 | if (!$entry) { | 319 | if (!$entry) { |
320 | $this->markTestSkipped('No content found in db.'); | 320 | $this->markTestSkipped('No content found in db.'); |
@@ -353,7 +353,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
353 | $this->assertEquals(false, $content['is_starred']); | 353 | $this->assertEquals(false, $content['is_starred']); |
354 | $this->assertEquals('New title for my article', $content['title']); | 354 | $this->assertEquals('New title for my article', $content['title']); |
355 | $this->assertEquals(1, $content['user_id']); | 355 | $this->assertEquals(1, $content['user_id']); |
356 | $this->assertCount(1, $content['tags']); | 356 | $this->assertCount(2, $content['tags']); |
357 | } | 357 | } |
358 | 358 | ||
359 | public function testPostSameEntry() | 359 | public function testPostSameEntry() |
@@ -372,7 +372,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
372 | $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']); | 372 | $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(true, $content['is_archived']); | 373 | $this->assertEquals(true, $content['is_archived']); |
374 | $this->assertEquals(false, $content['is_starred']); | 374 | $this->assertEquals(false, $content['is_starred']); |
375 | $this->assertCount(2, $content['tags']); | 375 | $this->assertCount(3, $content['tags']); |
376 | } | 376 | } |
377 | 377 | ||
378 | public function testPostArchivedAndStarredEntry() | 378 | public function testPostArchivedAndStarredEntry() |
@@ -658,7 +658,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
658 | 658 | ||
659 | $content = json_decode($this->client->getResponse()->getContent(), true); | 659 | $content = json_decode($this->client->getResponse()->getContent(), true); |
660 | 660 | ||
661 | $this->assertEquals(true, $content['exists']); | 661 | $this->assertEquals(2, $content['exists']); |
662 | } | 662 | } |
663 | 663 | ||
664 | public function testGetEntriesExistsWithManyUrls() | 664 | public function testGetEntriesExistsWithManyUrls() |
@@ -673,7 +673,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
673 | 673 | ||
674 | $this->assertArrayHasKey($url1, $content); | 674 | $this->assertArrayHasKey($url1, $content); |
675 | $this->assertArrayHasKey($url2, $content); | 675 | $this->assertArrayHasKey($url2, $content); |
676 | $this->assertEquals(true, $content[$url1]); | 676 | $this->assertEquals(2, $content[$url1]); |
677 | $this->assertEquals(false, $content[$url2]); | 677 | $this->assertEquals(false, $content[$url2]); |
678 | } | 678 | } |
679 | 679 | ||
@@ -730,4 +730,120 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
730 | 730 | ||
731 | $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); | 731 | $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); |
732 | } | 732 | } |
733 | |||
734 | public function testPostEntriesTagsListAction() | ||
735 | { | ||
736 | $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') | ||
737 | ->getRepository('WallabagCoreBundle:Entry') | ||
738 | ->findByUrlAndUserId('http://0.0.0.0/entry4', 1); | ||
739 | |||
740 | $tags = $entry->getTags(); | ||
741 | |||
742 | $this->assertCount(2, $tags); | ||
743 | |||
744 | $list = [ | ||
745 | [ | ||
746 | 'url' => 'http://0.0.0.0/entry4', | ||
747 | 'tags' => 'new tag 1, new tag 2', | ||
748 | ], | ||
749 | ]; | ||
750 | |||
751 | $this->client->request('POST', '/api/entries/tags/lists?list='.json_encode($list)); | ||
752 | |||
753 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
754 | |||
755 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
756 | |||
757 | $this->assertInternalType('int', $content[0]['entry']); | ||
758 | $this->assertEquals('http://0.0.0.0/entry4', $content[0]['url']); | ||
759 | |||
760 | $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') | ||
761 | ->getRepository('WallabagCoreBundle:Entry') | ||
762 | ->findByUrlAndUserId('http://0.0.0.0/entry4', 1); | ||
763 | |||
764 | $tags = $entry->getTags(); | ||
765 | $this->assertCount(4, $tags); | ||
766 | } | ||
767 | |||
768 | public function testDeleteEntriesTagsListAction() | ||
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(4, $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('DELETE', '/api/entries/tags/list?list='.json_encode($list)); | ||
786 | } | ||
787 | |||
788 | public function testPostEntriesListAction() | ||
789 | { | ||
790 | $list = [ | ||
791 | 'http://www.lemonde.fr/musiques/article/2017/04/23/loin-de-la-politique-le-printemps-de-bourges-retombe-en-enfance_5115862_1654986.html', | ||
792 | 'http://0.0.0.0/entry2', | ||
793 | ]; | ||
794 | |||
795 | $this->client->request('POST', '/api/entries/lists?urls='.json_encode($list)); | ||
796 | |||
797 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
798 | |||
799 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
800 | |||
801 | $this->assertInternalType('int', $content[0]['entry']); | ||
802 | $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']); | ||
803 | |||
804 | $this->assertInternalType('int', $content[1]['entry']); | ||
805 | $this->assertEquals('http://0.0.0.0/entry2', $content[1]['url']); | ||
806 | } | ||
807 | |||
808 | public function testDeleteEntriesListAction() | ||
809 | { | ||
810 | $list = [ | ||
811 | 'http://www.lemonde.fr/musiques/article/2017/04/23/loin-de-la-politique-le-printemps-de-bourges-retombe-en-enfance_5115862_1654986.html', | ||
812 | 'http://0.0.0.0/entry3', | ||
813 | ]; | ||
814 | |||
815 | $this->client->request('DELETE', '/api/entries/list?urls='.json_encode($list)); | ||
816 | |||
817 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
818 | |||
819 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
820 | |||
821 | $this->assertTrue($content[0]['entry']); | ||
822 | $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']); | ||
823 | |||
824 | $this->assertFalse($content[1]['entry']); | ||
825 | $this->assertEquals('http://0.0.0.0/entry3', $content[1]['url']); | ||
826 | } | ||
827 | |||
828 | public function testLimitBulkAction() | ||
829 | { | ||
830 | $list = [ | ||
831 | 'http://0.0.0.0/entry1', | ||
832 | 'http://0.0.0.0/entry1', | ||
833 | 'http://0.0.0.0/entry1', | ||
834 | 'http://0.0.0.0/entry1', | ||
835 | 'http://0.0.0.0/entry1', | ||
836 | 'http://0.0.0.0/entry1', | ||
837 | 'http://0.0.0.0/entry1', | ||
838 | 'http://0.0.0.0/entry1', | ||
839 | 'http://0.0.0.0/entry1', | ||
840 | 'http://0.0.0.0/entry1', | ||
841 | 'http://0.0.0.0/entry1', | ||
842 | ]; | ||
843 | |||
844 | $this->client->request('POST', '/api/entries/lists?urls='.json_encode($list)); | ||
845 | |||
846 | $this->assertEquals(400, $this->client->getResponse()->getStatusCode()); | ||
847 | $this->assertContains('API limit reached', $this->client->getResponse()->getContent()); | ||
848 | } | ||
733 | } | 849 | } |