diff options
Diffstat (limited to 'tests/Wallabag/ApiBundle')
3 files changed, 64 insertions, 47 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 2a1d2e15..1a41338c 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.'); |
@@ -403,7 +403,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
403 | $entry = $this->client->getContainer() | 403 | $entry = $this->client->getContainer() |
404 | ->get('doctrine.orm.entity_manager') | 404 | ->get('doctrine.orm.entity_manager') |
405 | ->getRepository('WallabagCoreBundle:Entry') | 405 | ->getRepository('WallabagCoreBundle:Entry') |
406 | ->findOneByUser(1, ['id' => 'asc']); | 406 | ->findOneByUser($this->getUserId(), ['id' => 'asc']); |
407 | 407 | ||
408 | if (!$entry) { | 408 | if (!$entry) { |
409 | $this->markTestSkipped('No content found in db.'); | 409 | $this->markTestSkipped('No content found in db.'); |
@@ -447,8 +447,9 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
447 | $this->assertSame(0, $content['is_archived']); | 447 | $this->assertSame(0, $content['is_archived']); |
448 | $this->assertSame(0, $content['is_starred']); | 448 | $this->assertSame(0, $content['is_starred']); |
449 | $this->assertNull($content['starred_at']); | 449 | $this->assertNull($content['starred_at']); |
450 | $this->assertNull($content['archived_at']); | ||
450 | $this->assertSame('New title for my article', $content['title']); | 451 | $this->assertSame('New title for my article', $content['title']); |
451 | $this->assertSame(1, $content['user_id']); | 452 | $this->assertSame($this->getUserId(), $content['user_id']); |
452 | $this->assertCount(2, $content['tags']); | 453 | $this->assertCount(2, $content['tags']); |
453 | $this->assertNull($content['origin_url']); | 454 | $this->assertNull($content['origin_url']); |
454 | $this->assertSame('my content', $content['content']); | 455 | $this->assertSame('my content', $content['content']); |
@@ -463,7 +464,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
463 | public function testPostSameEntry() | 464 | public function testPostSameEntry() |
464 | { | 465 | { |
465 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); | 466 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); |
466 | $entry = new Entry($em->getReference(User::class, 1)); | 467 | $entry = new Entry($em->getReference(User::class, $this->getUserId())); |
467 | $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'); | 468 | $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'); |
468 | $entry->setArchived(true); | 469 | $entry->setArchived(true); |
469 | $entry->addTag((new Tag())->setLabel('google')); | 470 | $entry->addTag((new Tag())->setLabel('google')); |
@@ -542,7 +543,8 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
542 | $this->assertSame(1, $content['is_archived']); | 543 | $this->assertSame(1, $content['is_archived']); |
543 | $this->assertSame(1, $content['is_starred']); | 544 | $this->assertSame(1, $content['is_starred']); |
544 | $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['starred_at']))->getTimestamp()); | 545 | $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['starred_at']))->getTimestamp()); |
545 | $this->assertSame(1, $content['user_id']); | 546 | $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['archived_at']))->getTimestamp()); |
547 | $this->assertSame($this->getUserId(), $content['user_id']); | ||
546 | } | 548 | } |
547 | 549 | ||
548 | public function testPostArchivedAndStarredEntryWithoutQuotes() | 550 | public function testPostArchivedAndStarredEntryWithoutQuotes() |
@@ -591,7 +593,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
591 | $entry = $this->client->getContainer() | 593 | $entry = $this->client->getContainer() |
592 | ->get('doctrine.orm.entity_manager') | 594 | ->get('doctrine.orm.entity_manager') |
593 | ->getRepository('WallabagCoreBundle:Entry') | 595 | ->getRepository('WallabagCoreBundle:Entry') |
594 | ->findOneByUser(1); | 596 | ->findOneByUser($this->getUserId()); |
595 | 597 | ||
596 | if (!$entry) { | 598 | if (!$entry) { |
597 | $this->markTestSkipped('No content found in db.'); | 599 | $this->markTestSkipped('No content found in db.'); |
@@ -618,7 +620,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
618 | $this->assertSame($entry->getUrl(), $content['url']); | 620 | $this->assertSame($entry->getUrl(), $content['url']); |
619 | $this->assertSame('New awesome title', $content['title']); | 621 | $this->assertSame('New awesome title', $content['title']); |
620 | $this->assertGreaterThanOrEqual(1, \count($content['tags']), 'We force only one tag'); | 622 | $this->assertGreaterThanOrEqual(1, \count($content['tags']), 'We force only one tag'); |
621 | $this->assertSame(1, $content['user_id']); | 623 | $this->assertSame($this->getUserId(), $content['user_id']); |
622 | $this->assertSame('de_AT', $content['language']); | 624 | $this->assertSame('de_AT', $content['language']); |
623 | $this->assertSame('http://preview.io/picture.jpg', $content['preview_picture']); | 625 | $this->assertSame('http://preview.io/picture.jpg', $content['preview_picture']); |
624 | $this->assertContains('sponge', $content['published_by']); | 626 | $this->assertContains('sponge', $content['published_by']); |
@@ -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.'); |
@@ -667,7 +669,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
667 | $entry = $this->client->getContainer() | 669 | $entry = $this->client->getContainer() |
668 | ->get('doctrine.orm.entity_manager') | 670 | ->get('doctrine.orm.entity_manager') |
669 | ->getRepository('WallabagCoreBundle:Entry') | 671 | ->getRepository('WallabagCoreBundle:Entry') |
670 | ->findOneByUser(1); | 672 | ->findOneByUser($this->getUserId()); |
671 | 673 | ||
672 | if (!$entry) { | 674 | if (!$entry) { |
673 | $this->markTestSkipped('No content found in db.'); | 675 | $this->markTestSkipped('No content found in db.'); |
@@ -698,7 +700,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
698 | $entry = $this->client->getContainer() | 700 | $entry = $this->client->getContainer() |
699 | ->get('doctrine.orm.entity_manager') | 701 | ->get('doctrine.orm.entity_manager') |
700 | ->getRepository('WallabagCoreBundle:Entry') | 702 | ->getRepository('WallabagCoreBundle:Entry') |
701 | ->findOneByUser(1); | 703 | ->findOneByUser($this->getUserId()); |
702 | 704 | ||
703 | if (!$entry) { | 705 | if (!$entry) { |
704 | $this->markTestSkipped('No content found in db.'); | 706 | $this->markTestSkipped('No content found in db.'); |
@@ -730,7 +732,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
730 | $entry = $this->client->getContainer() | 732 | $entry = $this->client->getContainer() |
731 | ->get('doctrine.orm.entity_manager') | 733 | ->get('doctrine.orm.entity_manager') |
732 | ->getRepository('WallabagCoreBundle:Entry') | 734 | ->getRepository('WallabagCoreBundle:Entry') |
733 | ->findOneByUser(1); | 735 | ->findOneByUser($this->getUserId()); |
734 | 736 | ||
735 | if (!$entry) { | 737 | if (!$entry) { |
736 | $this->markTestSkipped('No content found in db.'); | 738 | $this->markTestSkipped('No content found in db.'); |
@@ -775,7 +777,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
775 | $entry = $this->client->getContainer() | 777 | $entry = $this->client->getContainer() |
776 | ->get('doctrine.orm.entity_manager') | 778 | ->get('doctrine.orm.entity_manager') |
777 | ->getRepository('WallabagCoreBundle:Entry') | 779 | ->getRepository('WallabagCoreBundle:Entry') |
778 | ->findOneByUser(1); | 780 | ->findOneByUser($this->getUserId()); |
779 | 781 | ||
780 | if (!$entry) { | 782 | if (!$entry) { |
781 | $this->markTestSkipped('No content found in db.'); | 783 | $this->markTestSkipped('No content found in db.'); |
@@ -840,7 +842,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
840 | $entry = $this->client->getContainer() | 842 | $entry = $this->client->getContainer() |
841 | ->get('doctrine.orm.entity_manager') | 843 | ->get('doctrine.orm.entity_manager') |
842 | ->getRepository('WallabagCoreBundle:Entry') | 844 | ->getRepository('WallabagCoreBundle:Entry') |
843 | ->findOneBy(['user' => 1, 'isArchived' => true]); | 845 | ->findOneBy(['user' => $this->getUserId(), 'isArchived' => true]); |
844 | 846 | ||
845 | if (!$entry) { | 847 | if (!$entry) { |
846 | $this->markTestSkipped('No content found in db.'); | 848 | $this->markTestSkipped('No content found in db.'); |
@@ -862,7 +864,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
862 | $entry = $this->client->getContainer() | 864 | $entry = $this->client->getContainer() |
863 | ->get('doctrine.orm.entity_manager') | 865 | ->get('doctrine.orm.entity_manager') |
864 | ->getRepository('WallabagCoreBundle:Entry') | 866 | ->getRepository('WallabagCoreBundle:Entry') |
865 | ->findOneBy(['user' => 1, 'isStarred' => true]); | 867 | ->findOneBy(['user' => $this->getUserId(), 'isStarred' => true]); |
866 | 868 | ||
867 | if (!$entry) { | 869 | if (!$entry) { |
868 | $this->markTestSkipped('No content found in db.'); | 870 | $this->markTestSkipped('No content found in db.'); |
@@ -884,7 +886,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
884 | $entry = $this->client->getContainer() | 886 | $entry = $this->client->getContainer() |
885 | ->get('doctrine.orm.entity_manager') | 887 | ->get('doctrine.orm.entity_manager') |
886 | ->getRepository('WallabagCoreBundle:Entry') | 888 | ->getRepository('WallabagCoreBundle:Entry') |
887 | ->findOneBy(['user' => 1, 'isArchived' => true]); | 889 | ->findOneBy(['user' => $this->getUserId(), 'isArchived' => true]); |
888 | 890 | ||
889 | if (!$entry) { | 891 | if (!$entry) { |
890 | $this->markTestSkipped('No content found in db.'); | 892 | $this->markTestSkipped('No content found in db.'); |
@@ -910,7 +912,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
910 | $entry = $this->client->getContainer() | 912 | $entry = $this->client->getContainer() |
911 | ->get('doctrine.orm.entity_manager') | 913 | ->get('doctrine.orm.entity_manager') |
912 | ->getRepository('WallabagCoreBundle:Entry') | 914 | ->getRepository('WallabagCoreBundle:Entry') |
913 | ->findOneBy(['user' => 1, 'isStarred' => true]); | 915 | ->findOneBy(['user' => $this->getUserId(), 'isStarred' => true]); |
914 | 916 | ||
915 | if (!$entry) { | 917 | if (!$entry) { |
916 | $this->markTestSkipped('No content found in db.'); | 918 | $this->markTestSkipped('No content found in db.'); |
@@ -927,32 +929,27 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
927 | $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['starred_at']))->getTimestamp()); | 929 | $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['starred_at']))->getTimestamp()); |
928 | } | 930 | } |
929 | 931 | ||
930 | public function dataForEntriesExistWithUrl() | 932 | public function testGetEntriesExistsWithReturnId() |
931 | { | 933 | { |
932 | return [ | 934 | $this->client->request('GET', '/api/entries/exists?url=http://0.0.0.0/entry2&return_id=1'); |
933 | 'with_id' => [ | 935 | |
934 | 'url' => '/api/entries/exists?url=http://0.0.0.0/entry2&return_id=1', | 936 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); |
935 | 'expectedValue' => 2, | 937 | |
936 | ], | 938 | $content = json_decode($this->client->getResponse()->getContent(), true); |
937 | 'without_id' => [ | 939 | |
938 | 'url' => '/api/entries/exists?url=http://0.0.0.0/entry2', | 940 | // it returns a database id, we don't know it, so we only check it's greater than the lowest possible value |
939 | 'expectedValue' => true, | 941 | $this->assertGreaterThan(1, $content['exists']); |
940 | ], | ||
941 | ]; | ||
942 | } | 942 | } |
943 | 943 | ||
944 | /** | 944 | public function testGetEntriesExistsWithoutReturnId() |
945 | * @dataProvider dataForEntriesExistWithUrl | ||
946 | */ | ||
947 | public function testGetEntriesExists($url, $expectedValue) | ||
948 | { | 945 | { |
949 | $this->client->request('GET', $url); | 946 | $this->client->request('GET', '/api/entries/exists?url=http://0.0.0.0/entry2'); |
950 | 947 | ||
951 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); | 948 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); |
952 | 949 | ||
953 | $content = json_decode($this->client->getResponse()->getContent(), true); | 950 | $content = json_decode($this->client->getResponse()->getContent(), true); |
954 | 951 | ||
955 | $this->assertSame($expectedValue, $content['exists']); | 952 | $this->assertTrue($content['exists']); |
956 | } | 953 | } |
957 | 954 | ||
958 | public function testGetEntriesExistsWithManyUrls() | 955 | public function testGetEntriesExistsWithManyUrls() |
@@ -967,7 +964,8 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
967 | 964 | ||
968 | $this->assertArrayHasKey($url1, $content); | 965 | $this->assertArrayHasKey($url1, $content); |
969 | $this->assertArrayHasKey($url2, $content); | 966 | $this->assertArrayHasKey($url2, $content); |
970 | $this->assertSame(2, $content[$url1]); | 967 | // it returns a database id, we don't know it, so we only check it's greater than the lowest possible value |
968 | $this->assertGreaterThan(1, $content[$url1]); | ||
971 | $this->assertNull($content[$url2]); | 969 | $this->assertNull($content[$url2]); |
972 | } | 970 | } |
973 | 971 | ||
@@ -1009,7 +1007,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
1009 | { | 1007 | { |
1010 | $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') | 1008 | $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') |
1011 | ->getRepository('WallabagCoreBundle:Entry') | 1009 | ->getRepository('WallabagCoreBundle:Entry') |
1012 | ->findByUrlAndUserId('http://0.0.0.0/entry4', 1); | 1010 | ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getUserId()); |
1013 | 1011 | ||
1014 | if (!$entry) { | 1012 | if (!$entry) { |
1015 | $this->markTestSkipped('No content found in db.'); | 1013 | $this->markTestSkipped('No content found in db.'); |
@@ -1045,7 +1043,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
1045 | { | 1043 | { |
1046 | $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') | 1044 | $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') |
1047 | ->getRepository('WallabagCoreBundle:Entry') | 1045 | ->getRepository('WallabagCoreBundle:Entry') |
1048 | ->findByUrlAndUserId('http://0.0.0.0/entry4', 1); | 1046 | ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getUserId()); |
1049 | 1047 | ||
1050 | $tags = $entry->getTags(); | 1048 | $tags = $entry->getTags(); |
1051 | 1049 | ||
@@ -1069,7 +1067,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
1069 | 1067 | ||
1070 | $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') | 1068 | $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') |
1071 | ->getRepository('WallabagCoreBundle:Entry') | 1069 | ->getRepository('WallabagCoreBundle:Entry') |
1072 | ->findByUrlAndUserId('http://0.0.0.0/entry4', 1); | 1070 | ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getUserId()); |
1073 | 1071 | ||
1074 | $tags = $entry->getTags(); | 1072 | $tags = $entry->getTags(); |
1075 | $this->assertCount(4, $tags); | 1073 | $this->assertCount(4, $tags); |
@@ -1089,7 +1087,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
1089 | public function testDeleteEntriesTagsListAction() | 1087 | public function testDeleteEntriesTagsListAction() |
1090 | { | 1088 | { |
1091 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); | 1089 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); |
1092 | $entry = new Entry($em->getReference(User::class, 1)); | 1090 | $entry = new Entry($em->getReference(User::class, $this->getUserId())); |
1093 | $entry->setUrl('http://0.0.0.0/test-entry'); | 1091 | $entry->setUrl('http://0.0.0.0/test-entry'); |
1094 | $entry->addTag((new Tag())->setLabel('foo-tag')); | 1092 | $entry->addTag((new Tag())->setLabel('foo-tag')); |
1095 | $entry->addTag((new Tag())->setLabel('bar-tag')); | 1093 | $entry->addTag((new Tag())->setLabel('bar-tag')); |
@@ -1157,7 +1155,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
1157 | public function testDeleteEntriesListAction() | 1155 | public function testDeleteEntriesListAction() |
1158 | { | 1156 | { |
1159 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); | 1157 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); |
1160 | $em->persist((new Entry($em->getReference(User::class, 1)))->setUrl('http://0.0.0.0/test-entry1')); | 1158 | $em->persist((new Entry($em->getReference(User::class, $this->getUserId())))->setUrl('http://0.0.0.0/test-entry1')); |
1161 | 1159 | ||
1162 | $em->flush(); | 1160 | $em->flush(); |
1163 | $em->clear(); | 1161 | $em->clear(); |
@@ -1215,7 +1213,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
1215 | public function testRePostEntryAndReUsePublishedAt() | 1213 | public function testRePostEntryAndReUsePublishedAt() |
1216 | { | 1214 | { |
1217 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); | 1215 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); |
1218 | $entry = new Entry($em->getReference(User::class, 1)); | 1216 | $entry = new Entry($em->getReference(User::class, $this->getUserId())); |
1219 | $entry->setTitle('Antoine de Caunes : « Je veux avoir le droit de tâtonner »'); | 1217 | $entry->setTitle('Antoine de Caunes : « Je veux avoir le droit de tâtonner »'); |
1220 | $entry->setContent('hihi'); | 1218 | $entry->setContent('hihi'); |
1221 | $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'); | 1219 | $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/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 | } |