diff options
Diffstat (limited to 'tests/Wallabag/ApiBundle')
5 files changed, 200 insertions, 31 deletions
diff --git a/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php b/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php index e1a0ac7e..5586c70d 100644 --- a/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php | |||
@@ -135,7 +135,7 @@ class DeveloperControllerTest extends WallabagCoreTestCase | |||
135 | { | 135 | { |
136 | $client = $this->getClient(); | 136 | $client = $this->getClient(); |
137 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | 137 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); |
138 | $userManager = $client->getContainer()->get('fos_user.user_manager'); | 138 | $userManager = $client->getContainer()->get('fos_user.user_manager.test'); |
139 | $user = $userManager->findUserBy(['username' => $username]); | 139 | $user = $userManager->findUserBy(['username' => $username]); |
140 | $apiClient = new Client($user); | 140 | $apiClient = new Client($user); |
141 | $apiClient->setName('My app'); | 141 | $apiClient->setName('My app'); |
diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 46b5f460..8cc12ed3 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | |||
@@ -15,7 +15,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
15 | $entry = $this->client->getContainer() | 15 | $entry = $this->client->getContainer() |
16 | ->get('doctrine.orm.entity_manager') | 16 | ->get('doctrine.orm.entity_manager') |
17 | ->getRepository('WallabagCoreBundle:Entry') | 17 | ->getRepository('WallabagCoreBundle:Entry') |
18 | ->findOneBy(['user' => 1, 'isArchived' => false]); | 18 | ->findOneBy(['user' => $this->getUserId(), 'isArchived' => false]); |
19 | 19 | ||
20 | if (!$entry) { | 20 | if (!$entry) { |
21 | $this->markTestSkipped('No content found in db.'); | 21 | $this->markTestSkipped('No content found in db.'); |
@@ -41,7 +41,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
41 | $entry = $this->client->getContainer() | 41 | $entry = $this->client->getContainer() |
42 | ->get('doctrine.orm.entity_manager') | 42 | ->get('doctrine.orm.entity_manager') |
43 | ->getRepository('WallabagCoreBundle:Entry') | 43 | ->getRepository('WallabagCoreBundle:Entry') |
44 | ->findOneBy(['user' => 1, 'url' => 'http://0.0.0.0/entry2']); | 44 | ->findOneBy(['user' => $this->getUserId(), 'url' => 'http://0.0.0.0/entry2']); |
45 | 45 | ||
46 | if (!$entry) { | 46 | if (!$entry) { |
47 | $this->markTestSkipped('No content found in db.'); | 47 | $this->markTestSkipped('No content found in db.'); |
@@ -60,7 +60,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
60 | $entry = $this->client->getContainer() | 60 | $entry = $this->client->getContainer() |
61 | ->get('doctrine.orm.entity_manager') | 61 | ->get('doctrine.orm.entity_manager') |
62 | ->getRepository('WallabagCoreBundle:Entry') | 62 | ->getRepository('WallabagCoreBundle:Entry') |
63 | ->findOneBy(['user' => 1, 'isArchived' => false]); | 63 | ->findOneBy(['user' => $this->getUserId(), 'isArchived' => false]); |
64 | 64 | ||
65 | if (!$entry) { | 65 | if (!$entry) { |
66 | $this->markTestSkipped('No content found in db.'); | 66 | $this->markTestSkipped('No content found in db.'); |
@@ -108,7 +108,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
108 | $entry = $this->client->getContainer() | 108 | $entry = $this->client->getContainer() |
109 | ->get('doctrine.orm.entity_manager') | 109 | ->get('doctrine.orm.entity_manager') |
110 | ->getRepository('WallabagCoreBundle:Entry') | 110 | ->getRepository('WallabagCoreBundle:Entry') |
111 | ->findOneBy(['user' => 2, 'isArchived' => false]); | 111 | ->findOneBy(['user' => $this->getUserId('bob'), 'isArchived' => false]); |
112 | 112 | ||
113 | if (!$entry) { | 113 | if (!$entry) { |
114 | $this->markTestSkipped('No content found in db.'); | 114 | $this->markTestSkipped('No content found in db.'); |
@@ -185,7 +185,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
185 | $entry = $this->client->getContainer() | 185 | $entry = $this->client->getContainer() |
186 | ->get('doctrine.orm.entity_manager') | 186 | ->get('doctrine.orm.entity_manager') |
187 | ->getRepository('WallabagCoreBundle:Entry') | 187 | ->getRepository('WallabagCoreBundle:Entry') |
188 | ->findOneByUser(1); | 188 | ->findOneByUser($this->getUserId()); |
189 | 189 | ||
190 | if (!$entry) { | 190 | if (!$entry) { |
191 | $this->markTestSkipped('No content found in db.'); | 191 | $this->markTestSkipped('No content found in db.'); |
@@ -489,8 +489,9 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
489 | $this->assertSame(0, $content['is_archived']); | 489 | $this->assertSame(0, $content['is_archived']); |
490 | $this->assertSame(0, $content['is_starred']); | 490 | $this->assertSame(0, $content['is_starred']); |
491 | $this->assertNull($content['starred_at']); | 491 | $this->assertNull($content['starred_at']); |
492 | $this->assertNull($content['archived_at']); | ||
492 | $this->assertSame('New title for my article', $content['title']); | 493 | $this->assertSame('New title for my article', $content['title']); |
493 | $this->assertSame(1, $content['user_id']); | 494 | $this->assertSame($this->getUserId(), $content['user_id']); |
494 | $this->assertCount(2, $content['tags']); | 495 | $this->assertCount(2, $content['tags']); |
495 | $this->assertNull($content['origin_url']); | 496 | $this->assertNull($content['origin_url']); |
496 | $this->assertSame('my content', $content['content']); | 497 | $this->assertSame('my content', $content['content']); |
@@ -505,7 +506,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
505 | public function testPostSameEntry() | 506 | public function testPostSameEntry() |
506 | { | 507 | { |
507 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); | 508 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); |
508 | $entry = new Entry($em->getReference(User::class, 1)); | 509 | $entry = new Entry($em->getReference(User::class, $this->getUserId())); |
509 | $entry->setUrl('https://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'); | 510 | $entry->setUrl('https://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'); |
510 | $entry->setArchived(true); | 511 | $entry->setArchived(true); |
511 | $entry->addTag((new Tag())->setLabel('google')); | 512 | $entry->addTag((new Tag())->setLabel('google')); |
@@ -584,7 +585,8 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
584 | $this->assertSame(1, $content['is_archived']); | 585 | $this->assertSame(1, $content['is_archived']); |
585 | $this->assertSame(1, $content['is_starred']); | 586 | $this->assertSame(1, $content['is_starred']); |
586 | $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['starred_at']))->getTimestamp()); | 587 | $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['starred_at']))->getTimestamp()); |
587 | $this->assertSame(1, $content['user_id']); | 588 | $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['archived_at']))->getTimestamp()); |
589 | $this->assertSame($this->getUserId(), $content['user_id']); | ||
588 | } | 590 | } |
589 | 591 | ||
590 | public function testPostArchivedAndStarredEntryWithoutQuotes() | 592 | public function testPostArchivedAndStarredEntryWithoutQuotes() |
@@ -633,7 +635,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
633 | $entry = $this->client->getContainer() | 635 | $entry = $this->client->getContainer() |
634 | ->get('doctrine.orm.entity_manager') | 636 | ->get('doctrine.orm.entity_manager') |
635 | ->getRepository('WallabagCoreBundle:Entry') | 637 | ->getRepository('WallabagCoreBundle:Entry') |
636 | ->findOneByUser(1); | 638 | ->findOneByUser($this->getUserId()); |
637 | 639 | ||
638 | if (!$entry) { | 640 | if (!$entry) { |
639 | $this->markTestSkipped('No content found in db.'); | 641 | $this->markTestSkipped('No content found in db.'); |
@@ -660,7 +662,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
660 | $this->assertSame($entry->getUrl(), $content['url']); | 662 | $this->assertSame($entry->getUrl(), $content['url']); |
661 | $this->assertSame('New awesome title', $content['title']); | 663 | $this->assertSame('New awesome title', $content['title']); |
662 | $this->assertGreaterThanOrEqual(1, \count($content['tags']), 'We force only one tag'); | 664 | $this->assertGreaterThanOrEqual(1, \count($content['tags']), 'We force only one tag'); |
663 | $this->assertSame(1, $content['user_id']); | 665 | $this->assertSame($this->getUserId(), $content['user_id']); |
664 | $this->assertSame('de_AT', $content['language']); | 666 | $this->assertSame('de_AT', $content['language']); |
665 | $this->assertSame('http://preview.io/picture.jpg', $content['preview_picture']); | 667 | $this->assertSame('http://preview.io/picture.jpg', $content['preview_picture']); |
666 | $this->assertContains('sponge', $content['published_by']); | 668 | $this->assertContains('sponge', $content['published_by']); |
@@ -675,7 +677,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
675 | $entry = $this->client->getContainer() | 677 | $entry = $this->client->getContainer() |
676 | ->get('doctrine.orm.entity_manager') | 678 | ->get('doctrine.orm.entity_manager') |
677 | ->getRepository('WallabagCoreBundle:Entry') | 679 | ->getRepository('WallabagCoreBundle:Entry') |
678 | ->findOneByUser(1); | 680 | ->findOneByUser($this->getUserId()); |
679 | 681 | ||
680 | if (!$entry) { | 682 | if (!$entry) { |
681 | $this->markTestSkipped('No content found in db.'); | 683 | $this->markTestSkipped('No content found in db.'); |
@@ -709,7 +711,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
709 | $entry = $this->client->getContainer() | 711 | $entry = $this->client->getContainer() |
710 | ->get('doctrine.orm.entity_manager') | 712 | ->get('doctrine.orm.entity_manager') |
711 | ->getRepository('WallabagCoreBundle:Entry') | 713 | ->getRepository('WallabagCoreBundle:Entry') |
712 | ->findOneByUser(1); | 714 | ->findOneByUser($this->getUserId()); |
713 | 715 | ||
714 | if (!$entry) { | 716 | if (!$entry) { |
715 | $this->markTestSkipped('No content found in db.'); | 717 | $this->markTestSkipped('No content found in db.'); |
@@ -740,7 +742,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
740 | $entry = $this->client->getContainer() | 742 | $entry = $this->client->getContainer() |
741 | ->get('doctrine.orm.entity_manager') | 743 | ->get('doctrine.orm.entity_manager') |
742 | ->getRepository('WallabagCoreBundle:Entry') | 744 | ->getRepository('WallabagCoreBundle:Entry') |
743 | ->findOneByUser(1); | 745 | ->findOneByUser($this->getUserId()); |
744 | 746 | ||
745 | if (!$entry) { | 747 | if (!$entry) { |
746 | $this->markTestSkipped('No content found in db.'); | 748 | $this->markTestSkipped('No content found in db.'); |
@@ -772,7 +774,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
772 | $entry = $this->client->getContainer() | 774 | $entry = $this->client->getContainer() |
773 | ->get('doctrine.orm.entity_manager') | 775 | ->get('doctrine.orm.entity_manager') |
774 | ->getRepository('WallabagCoreBundle:Entry') | 776 | ->getRepository('WallabagCoreBundle:Entry') |
775 | ->findOneByUser(1); | 777 | ->findOneByUser($this->getUserId()); |
776 | 778 | ||
777 | if (!$entry) { | 779 | if (!$entry) { |
778 | $this->markTestSkipped('No content found in db.'); | 780 | $this->markTestSkipped('No content found in db.'); |
@@ -817,7 +819,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
817 | $entry = $this->client->getContainer() | 819 | $entry = $this->client->getContainer() |
818 | ->get('doctrine.orm.entity_manager') | 820 | ->get('doctrine.orm.entity_manager') |
819 | ->getRepository('WallabagCoreBundle:Entry') | 821 | ->getRepository('WallabagCoreBundle:Entry') |
820 | ->findOneByUser(1); | 822 | ->findOneByUser($this->getUserId()); |
821 | 823 | ||
822 | if (!$entry) { | 824 | if (!$entry) { |
823 | $this->markTestSkipped('No content found in db.'); | 825 | $this->markTestSkipped('No content found in db.'); |
@@ -834,7 +836,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
834 | $content = json_decode($this->client->getResponse()->getContent(), true); | 836 | $content = json_decode($this->client->getResponse()->getContent(), true); |
835 | 837 | ||
836 | $this->assertArrayHasKey('tags', $content); | 838 | $this->assertArrayHasKey('tags', $content); |
837 | $this->assertSame($nbTags + 3, \count($content['tags'])); | 839 | $this->assertCount($nbTags + 3, $content['tags']); |
838 | 840 | ||
839 | $entryDB = $this->client->getContainer() | 841 | $entryDB = $this->client->getContainer() |
840 | ->get('doctrine.orm.entity_manager') | 842 | ->get('doctrine.orm.entity_manager') |
@@ -874,7 +876,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
874 | $content = json_decode($this->client->getResponse()->getContent(), true); | 876 | $content = json_decode($this->client->getResponse()->getContent(), true); |
875 | 877 | ||
876 | $this->assertArrayHasKey('tags', $content); | 878 | $this->assertArrayHasKey('tags', $content); |
877 | $this->assertSame($nbTags - 1, \count($content['tags'])); | 879 | $this->assertCount($nbTags - 1, $content['tags']); |
878 | } | 880 | } |
879 | 881 | ||
880 | public function testSaveIsArchivedAfterPost() | 882 | public function testSaveIsArchivedAfterPost() |
@@ -882,7 +884,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
882 | $entry = $this->client->getContainer() | 884 | $entry = $this->client->getContainer() |
883 | ->get('doctrine.orm.entity_manager') | 885 | ->get('doctrine.orm.entity_manager') |
884 | ->getRepository('WallabagCoreBundle:Entry') | 886 | ->getRepository('WallabagCoreBundle:Entry') |
885 | ->findOneBy(['user' => 1, 'isArchived' => true]); | 887 | ->findOneBy(['user' => $this->getUserId(), 'isArchived' => true]); |
886 | 888 | ||
887 | if (!$entry) { | 889 | if (!$entry) { |
888 | $this->markTestSkipped('No content found in db.'); | 890 | $this->markTestSkipped('No content found in db.'); |
@@ -904,7 +906,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
904 | $entry = $this->client->getContainer() | 906 | $entry = $this->client->getContainer() |
905 | ->get('doctrine.orm.entity_manager') | 907 | ->get('doctrine.orm.entity_manager') |
906 | ->getRepository('WallabagCoreBundle:Entry') | 908 | ->getRepository('WallabagCoreBundle:Entry') |
907 | ->findOneBy(['user' => 1, 'isStarred' => true]); | 909 | ->findOneBy(['user' => $this->getUserId(), 'isStarred' => true]); |
908 | 910 | ||
909 | if (!$entry) { | 911 | if (!$entry) { |
910 | $this->markTestSkipped('No content found in db.'); | 912 | $this->markTestSkipped('No content found in db.'); |
@@ -926,7 +928,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
926 | $entry = $this->client->getContainer() | 928 | $entry = $this->client->getContainer() |
927 | ->get('doctrine.orm.entity_manager') | 929 | ->get('doctrine.orm.entity_manager') |
928 | ->getRepository('WallabagCoreBundle:Entry') | 930 | ->getRepository('WallabagCoreBundle:Entry') |
929 | ->findOneBy(['user' => 1, 'isArchived' => true]); | 931 | ->findOneBy(['user' => $this->getUserId(), 'isArchived' => true]); |
930 | 932 | ||
931 | if (!$entry) { | 933 | if (!$entry) { |
932 | $this->markTestSkipped('No content found in db.'); | 934 | $this->markTestSkipped('No content found in db.'); |
@@ -952,7 +954,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
952 | $entry = $this->client->getContainer() | 954 | $entry = $this->client->getContainer() |
953 | ->get('doctrine.orm.entity_manager') | 955 | ->get('doctrine.orm.entity_manager') |
954 | ->getRepository('WallabagCoreBundle:Entry') | 956 | ->getRepository('WallabagCoreBundle:Entry') |
955 | ->findOneBy(['user' => 1, 'isStarred' => true]); | 957 | ->findOneBy(['user' => $this->getUserId(), 'isStarred' => true]); |
956 | 958 | ||
957 | if (!$entry) { | 959 | if (!$entry) { |
958 | $this->markTestSkipped('No content found in db.'); | 960 | $this->markTestSkipped('No content found in db.'); |
@@ -971,6 +973,8 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
971 | 973 | ||
972 | public function dataForEntriesExistWithUrl() | 974 | public function dataForEntriesExistWithUrl() |
973 | { | 975 | { |
976 | $url = hash('sha1', 'http://0.0.0.0/entry2'); | ||
977 | |||
974 | return [ | 978 | return [ |
975 | 'with_id' => [ | 979 | 'with_id' => [ |
976 | 'url' => '/api/entries/exists?url=http://0.0.0.0/entry2&return_id=1', | 980 | 'url' => '/api/entries/exists?url=http://0.0.0.0/entry2&return_id=1', |
@@ -980,6 +984,14 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
980 | 'url' => '/api/entries/exists?url=http://0.0.0.0/entry2', | 984 | 'url' => '/api/entries/exists?url=http://0.0.0.0/entry2', |
981 | 'expectedValue' => true, | 985 | 'expectedValue' => true, |
982 | ], | 986 | ], |
987 | 'hashed_url_with_id' => [ | ||
988 | 'url' => '/api/entries/exists?hashed_url=' . $url . '&return_id=1', | ||
989 | 'expectedValue' => 2, | ||
990 | ], | ||
991 | 'hashed_url_without_id' => [ | ||
992 | 'url' => '/api/entries/exists?hashed_url=' . $url . '', | ||
993 | 'expectedValue' => true, | ||
994 | ], | ||
983 | ]; | 995 | ]; |
984 | } | 996 | } |
985 | 997 | ||
@@ -1001,6 +1013,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
1001 | { | 1013 | { |
1002 | $url1 = 'http://0.0.0.0/entry2'; | 1014 | $url1 = 'http://0.0.0.0/entry2'; |
1003 | $url2 = 'http://0.0.0.0/entry10'; | 1015 | $url2 = 'http://0.0.0.0/entry10'; |
1016 | |||
1004 | $this->client->request('GET', '/api/entries/exists?urls[]=' . $url1 . '&urls[]=' . $url2 . '&return_id=1'); | 1017 | $this->client->request('GET', '/api/entries/exists?urls[]=' . $url1 . '&urls[]=' . $url2 . '&return_id=1'); |
1005 | 1018 | ||
1006 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); | 1019 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); |
@@ -1009,7 +1022,8 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
1009 | 1022 | ||
1010 | $this->assertArrayHasKey($url1, $content); | 1023 | $this->assertArrayHasKey($url1, $content); |
1011 | $this->assertArrayHasKey($url2, $content); | 1024 | $this->assertArrayHasKey($url2, $content); |
1012 | $this->assertSame(2, $content[$url1]); | 1025 | // it returns a database id, we don't know it, so we only check it's greater than the lowest possible value |
1026 | $this->assertGreaterThan(1, $content[$url1]); | ||
1013 | $this->assertNull($content[$url2]); | 1027 | $this->assertNull($content[$url2]); |
1014 | } | 1028 | } |
1015 | 1029 | ||
@@ -1029,6 +1043,38 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
1029 | $this->assertFalse($content[$url2]); | 1043 | $this->assertFalse($content[$url2]); |
1030 | } | 1044 | } |
1031 | 1045 | ||
1046 | public function testGetEntriesExistsWithManyUrlsHashed() | ||
1047 | { | ||
1048 | $url1 = 'http://0.0.0.0/entry2'; | ||
1049 | $url2 = 'http://0.0.0.0/entry10'; | ||
1050 | $this->client->request('GET', '/api/entries/exists?hashed_urls[]=' . hash('sha1', $url1) . '&hashed_urls[]=' . hash('sha1', $url2) . '&return_id=1'); | ||
1051 | |||
1052 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); | ||
1053 | |||
1054 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
1055 | |||
1056 | $this->assertArrayHasKey(hash('sha1', $url1), $content); | ||
1057 | $this->assertArrayHasKey(hash('sha1', $url2), $content); | ||
1058 | $this->assertSame(2, $content[hash('sha1', $url1)]); | ||
1059 | $this->assertNull($content[hash('sha1', $url2)]); | ||
1060 | } | ||
1061 | |||
1062 | public function testGetEntriesExistsWithManyUrlsHashedReturnBool() | ||
1063 | { | ||
1064 | $url1 = 'http://0.0.0.0/entry2'; | ||
1065 | $url2 = 'http://0.0.0.0/entry10'; | ||
1066 | $this->client->request('GET', '/api/entries/exists?hashed_urls[]=' . hash('sha1', $url1) . '&hashed_urls[]=' . hash('sha1', $url2)); | ||
1067 | |||
1068 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); | ||
1069 | |||
1070 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
1071 | |||
1072 | $this->assertArrayHasKey(hash('sha1', $url1), $content); | ||
1073 | $this->assertArrayHasKey(hash('sha1', $url2), $content); | ||
1074 | $this->assertTrue($content[hash('sha1', $url1)]); | ||
1075 | $this->assertFalse($content[hash('sha1', $url2)]); | ||
1076 | } | ||
1077 | |||
1032 | public function testGetEntriesExistsWhichDoesNotExists() | 1078 | public function testGetEntriesExistsWhichDoesNotExists() |
1033 | { | 1079 | { |
1034 | $this->client->request('GET', '/api/entries/exists?url=http://google.com/entry2'); | 1080 | $this->client->request('GET', '/api/entries/exists?url=http://google.com/entry2'); |
@@ -1040,6 +1086,17 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
1040 | $this->assertFalse($content['exists']); | 1086 | $this->assertFalse($content['exists']); |
1041 | } | 1087 | } |
1042 | 1088 | ||
1089 | public function testGetEntriesExistsWhichDoesNotExistsWithHashedUrl() | ||
1090 | { | ||
1091 | $this->client->request('GET', '/api/entries/exists?hashed_url=' . hash('sha1', 'http://google.com/entry2')); | ||
1092 | |||
1093 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); | ||
1094 | |||
1095 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
1096 | |||
1097 | $this->assertFalse($content['exists']); | ||
1098 | } | ||
1099 | |||
1043 | public function testGetEntriesExistsWithNoUrl() | 1100 | public function testGetEntriesExistsWithNoUrl() |
1044 | { | 1101 | { |
1045 | $this->client->request('GET', '/api/entries/exists?url='); | 1102 | $this->client->request('GET', '/api/entries/exists?url='); |
@@ -1047,11 +1104,18 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
1047 | $this->assertSame(403, $this->client->getResponse()->getStatusCode()); | 1104 | $this->assertSame(403, $this->client->getResponse()->getStatusCode()); |
1048 | } | 1105 | } |
1049 | 1106 | ||
1107 | public function testGetEntriesExistsWithNoHashedUrl() | ||
1108 | { | ||
1109 | $this->client->request('GET', '/api/entries/exists?hashed_url='); | ||
1110 | |||
1111 | $this->assertSame(403, $this->client->getResponse()->getStatusCode()); | ||
1112 | } | ||
1113 | |||
1050 | public function testReloadEntryErrorWhileFetching() | 1114 | public function testReloadEntryErrorWhileFetching() |
1051 | { | 1115 | { |
1052 | $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') | 1116 | $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') |
1053 | ->getRepository('WallabagCoreBundle:Entry') | 1117 | ->getRepository('WallabagCoreBundle:Entry') |
1054 | ->findByUrlAndUserId('http://0.0.0.0/entry4', 1); | 1118 | ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getUserId()); |
1055 | 1119 | ||
1056 | if (!$entry) { | 1120 | if (!$entry) { |
1057 | $this->markTestSkipped('No content found in db.'); | 1121 | $this->markTestSkipped('No content found in db.'); |
@@ -1087,7 +1151,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
1087 | { | 1151 | { |
1088 | $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') | 1152 | $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') |
1089 | ->getRepository('WallabagCoreBundle:Entry') | 1153 | ->getRepository('WallabagCoreBundle:Entry') |
1090 | ->findByUrlAndUserId('http://0.0.0.0/entry4', 1); | 1154 | ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getUserId()); |
1091 | 1155 | ||
1092 | $tags = $entry->getTags(); | 1156 | $tags = $entry->getTags(); |
1093 | 1157 | ||
@@ -1111,7 +1175,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
1111 | 1175 | ||
1112 | $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') | 1176 | $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') |
1113 | ->getRepository('WallabagCoreBundle:Entry') | 1177 | ->getRepository('WallabagCoreBundle:Entry') |
1114 | ->findByUrlAndUserId('http://0.0.0.0/entry4', 1); | 1178 | ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getUserId()); |
1115 | 1179 | ||
1116 | $tags = $entry->getTags(); | 1180 | $tags = $entry->getTags(); |
1117 | $this->assertCount(4, $tags); | 1181 | $this->assertCount(4, $tags); |
@@ -1131,7 +1195,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
1131 | public function testDeleteEntriesTagsListAction() | 1195 | public function testDeleteEntriesTagsListAction() |
1132 | { | 1196 | { |
1133 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); | 1197 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); |
1134 | $entry = new Entry($em->getReference(User::class, 1)); | 1198 | $entry = new Entry($em->getReference(User::class, $this->getUserId())); |
1135 | $entry->setUrl('http://0.0.0.0/test-entry'); | 1199 | $entry->setUrl('http://0.0.0.0/test-entry'); |
1136 | $entry->addTag((new Tag())->setLabel('foo-tag')); | 1200 | $entry->addTag((new Tag())->setLabel('foo-tag')); |
1137 | $entry->addTag((new Tag())->setLabel('bar-tag')); | 1201 | $entry->addTag((new Tag())->setLabel('bar-tag')); |
@@ -1199,7 +1263,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
1199 | public function testDeleteEntriesListAction() | 1263 | public function testDeleteEntriesListAction() |
1200 | { | 1264 | { |
1201 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); | 1265 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); |
1202 | $em->persist((new Entry($em->getReference(User::class, 1)))->setUrl('http://0.0.0.0/test-entry1')); | 1266 | $em->persist((new Entry($em->getReference(User::class, $this->getUserId())))->setUrl('http://0.0.0.0/test-entry1')); |
1203 | 1267 | ||
1204 | $em->flush(); | 1268 | $em->flush(); |
1205 | $em->clear(); | 1269 | $em->clear(); |
@@ -1257,7 +1321,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
1257 | public function testRePostEntryAndReUsePublishedAt() | 1321 | public function testRePostEntryAndReUsePublishedAt() |
1258 | { | 1322 | { |
1259 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); | 1323 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); |
1260 | $entry = new Entry($em->getReference(User::class, 1)); | 1324 | $entry = new Entry($em->getReference(User::class, $this->getUserId())); |
1261 | $entry->setTitle('Antoine de Caunes : « Je veux avoir le droit de tâtonner »'); | 1325 | $entry->setTitle('Antoine de Caunes : « Je veux avoir le droit de tâtonner »'); |
1262 | $entry->setContent('hihi'); | 1326 | $entry->setContent('hihi'); |
1263 | $entry->setUrl('https://www.lemonde.fr/m-perso/article/2017/06/25/antoine-de-caunes-je-veux-avoir-le-droit-de-tatonner_5150728_4497916.html'); | 1327 | $entry->setUrl('https://www.lemonde.fr/m-perso/article/2017/06/25/antoine-de-caunes-je-veux-avoir-le-droit-de-tatonner_5150728_4497916.html'); |
diff --git a/tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php new file mode 100644 index 00000000..fd524639 --- /dev/null +++ b/tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php | |||
@@ -0,0 +1,69 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\ApiBundle\Controller; | ||
4 | |||
5 | use Tests\Wallabag\ApiBundle\WallabagApiTestCase; | ||
6 | |||
7 | class SearchRestControllerTest extends WallabagApiTestCase | ||
8 | { | ||
9 | public function testGetSearchWithFullOptions() | ||
10 | { | ||
11 | $this->client->request('GET', '/api/search', [ | ||
12 | 'page' => 1, | ||
13 | 'perPage' => 2, | ||
14 | 'term' => 'entry', // 6 results | ||
15 | ]); | ||
16 | |||
17 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); | ||
18 | |||
19 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
20 | |||
21 | $this->assertGreaterThanOrEqual(1, \count($content)); | ||
22 | $this->assertArrayHasKey('items', $content['_embedded']); | ||
23 | $this->assertGreaterThanOrEqual(0, $content['total']); | ||
24 | $this->assertSame(1, $content['page']); | ||
25 | $this->assertSame(2, $content['limit']); | ||
26 | $this->assertGreaterThanOrEqual(1, $content['pages']); | ||
27 | |||
28 | $this->assertArrayHasKey('_links', $content); | ||
29 | $this->assertArrayHasKey('self', $content['_links']); | ||
30 | $this->assertArrayHasKey('first', $content['_links']); | ||
31 | $this->assertArrayHasKey('last', $content['_links']); | ||
32 | |||
33 | foreach (['self', 'first', 'last'] as $link) { | ||
34 | $this->assertArrayHasKey('href', $content['_links'][$link]); | ||
35 | $this->assertContains('term=entry', $content['_links'][$link]['href']); | ||
36 | } | ||
37 | |||
38 | $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); | ||
39 | } | ||
40 | |||
41 | public function testGetSearchWithNoLimit() | ||
42 | { | ||
43 | $this->client->request('GET', '/api/search', [ | ||
44 | 'term' => 'entry', | ||
45 | ]); | ||
46 | |||
47 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); | ||
48 | |||
49 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
50 | |||
51 | $this->assertGreaterThanOrEqual(1, \count($content)); | ||
52 | $this->assertArrayHasKey('items', $content['_embedded']); | ||
53 | $this->assertGreaterThanOrEqual(0, $content['total']); | ||
54 | $this->assertSame(1, $content['page']); | ||
55 | $this->assertGreaterThanOrEqual(1, $content['pages']); | ||
56 | |||
57 | $this->assertArrayHasKey('_links', $content); | ||
58 | $this->assertArrayHasKey('self', $content['_links']); | ||
59 | $this->assertArrayHasKey('first', $content['_links']); | ||
60 | $this->assertArrayHasKey('last', $content['_links']); | ||
61 | |||
62 | foreach (['self', 'first', 'last'] as $link) { | ||
63 | $this->assertArrayHasKey('href', $content['_links'][$link]); | ||
64 | $this->assertContains('term=entry', $content['_links'][$link]['href']); | ||
65 | } | ||
66 | |||
67 | $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); | ||
68 | } | ||
69 | } | ||
diff --git a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php index ac4d6cdc..8b49c0ae 100644 --- a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php | |||
@@ -18,4 +18,21 @@ class WallabagRestControllerTest extends WallabagApiTestCase | |||
18 | 18 | ||
19 | $this->assertSame($client->getContainer()->getParameter('wallabag_core.version'), $content); | 19 | $this->assertSame($client->getContainer()->getParameter('wallabag_core.version'), $content); |
20 | } | 20 | } |
21 | |||
22 | public function testGetInfo() | ||
23 | { | ||
24 | // create a new client instead of using $this->client to be sure client isn't authenticated | ||
25 | $client = static::createClient(); | ||
26 | $client->request('GET', '/api/info'); | ||
27 | |||
28 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
29 | |||
30 | $content = json_decode($client->getResponse()->getContent(), true); | ||
31 | |||
32 | $this->assertArrayHasKey('appname', $content); | ||
33 | $this->assertArrayHasKey('version', $content); | ||
34 | $this->assertArrayHasKey('allowed_registration', $content); | ||
35 | |||
36 | $this->assertSame('wallabag', $content['appname']); | ||
37 | } | ||
21 | } | 38 | } |
diff --git a/tests/Wallabag/ApiBundle/WallabagApiTestCase.php b/tests/Wallabag/ApiBundle/WallabagApiTestCase.php index 8a188e1c..fd2e113e 100644 --- a/tests/Wallabag/ApiBundle/WallabagApiTestCase.php +++ b/tests/Wallabag/ApiBundle/WallabagApiTestCase.php | |||
@@ -31,9 +31,9 @@ abstract class WallabagApiTestCase extends WebTestCase | |||
31 | $container = $client->getContainer(); | 31 | $container = $client->getContainer(); |
32 | 32 | ||
33 | /** @var $userManager \FOS\UserBundle\Doctrine\UserManager */ | 33 | /** @var $userManager \FOS\UserBundle\Doctrine\UserManager */ |
34 | $userManager = $container->get('fos_user.user_manager'); | 34 | $userManager = $container->get('fos_user.user_manager.test'); |
35 | /** @var $loginManager \FOS\UserBundle\Security\LoginManager */ | 35 | /** @var $loginManager \FOS\UserBundle\Security\LoginManager */ |
36 | $loginManager = $container->get('fos_user.security.login_manager'); | 36 | $loginManager = $container->get('fos_user.security.login_manager.test'); |
37 | $firewallName = $container->getParameter('fos_user.firewall_name'); | 37 | $firewallName = $container->getParameter('fos_user.firewall_name'); |
38 | 38 | ||
39 | $this->user = $userManager->findUserBy(['username' => 'admin']); | 39 | $this->user = $userManager->findUserBy(['username' => 'admin']); |
@@ -48,4 +48,23 @@ abstract class WallabagApiTestCase extends WebTestCase | |||
48 | 48 | ||
49 | return $client; | 49 | return $client; |
50 | } | 50 | } |
51 | |||
52 | /** | ||
53 | * Return the ID for the user admin. | ||
54 | * Used because on heavy testing we don't want to re-create the database on each run. | ||
55 | * Which means "admin" user won't have id 1 all the time. | ||
56 | * | ||
57 | * @param string $username | ||
58 | * | ||
59 | * @return int | ||
60 | */ | ||
61 | protected function getUserId($username = 'admin') | ||
62 | { | ||
63 | return $this->client | ||
64 | ->getContainer() | ||
65 | ->get('doctrine.orm.entity_manager') | ||
66 | ->getRepository('WallabagUserBundle:User') | ||
67 | ->findOneByUserName($username) | ||
68 | ->getId(); | ||
69 | } | ||
51 | } | 70 | } |