aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php3
-rw-r--r--tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php84
-rw-r--r--tests/Wallabag/ApiBundle/WallabagApiTestCase.php19
-rw-r--r--tests/Wallabag/ImportBundle/Command/ImportCommandTest.php4
4 files changed, 63 insertions, 47 deletions
diff --git a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php
index 96474468..537283f2 100644
--- a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php
+++ b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php
@@ -100,8 +100,7 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase
100 $this->assertSame('my quote', $content['quote']); 100 $this->assertSame('my quote', $content['quote']);
101 101
102 /** @var Annotation $annotation */ 102 /** @var Annotation $annotation */
103 $annotation = $this->client->getContainer() 103 $annotation = $em
104 ->get('doctrine.orm.entity_manager')
105 ->getRepository('WallabagAnnotationBundle:Annotation') 104 ->getRepository('WallabagAnnotationBundle:Annotation')
106 ->findLastAnnotationByPageId($entry->getId(), 1); 105 ->findLastAnnotationByPageId($entry->getId(), 1);
107 106
diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
index 6b26376d..176da3cd 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.');
@@ -394,7 +394,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
394 $entry = $this->client->getContainer() 394 $entry = $this->client->getContainer()
395 ->get('doctrine.orm.entity_manager') 395 ->get('doctrine.orm.entity_manager')
396 ->getRepository('WallabagCoreBundle:Entry') 396 ->getRepository('WallabagCoreBundle:Entry')
397 ->findOneByUser(1, ['id' => 'asc']); 397 ->findOneByUser($this->getUserId(), ['id' => 'asc']);
398 398
399 if (!$entry) { 399 if (!$entry) {
400 $this->markTestSkipped('No content found in db.'); 400 $this->markTestSkipped('No content found in db.');
@@ -440,7 +440,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
440 $this->assertNull($content['starred_at']); 440 $this->assertNull($content['starred_at']);
441 $this->assertNull($content['archived_at']); 441 $this->assertNull($content['archived_at']);
442 $this->assertSame('New title for my article', $content['title']); 442 $this->assertSame('New title for my article', $content['title']);
443 $this->assertSame(1, $content['user_id']); 443 $this->assertSame($this->getUserId(), $content['user_id']);
444 $this->assertCount(2, $content['tags']); 444 $this->assertCount(2, $content['tags']);
445 $this->assertNull($content['origin_url']); 445 $this->assertNull($content['origin_url']);
446 $this->assertSame('my content', $content['content']); 446 $this->assertSame('my content', $content['content']);
@@ -455,7 +455,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
455 public function testPostSameEntry() 455 public function testPostSameEntry()
456 { 456 {
457 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); 457 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
458 $entry = new Entry($em->getReference(User::class, 1)); 458 $entry = new Entry($em->getReference(User::class, $this->getUserId()));
459 $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'); 459 $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');
460 $entry->setArchived(true); 460 $entry->setArchived(true);
461 $entry->addTag((new Tag())->setLabel('google')); 461 $entry->addTag((new Tag())->setLabel('google'));
@@ -535,7 +535,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
535 $this->assertSame(1, $content['is_starred']); 535 $this->assertSame(1, $content['is_starred']);
536 $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['starred_at']))->getTimestamp()); 536 $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['starred_at']))->getTimestamp());
537 $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['archived_at']))->getTimestamp()); 537 $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['archived_at']))->getTimestamp());
538 $this->assertSame(1, $content['user_id']); 538 $this->assertSame($this->getUserId(), $content['user_id']);
539 } 539 }
540 540
541 public function testPostArchivedAndStarredEntryWithoutQuotes() 541 public function testPostArchivedAndStarredEntryWithoutQuotes()
@@ -584,7 +584,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
584 $entry = $this->client->getContainer() 584 $entry = $this->client->getContainer()
585 ->get('doctrine.orm.entity_manager') 585 ->get('doctrine.orm.entity_manager')
586 ->getRepository('WallabagCoreBundle:Entry') 586 ->getRepository('WallabagCoreBundle:Entry')
587 ->findOneByUser(1); 587 ->findOneByUser($this->getUserId());
588 588
589 if (!$entry) { 589 if (!$entry) {
590 $this->markTestSkipped('No content found in db.'); 590 $this->markTestSkipped('No content found in db.');
@@ -611,7 +611,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
611 $this->assertSame($entry->getUrl(), $content['url']); 611 $this->assertSame($entry->getUrl(), $content['url']);
612 $this->assertSame('New awesome title', $content['title']); 612 $this->assertSame('New awesome title', $content['title']);
613 $this->assertGreaterThanOrEqual(1, \count($content['tags']), 'We force only one tag'); 613 $this->assertGreaterThanOrEqual(1, \count($content['tags']), 'We force only one tag');
614 $this->assertSame(1, $content['user_id']); 614 $this->assertSame($this->getUserId(), $content['user_id']);
615 $this->assertSame('de_AT', $content['language']); 615 $this->assertSame('de_AT', $content['language']);
616 $this->assertSame('http://preview.io/picture.jpg', $content['preview_picture']); 616 $this->assertSame('http://preview.io/picture.jpg', $content['preview_picture']);
617 $this->assertContains('sponge', $content['published_by']); 617 $this->assertContains('sponge', $content['published_by']);
@@ -626,7 +626,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
626 $entry = $this->client->getContainer() 626 $entry = $this->client->getContainer()
627 ->get('doctrine.orm.entity_manager') 627 ->get('doctrine.orm.entity_manager')
628 ->getRepository('WallabagCoreBundle:Entry') 628 ->getRepository('WallabagCoreBundle:Entry')
629 ->findOneByUser(1); 629 ->findOneByUser($this->getUserId());
630 630
631 if (!$entry) { 631 if (!$entry) {
632 $this->markTestSkipped('No content found in db.'); 632 $this->markTestSkipped('No content found in db.');
@@ -660,7 +660,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
660 $entry = $this->client->getContainer() 660 $entry = $this->client->getContainer()
661 ->get('doctrine.orm.entity_manager') 661 ->get('doctrine.orm.entity_manager')
662 ->getRepository('WallabagCoreBundle:Entry') 662 ->getRepository('WallabagCoreBundle:Entry')
663 ->findOneByUser(1); 663 ->findOneByUser($this->getUserId());
664 664
665 if (!$entry) { 665 if (!$entry) {
666 $this->markTestSkipped('No content found in db.'); 666 $this->markTestSkipped('No content found in db.');
@@ -691,7 +691,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
691 $entry = $this->client->getContainer() 691 $entry = $this->client->getContainer()
692 ->get('doctrine.orm.entity_manager') 692 ->get('doctrine.orm.entity_manager')
693 ->getRepository('WallabagCoreBundle:Entry') 693 ->getRepository('WallabagCoreBundle:Entry')
694 ->findOneByUser(1); 694 ->findOneByUser($this->getUserId());
695 695
696 if (!$entry) { 696 if (!$entry) {
697 $this->markTestSkipped('No content found in db.'); 697 $this->markTestSkipped('No content found in db.');
@@ -723,7 +723,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
723 $entry = $this->client->getContainer() 723 $entry = $this->client->getContainer()
724 ->get('doctrine.orm.entity_manager') 724 ->get('doctrine.orm.entity_manager')
725 ->getRepository('WallabagCoreBundle:Entry') 725 ->getRepository('WallabagCoreBundle:Entry')
726 ->findOneByUser(1); 726 ->findOneByUser($this->getUserId());
727 727
728 if (!$entry) { 728 if (!$entry) {
729 $this->markTestSkipped('No content found in db.'); 729 $this->markTestSkipped('No content found in db.');
@@ -768,7 +768,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
768 $entry = $this->client->getContainer() 768 $entry = $this->client->getContainer()
769 ->get('doctrine.orm.entity_manager') 769 ->get('doctrine.orm.entity_manager')
770 ->getRepository('WallabagCoreBundle:Entry') 770 ->getRepository('WallabagCoreBundle:Entry')
771 ->findOneByUser(1); 771 ->findOneByUser($this->getUserId());
772 772
773 if (!$entry) { 773 if (!$entry) {
774 $this->markTestSkipped('No content found in db.'); 774 $this->markTestSkipped('No content found in db.');
@@ -833,7 +833,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
833 $entry = $this->client->getContainer() 833 $entry = $this->client->getContainer()
834 ->get('doctrine.orm.entity_manager') 834 ->get('doctrine.orm.entity_manager')
835 ->getRepository('WallabagCoreBundle:Entry') 835 ->getRepository('WallabagCoreBundle:Entry')
836 ->findOneBy(['user' => 1, 'isArchived' => true]); 836 ->findOneBy(['user' => $this->getUserId(), 'isArchived' => true]);
837 837
838 if (!$entry) { 838 if (!$entry) {
839 $this->markTestSkipped('No content found in db.'); 839 $this->markTestSkipped('No content found in db.');
@@ -855,7 +855,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
855 $entry = $this->client->getContainer() 855 $entry = $this->client->getContainer()
856 ->get('doctrine.orm.entity_manager') 856 ->get('doctrine.orm.entity_manager')
857 ->getRepository('WallabagCoreBundle:Entry') 857 ->getRepository('WallabagCoreBundle:Entry')
858 ->findOneBy(['user' => 1, 'isStarred' => true]); 858 ->findOneBy(['user' => $this->getUserId(), 'isStarred' => true]);
859 859
860 if (!$entry) { 860 if (!$entry) {
861 $this->markTestSkipped('No content found in db.'); 861 $this->markTestSkipped('No content found in db.');
@@ -877,7 +877,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
877 $entry = $this->client->getContainer() 877 $entry = $this->client->getContainer()
878 ->get('doctrine.orm.entity_manager') 878 ->get('doctrine.orm.entity_manager')
879 ->getRepository('WallabagCoreBundle:Entry') 879 ->getRepository('WallabagCoreBundle:Entry')
880 ->findOneBy(['user' => 1, 'isArchived' => true]); 880 ->findOneBy(['user' => $this->getUserId(), 'isArchived' => true]);
881 881
882 if (!$entry) { 882 if (!$entry) {
883 $this->markTestSkipped('No content found in db.'); 883 $this->markTestSkipped('No content found in db.');
@@ -903,7 +903,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
903 $entry = $this->client->getContainer() 903 $entry = $this->client->getContainer()
904 ->get('doctrine.orm.entity_manager') 904 ->get('doctrine.orm.entity_manager')
905 ->getRepository('WallabagCoreBundle:Entry') 905 ->getRepository('WallabagCoreBundle:Entry')
906 ->findOneBy(['user' => 1, 'isStarred' => true]); 906 ->findOneBy(['user' => $this->getUserId(), 'isStarred' => true]);
907 907
908 if (!$entry) { 908 if (!$entry) {
909 $this->markTestSkipped('No content found in db.'); 909 $this->markTestSkipped('No content found in db.');
@@ -920,32 +920,27 @@ class EntryRestControllerTest extends WallabagApiTestCase
920 $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['starred_at']))->getTimestamp()); 920 $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['starred_at']))->getTimestamp());
921 } 921 }
922 922
923 public function dataForEntriesExistWithUrl() 923 public function testGetEntriesExistsWithReturnId()
924 { 924 {
925 return [ 925 $this->client->request('GET', '/api/entries/exists?url=http://0.0.0.0/entry2&return_id=1');
926 'with_id' => [ 926
927 'url' => '/api/entries/exists?url=http://0.0.0.0/entry2&return_id=1', 927 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
928 'expectedValue' => 2, 928
929 ], 929 $content = json_decode($this->client->getResponse()->getContent(), true);
930 'without_id' => [ 930
931 'url' => '/api/entries/exists?url=http://0.0.0.0/entry2', 931 // it returns a database id, we don't know it, so we only check it's greater than the lowest possible value
932 'expectedValue' => true, 932 $this->assertGreaterThan(1, $content['exists']);
933 ],
934 ];
935 } 933 }
936 934
937 /** 935 public function testGetEntriesExistsWithoutReturnId()
938 * @dataProvider dataForEntriesExistWithUrl
939 */
940 public function testGetEntriesExists($url, $expectedValue)
941 { 936 {
942 $this->client->request('GET', $url); 937 $this->client->request('GET', '/api/entries/exists?url=http://0.0.0.0/entry2');
943 938
944 $this->assertSame(200, $this->client->getResponse()->getStatusCode()); 939 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
945 940
946 $content = json_decode($this->client->getResponse()->getContent(), true); 941 $content = json_decode($this->client->getResponse()->getContent(), true);
947 942
948 $this->assertSame($expectedValue, $content['exists']); 943 $this->assertSame(true, $content['exists']);
949 } 944 }
950 945
951 public function testGetEntriesExistsWithManyUrls() 946 public function testGetEntriesExistsWithManyUrls()
@@ -960,7 +955,8 @@ class EntryRestControllerTest extends WallabagApiTestCase
960 955
961 $this->assertArrayHasKey($url1, $content); 956 $this->assertArrayHasKey($url1, $content);
962 $this->assertArrayHasKey($url2, $content); 957 $this->assertArrayHasKey($url2, $content);
963 $this->assertSame(2, $content[$url1]); 958 // it returns a database id, we don't know it, so we only check it's greater than the lowest possible value
959 $this->assertGreaterThan(1, $content[$url1]);
964 $this->assertNull($content[$url2]); 960 $this->assertNull($content[$url2]);
965 } 961 }
966 962
@@ -1002,7 +998,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
1002 { 998 {
1003 $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') 999 $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager')
1004 ->getRepository('WallabagCoreBundle:Entry') 1000 ->getRepository('WallabagCoreBundle:Entry')
1005 ->findByUrlAndUserId('http://0.0.0.0/entry4', 1); 1001 ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getUserId());
1006 1002
1007 if (!$entry) { 1003 if (!$entry) {
1008 $this->markTestSkipped('No content found in db.'); 1004 $this->markTestSkipped('No content found in db.');
@@ -1038,7 +1034,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
1038 { 1034 {
1039 $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') 1035 $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager')
1040 ->getRepository('WallabagCoreBundle:Entry') 1036 ->getRepository('WallabagCoreBundle:Entry')
1041 ->findByUrlAndUserId('http://0.0.0.0/entry4', 1); 1037 ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getUserId());
1042 1038
1043 $tags = $entry->getTags(); 1039 $tags = $entry->getTags();
1044 1040
@@ -1062,7 +1058,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
1062 1058
1063 $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') 1059 $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager')
1064 ->getRepository('WallabagCoreBundle:Entry') 1060 ->getRepository('WallabagCoreBundle:Entry')
1065 ->findByUrlAndUserId('http://0.0.0.0/entry4', 1); 1061 ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getUserId());
1066 1062
1067 $tags = $entry->getTags(); 1063 $tags = $entry->getTags();
1068 $this->assertCount(4, $tags); 1064 $this->assertCount(4, $tags);
@@ -1082,7 +1078,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
1082 public function testDeleteEntriesTagsListAction() 1078 public function testDeleteEntriesTagsListAction()
1083 { 1079 {
1084 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); 1080 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
1085 $entry = new Entry($em->getReference(User::class, 1)); 1081 $entry = new Entry($em->getReference(User::class, $this->getUserId()));
1086 $entry->setUrl('http://0.0.0.0/test-entry'); 1082 $entry->setUrl('http://0.0.0.0/test-entry');
1087 $entry->addTag((new Tag())->setLabel('foo-tag')); 1083 $entry->addTag((new Tag())->setLabel('foo-tag'));
1088 $entry->addTag((new Tag())->setLabel('bar-tag')); 1084 $entry->addTag((new Tag())->setLabel('bar-tag'));
@@ -1150,7 +1146,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
1150 public function testDeleteEntriesListAction() 1146 public function testDeleteEntriesListAction()
1151 { 1147 {
1152 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); 1148 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
1153 $em->persist((new Entry($em->getReference(User::class, 1)))->setUrl('http://0.0.0.0/test-entry1')); 1149 $em->persist((new Entry($em->getReference(User::class, $this->getUserId())))->setUrl('http://0.0.0.0/test-entry1'));
1154 1150
1155 $em->flush(); 1151 $em->flush();
1156 $em->clear(); 1152 $em->clear();
@@ -1208,7 +1204,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
1208 public function testRePostEntryAndReUsePublishedAt() 1204 public function testRePostEntryAndReUsePublishedAt()
1209 { 1205 {
1210 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); 1206 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
1211 $entry = new Entry($em->getReference(User::class, 1)); 1207 $entry = new Entry($em->getReference(User::class, $this->getUserId()));
1212 $entry->setTitle('Antoine de Caunes : « Je veux avoir le droit de tâtonner »'); 1208 $entry->setTitle('Antoine de Caunes : « Je veux avoir le droit de tâtonner »');
1213 $entry->setContent('hihi'); 1209 $entry->setContent('hihi');
1214 $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'); 1210 $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 0c52aea0..a0f2f889 100644
--- a/tests/Wallabag/ApiBundle/WallabagApiTestCase.php
+++ b/tests/Wallabag/ApiBundle/WallabagApiTestCase.php
@@ -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 public 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}
diff --git a/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php b/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php
index f95320a4..8e1c528d 100644
--- a/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php
+++ b/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php
@@ -84,6 +84,8 @@ class ImportCommandTest extends WallabagCoreTestCase
84 84
85 public function testRunImportCommandWithUserId() 85 public function testRunImportCommandWithUserId()
86 { 86 {
87 $this->logInAs('admin');
88
87 $application = new Application($this->getClient()->getKernel()); 89 $application = new Application($this->getClient()->getKernel());
88 $application->add(new ImportCommand()); 90 $application->add(new ImportCommand());
89 91
@@ -92,7 +94,7 @@ class ImportCommandTest extends WallabagCoreTestCase
92 $tester = new CommandTester($command); 94 $tester = new CommandTester($command);
93 $tester->execute([ 95 $tester->execute([
94 'command' => $command->getName(), 96 'command' => $command->getName(),
95 'username' => 1, 97 'username' => $this->getLoggedInUserId(),
96 'filepath' => $application->getKernel()->getContainer()->getParameter('kernel.project_dir') . '/tests/Wallabag/ImportBundle/fixtures/wallabag-v2-read.json', 98 'filepath' => $application->getKernel()->getContainer()->getParameter('kernel.project_dir') . '/tests/Wallabag/ImportBundle/fixtures/wallabag-v2-read.json',
97 '--useUserId' => true, 99 '--useUserId' => true,
98 '--importer' => 'v2', 100 '--importer' => 'v2',