aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php')
-rw-r--r--tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php160
1 files changed, 155 insertions, 5 deletions
diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
index 0a65f9ce..4aa60e90 100644
--- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
+++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
@@ -3,8 +3,10 @@
3namespace Tests\Wallabag\ApiBundle\Controller; 3namespace Tests\Wallabag\ApiBundle\Controller;
4 4
5use Tests\Wallabag\ApiBundle\WallabagApiTestCase; 5use Tests\Wallabag\ApiBundle\WallabagApiTestCase;
6use Wallabag\CoreBundle\Entity\Entry;
6use Wallabag\CoreBundle\Entity\Tag; 7use Wallabag\CoreBundle\Entity\Tag;
7use Wallabag\CoreBundle\Helper\ContentProxy; 8use Wallabag\CoreBundle\Helper\ContentProxy;
9use Wallabag\UserBundle\Entity\User;
8 10
9class EntryRestControllerTest extends WallabagApiTestCase 11class 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',
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', $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()
@@ -465,6 +477,10 @@ class EntryRestControllerTest extends WallabagApiTestCase
465 'tags' => 'new tag '.uniqid(), 477 'tags' => 'new tag '.uniqid(),
466 'starred' => '1', 478 'starred' => '1',
467 'archive' => '0', 479 'archive' => '0',
480 'language' => 'de_AT',
481 'preview_picture' => 'http://preview.io/picture.jpg',
482 'authors' => 'bob,sponge',
483 'content' => 'awesome',
468 ]); 484 ]);
469 485
470 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 486 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
@@ -476,6 +492,11 @@ class EntryRestControllerTest extends WallabagApiTestCase
476 $this->assertEquals('New awesome title', $content['title']); 492 $this->assertEquals('New awesome title', $content['title']);
477 $this->assertGreaterThan($nbTags, count($content['tags'])); 493 $this->assertGreaterThan($nbTags, count($content['tags']));
478 $this->assertEquals(1, $content['user_id']); 494 $this->assertEquals(1, $content['user_id']);
495 $this->assertEquals('de_AT', $content['language']);
496 $this->assertEquals('http://preview.io/picture.jpg', $content['preview_picture']);
497 $this->assertContains('sponge', $content['published_by']);
498 $this->assertContains('bob', $content['published_by']);
499 $this->assertEquals('awesome', $content['content']);
479 } 500 }
480 501
481 public function testPatchEntryWithoutQuotes() 502 public function testPatchEntryWithoutQuotes()
@@ -497,6 +518,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
497 'tags' => 'new tag '.uniqid(), 518 'tags' => 'new tag '.uniqid(),
498 'starred' => 1, 519 'starred' => 1,
499 'archive' => 0, 520 'archive' => 0,
521 'authors' => ['bob', 'sponge'],
500 ]); 522 ]);
501 523
502 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 524 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
@@ -507,6 +529,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
507 $this->assertEquals($entry->getUrl(), $content['url']); 529 $this->assertEquals($entry->getUrl(), $content['url']);
508 $this->assertEquals('New awesome title', $content['title']); 530 $this->assertEquals('New awesome title', $content['title']);
509 $this->assertGreaterThan($nbTags, count($content['tags'])); 531 $this->assertGreaterThan($nbTags, count($content['tags']));
532 $this->assertTrue(empty($content['published_by']), 'Authors were not saved because of an array instead of a string');
510 } 533 }
511 534
512 public function testGetTagsEntry() 535 public function testGetTagsEntry()
@@ -692,7 +715,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
692 715
693 $content = json_decode($this->client->getResponse()->getContent(), true); 716 $content = json_decode($this->client->getResponse()->getContent(), true);
694 717
695 $this->assertEquals(true, $content['exists']); 718 $this->assertEquals(2, $content['exists']);
696 } 719 }
697 720
698 public function testGetEntriesExistsWithManyUrls() 721 public function testGetEntriesExistsWithManyUrls()
@@ -707,7 +730,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
707 730
708 $this->assertArrayHasKey($url1, $content); 731 $this->assertArrayHasKey($url1, $content);
709 $this->assertArrayHasKey($url2, $content); 732 $this->assertArrayHasKey($url2, $content);
710 $this->assertEquals(true, $content[$url1]); 733 $this->assertEquals(2, $content[$url1]);
711 $this->assertEquals(false, $content[$url2]); 734 $this->assertEquals(false, $content[$url2]);
712 } 735 }
713 736
@@ -764,4 +787,131 @@ class EntryRestControllerTest extends WallabagApiTestCase
764 787
765 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); 788 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type'));
766 } 789 }
790
791 public function testPostEntriesTagsListAction()
792 {
793 $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager')
794 ->getRepository('WallabagCoreBundle:Entry')
795 ->findByUrlAndUserId('http://0.0.0.0/entry4', 1);
796
797 $tags = $entry->getTags();
798
799 $this->assertCount(2, $tags);
800
801 $list = [
802 [
803 'url' => 'http://0.0.0.0/entry4',
804 'tags' => 'new tag 1, new tag 2',
805 ],
806 ];
807
808 $this->client->request('POST', '/api/entries/tags/lists?list='.json_encode($list));
809
810 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
811
812 $content = json_decode($this->client->getResponse()->getContent(), true);
813
814 $this->assertInternalType('int', $content[0]['entry']);
815 $this->assertEquals('http://0.0.0.0/entry4', $content[0]['url']);
816
817 $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager')
818 ->getRepository('WallabagCoreBundle:Entry')
819 ->findByUrlAndUserId('http://0.0.0.0/entry4', 1);
820
821 $tags = $entry->getTags();
822 $this->assertCount(4, $tags);
823 }
824
825 public function testDeleteEntriesTagsListAction()
826 {
827 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
828 $entry = new Entry($em->getReference(User::class, 1));
829 $entry->setUrl('http://0.0.0.0/test-entry');
830 $entry->addTag((new Tag())->setLabel('foo-tag'));
831 $entry->addTag((new Tag())->setLabel('bar-tag'));
832 $em->persist($entry);
833 $em->flush();
834
835 $em->clear();
836
837 $list = [
838 [
839 'url' => 'http://0.0.0.0/test-entry',
840 'tags' => 'foo-tag, bar-tag',
841 ],
842 ];
843
844 $this->client->request('DELETE', '/api/entries/tags/list?list='.json_encode($list));
845 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
846
847 $entry = $em->getRepository('WallabagCoreBundle:Entry')->find($entry->getId());
848 $this->assertCount(0, $entry->getTags());
849 }
850
851 public function testPostEntriesListAction()
852 {
853 $list = [
854 'http://www.lemonde.fr/musiques/article/2017/04/23/loin-de-la-politique-le-printemps-de-bourges-retombe-en-enfance_5115862_1654986.html',
855 'http://0.0.0.0/entry2',
856 ];
857
858 $this->client->request('POST', '/api/entries/lists?urls='.json_encode($list));
859
860 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
861
862 $content = json_decode($this->client->getResponse()->getContent(), true);
863
864 $this->assertInternalType('int', $content[0]['entry']);
865 $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']);
866
867 $this->assertInternalType('int', $content[1]['entry']);
868 $this->assertEquals('http://0.0.0.0/entry2', $content[1]['url']);
869 }
870
871 public function testDeleteEntriesListAction()
872 {
873 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
874 $em->persist((new Entry($em->getReference(User::class, 1)))->setUrl('http://0.0.0.0/test-entry1'));
875
876 $em->flush();
877 $em->clear();
878 $list = [
879 'http://0.0.0.0/test-entry1',
880 'http://0.0.0.0/test-entry-not-exist',
881 ];
882
883 $this->client->request('DELETE', '/api/entries/list?urls='.json_encode($list));
884
885 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
886
887 $content = json_decode($this->client->getResponse()->getContent(), true);
888
889 $this->assertTrue($content[0]['entry']);
890 $this->assertEquals('http://0.0.0.0/test-entry1', $content[0]['url']);
891
892 $this->assertFalse($content[1]['entry']);
893 $this->assertEquals('http://0.0.0.0/test-entry-not-exist', $content[1]['url']);
894 }
895
896 public function testLimitBulkAction()
897 {
898 $list = [
899 'http://0.0.0.0/entry1',
900 'http://0.0.0.0/entry1',
901 'http://0.0.0.0/entry1',
902 'http://0.0.0.0/entry1',
903 'http://0.0.0.0/entry1',
904 'http://0.0.0.0/entry1',
905 'http://0.0.0.0/entry1',
906 'http://0.0.0.0/entry1',
907 'http://0.0.0.0/entry1',
908 'http://0.0.0.0/entry1',
909 'http://0.0.0.0/entry1',
910 ];
911
912 $this->client->request('POST', '/api/entries/lists?urls='.json_encode($list));
913
914 $this->assertEquals(400, $this->client->getResponse()->getStatusCode());
915 $this->assertContains('API limit reached', $this->client->getResponse()->getContent());
916 }
767} 917}