diff options
Diffstat (limited to 'tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php')
-rw-r--r-- | tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | 149 |
1 files changed, 144 insertions, 5 deletions
diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 0a65f9ce..0968cfaf 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | |||
@@ -3,8 +3,10 @@ | |||
3 | namespace Tests\Wallabag\ApiBundle\Controller; | 3 | namespace Tests\Wallabag\ApiBundle\Controller; |
4 | 4 | ||
5 | use Tests\Wallabag\ApiBundle\WallabagApiTestCase; | 5 | use Tests\Wallabag\ApiBundle\WallabagApiTestCase; |
6 | use Wallabag\CoreBundle\Entity\Entry; | ||
6 | use Wallabag\CoreBundle\Entity\Tag; | 7 | use Wallabag\CoreBundle\Entity\Tag; |
7 | use Wallabag\CoreBundle\Helper\ContentProxy; | 8 | use Wallabag\CoreBundle\Helper\ContentProxy; |
9 | use Wallabag\UserBundle\Entity\User; | ||
8 | 10 | ||
9 | class EntryRestControllerTest extends WallabagApiTestCase | 11 | class EntryRestControllerTest extends WallabagApiTestCase |
10 | { | 12 | { |
@@ -315,7 +317,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
315 | $entry = $this->client->getContainer() | 317 | $entry = $this->client->getContainer() |
316 | ->get('doctrine.orm.entity_manager') | 318 | ->get('doctrine.orm.entity_manager') |
317 | ->getRepository('WallabagCoreBundle:Entry') | 319 | ->getRepository('WallabagCoreBundle:Entry') |
318 | ->findOneByUser(1); | 320 | ->findOneByUser(1, ['id' => 'asc']); |
319 | 321 | ||
320 | if (!$entry) { | 322 | if (!$entry) { |
321 | $this->markTestSkipped('No content found in db.'); | 323 | $this->markTestSkipped('No content found in db.'); |
@@ -342,6 +344,10 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
342 | 'url' => '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', | 344 | 'url' => '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', |
343 | 'tags' => 'google', | 345 | 'tags' => 'google', |
344 | 'title' => 'New title for my article', | 346 | 'title' => 'New title for my article', |
347 | 'content' => 'my content', | ||
348 | 'language' => 'de_DE', | ||
349 | 'published_at' => '2016-09-08T11:55:58+0200', | ||
350 | 'authors' => 'bob,helen', | ||
345 | ]); | 351 | ]); |
346 | 352 | ||
347 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | 353 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
@@ -354,7 +360,13 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
354 | $this->assertEquals(false, $content['is_starred']); | 360 | $this->assertEquals(false, $content['is_starred']); |
355 | $this->assertEquals('New title for my article', $content['title']); | 361 | $this->assertEquals('New title for my article', $content['title']); |
356 | $this->assertEquals(1, $content['user_id']); | 362 | $this->assertEquals(1, $content['user_id']); |
357 | $this->assertCount(1, $content['tags']); | 363 | $this->assertCount(2, $content['tags']); |
364 | $this->assertSame('my content', $content['content']); | ||
365 | $this->assertSame('de_DE', $content['language']); | ||
366 | $this->assertSame('2016-09-08T11:55:58+0200', $content['published_at']); | ||
367 | $this->assertCount(2, $content['published_by']); | ||
368 | $this->assertContains('bob', $content['published_by']); | ||
369 | $this->assertContains('helen', $content['published_by']); | ||
358 | } | 370 | } |
359 | 371 | ||
360 | public function testPostSameEntry() | 372 | public function testPostSameEntry() |
@@ -373,7 +385,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']); | 385 | $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']); | 386 | $this->assertEquals(true, $content['is_archived']); |
375 | $this->assertEquals(false, $content['is_starred']); | 387 | $this->assertEquals(false, $content['is_starred']); |
376 | $this->assertCount(2, $content['tags']); | 388 | $this->assertCount(3, $content['tags']); |
377 | } | 389 | } |
378 | 390 | ||
379 | public function testPostEntryWhenFetchContentFails() | 391 | public function testPostEntryWhenFetchContentFails() |
@@ -692,7 +704,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
692 | 704 | ||
693 | $content = json_decode($this->client->getResponse()->getContent(), true); | 705 | $content = json_decode($this->client->getResponse()->getContent(), true); |
694 | 706 | ||
695 | $this->assertEquals(true, $content['exists']); | 707 | $this->assertEquals(2, $content['exists']); |
696 | } | 708 | } |
697 | 709 | ||
698 | public function testGetEntriesExistsWithManyUrls() | 710 | public function testGetEntriesExistsWithManyUrls() |
@@ -707,7 +719,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
707 | 719 | ||
708 | $this->assertArrayHasKey($url1, $content); | 720 | $this->assertArrayHasKey($url1, $content); |
709 | $this->assertArrayHasKey($url2, $content); | 721 | $this->assertArrayHasKey($url2, $content); |
710 | $this->assertEquals(true, $content[$url1]); | 722 | $this->assertEquals(2, $content[$url1]); |
711 | $this->assertEquals(false, $content[$url2]); | 723 | $this->assertEquals(false, $content[$url2]); |
712 | } | 724 | } |
713 | 725 | ||
@@ -764,4 +776,131 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
764 | 776 | ||
765 | $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); | 777 | $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); |
766 | } | 778 | } |
779 | |||
780 | public function testPostEntriesTagsListAction() | ||
781 | { | ||
782 | $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') | ||
783 | ->getRepository('WallabagCoreBundle:Entry') | ||
784 | ->findByUrlAndUserId('http://0.0.0.0/entry4', 1); | ||
785 | |||
786 | $tags = $entry->getTags(); | ||
787 | |||
788 | $this->assertCount(2, $tags); | ||
789 | |||
790 | $list = [ | ||
791 | [ | ||
792 | 'url' => 'http://0.0.0.0/entry4', | ||
793 | 'tags' => 'new tag 1, new tag 2', | ||
794 | ], | ||
795 | ]; | ||
796 | |||
797 | $this->client->request('POST', '/api/entries/tags/lists?list='.json_encode($list)); | ||
798 | |||
799 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
800 | |||
801 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
802 | |||
803 | $this->assertInternalType('int', $content[0]['entry']); | ||
804 | $this->assertEquals('http://0.0.0.0/entry4', $content[0]['url']); | ||
805 | |||
806 | $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') | ||
807 | ->getRepository('WallabagCoreBundle:Entry') | ||
808 | ->findByUrlAndUserId('http://0.0.0.0/entry4', 1); | ||
809 | |||
810 | $tags = $entry->getTags(); | ||
811 | $this->assertCount(4, $tags); | ||
812 | } | ||
813 | |||
814 | public function testDeleteEntriesTagsListAction() | ||
815 | { | ||
816 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); | ||
817 | $entry = new Entry($em->getReference(User::class, 1)); | ||
818 | $entry->setUrl('http://0.0.0.0/test-entry'); | ||
819 | $entry->addTag((new Tag())->setLabel('foo-tag')); | ||
820 | $entry->addTag((new Tag())->setLabel('bar-tag')); | ||
821 | $em->persist($entry); | ||
822 | $em->flush(); | ||
823 | |||
824 | $em->clear(); | ||
825 | |||
826 | $list = [ | ||
827 | [ | ||
828 | 'url' => 'http://0.0.0.0/test-entry', | ||
829 | 'tags' => 'foo-tag, bar-tag', | ||
830 | ], | ||
831 | ]; | ||
832 | |||
833 | $this->client->request('DELETE', '/api/entries/tags/list?list='.json_encode($list)); | ||
834 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
835 | |||
836 | $entry = $em->getRepository('WallabagCoreBundle:Entry')->find($entry->getId()); | ||
837 | $this->assertCount(0, $entry->getTags()); | ||
838 | } | ||
839 | |||
840 | public function testPostEntriesListAction() | ||
841 | { | ||
842 | $list = [ | ||
843 | 'http://www.lemonde.fr/musiques/article/2017/04/23/loin-de-la-politique-le-printemps-de-bourges-retombe-en-enfance_5115862_1654986.html', | ||
844 | 'http://0.0.0.0/entry2', | ||
845 | ]; | ||
846 | |||
847 | $this->client->request('POST', '/api/entries/lists?urls='.json_encode($list)); | ||
848 | |||
849 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
850 | |||
851 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
852 | |||
853 | $this->assertInternalType('int', $content[0]['entry']); | ||
854 | $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']); | ||
855 | |||
856 | $this->assertInternalType('int', $content[1]['entry']); | ||
857 | $this->assertEquals('http://0.0.0.0/entry2', $content[1]['url']); | ||
858 | } | ||
859 | |||
860 | public function testDeleteEntriesListAction() | ||
861 | { | ||
862 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); | ||
863 | $em->persist((new Entry($em->getReference(User::class, 1)))->setUrl('http://0.0.0.0/test-entry1')); | ||
864 | |||
865 | $em->flush(); | ||
866 | $em->clear(); | ||
867 | $list = [ | ||
868 | 'http://0.0.0.0/test-entry1', | ||
869 | 'http://0.0.0.0/test-entry-not-exist', | ||
870 | ]; | ||
871 | |||
872 | $this->client->request('DELETE', '/api/entries/list?urls='.json_encode($list)); | ||
873 | |||
874 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
875 | |||
876 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
877 | |||
878 | $this->assertTrue($content[0]['entry']); | ||
879 | $this->assertEquals('http://0.0.0.0/test-entry1', $content[0]['url']); | ||
880 | |||
881 | $this->assertFalse($content[1]['entry']); | ||
882 | $this->assertEquals('http://0.0.0.0/test-entry-not-exist', $content[1]['url']); | ||
883 | } | ||
884 | |||
885 | public function testLimitBulkAction() | ||
886 | { | ||
887 | $list = [ | ||
888 | 'http://0.0.0.0/entry1', | ||
889 | 'http://0.0.0.0/entry1', | ||
890 | 'http://0.0.0.0/entry1', | ||
891 | 'http://0.0.0.0/entry1', | ||
892 | 'http://0.0.0.0/entry1', | ||
893 | 'http://0.0.0.0/entry1', | ||
894 | 'http://0.0.0.0/entry1', | ||
895 | 'http://0.0.0.0/entry1', | ||
896 | 'http://0.0.0.0/entry1', | ||
897 | 'http://0.0.0.0/entry1', | ||
898 | 'http://0.0.0.0/entry1', | ||
899 | ]; | ||
900 | |||
901 | $this->client->request('POST', '/api/entries/lists?urls='.json_encode($list)); | ||
902 | |||
903 | $this->assertEquals(400, $this->client->getResponse()->getStatusCode()); | ||
904 | $this->assertContains('API limit reached', $this->client->getResponse()->getContent()); | ||
905 | } | ||
767 | } | 906 | } |