aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php5
-rw-r--r--tests/Wallabag/AnnotationBundle/WallabagAnnotationTestCase.php4
-rw-r--r--tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php2
-rw-r--r--tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php88
-rw-r--r--tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php69
-rw-r--r--tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php17
-rw-r--r--tests/Wallabag/ApiBundle/WallabagApiTestCase.php23
-rw-r--r--tests/Wallabag/CoreBundle/Command/InstallCommandTest.php18
-rw-r--r--tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php6
-rw-r--r--tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php3
-rw-r--r--tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php120
-rw-r--r--tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php57
-rw-r--r--tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php2
-rw-r--r--tests/Wallabag/CoreBundle/Controller/RssControllerTest.php2
-rw-r--r--tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php28
-rw-r--r--tests/Wallabag/CoreBundle/Controller/TagControllerTest.php45
-rw-r--r--tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php23
-rw-r--r--tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php68
-rw-r--r--tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php14
-rw-r--r--tests/Wallabag/CoreBundle/Helper/RedirectTest.php3
-rw-r--r--tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php2
-rw-r--r--tests/Wallabag/CoreBundle/WallabagCoreTestCase.php4
-rw-r--r--tests/Wallabag/ImportBundle/Command/ImportCommandTest.php4
-rw-r--r--tests/Wallabag/ImportBundle/Consumer/AMQPEntryConsumerTest.php2
-rw-r--r--tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php2
-rw-r--r--tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php2
-rw-r--r--tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php2
-rw-r--r--tests/Wallabag/ImportBundle/Controller/InstapaperControllerTest.php4
-rw-r--r--tests/Wallabag/ImportBundle/Controller/PinboardControllerTest.php2
-rw-r--r--tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php2
-rw-r--r--tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php2
-rw-r--r--tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php4
-rw-r--r--tests/Wallabag/UserBundle/Controller/ManageControllerTest.php2
-rw-r--r--tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php6
-rw-r--r--tests/Wallabag/UserBundle/Mailer/AuthCodeMailerTest.php18
-rw-r--r--tests/Wallabag/UserBundle/Mailer/CountableMemorySpool.php19
36 files changed, 544 insertions, 130 deletions
diff --git a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php
index 96474468..2c46e0a1 100644
--- a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php
+++ b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php
@@ -1,6 +1,6 @@
1<?php 1<?php
2 2
3namespace Tests\AnnotationBundle\Controller; 3namespace Tests\Wallabag\AnnotationBundle\Controller;
4 4
5use Tests\Wallabag\AnnotationBundle\WallabagAnnotationTestCase; 5use Tests\Wallabag\AnnotationBundle\WallabagAnnotationTestCase;
6use Wallabag\AnnotationBundle\Entity\Annotation; 6use Wallabag\AnnotationBundle\Entity\Annotation;
@@ -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/AnnotationBundle/WallabagAnnotationTestCase.php b/tests/Wallabag/AnnotationBundle/WallabagAnnotationTestCase.php
index 105e8add..9c7aba6b 100644
--- a/tests/Wallabag/AnnotationBundle/WallabagAnnotationTestCase.php
+++ b/tests/Wallabag/AnnotationBundle/WallabagAnnotationTestCase.php
@@ -43,9 +43,9 @@ abstract class WallabagAnnotationTestCase extends WebTestCase
43 $container = $client->getContainer(); 43 $container = $client->getContainer();
44 44
45 /** @var $userManager \FOS\UserBundle\Doctrine\UserManager */ 45 /** @var $userManager \FOS\UserBundle\Doctrine\UserManager */
46 $userManager = $container->get('fos_user.user_manager'); 46 $userManager = $container->get('fos_user.user_manager.test');
47 /** @var $loginManager \FOS\UserBundle\Security\LoginManager */ 47 /** @var $loginManager \FOS\UserBundle\Security\LoginManager */
48 $loginManager = $container->get('fos_user.security.login_manager'); 48 $loginManager = $container->get('fos_user.security.login_manager.test');
49 $firewallName = $container->getParameter('fos_user.firewall_name'); 49 $firewallName = $container->getParameter('fos_user.firewall_name');
50 50
51 $this->user = $userManager->findUserBy(['username' => 'admin']); 51 $this->user = $userManager->findUserBy(['username' => 'admin']);
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..2151f587 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.');
@@ -969,32 +971,27 @@ class EntryRestControllerTest extends WallabagApiTestCase
969 $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['starred_at']))->getTimestamp()); 971 $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['starred_at']))->getTimestamp());
970 } 972 }
971 973
972 public function dataForEntriesExistWithUrl() 974 public function testGetEntriesExistsWithReturnId()
973 { 975 {
974 return [ 976 $this->client->request('GET', '/api/entries/exists?url=http://0.0.0.0/entry2&return_id=1');
975 'with_id' => [ 977
976 'url' => '/api/entries/exists?url=http://0.0.0.0/entry2&return_id=1', 978 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
977 'expectedValue' => 2, 979
978 ], 980 $content = json_decode($this->client->getResponse()->getContent(), true);
979 'without_id' => [ 981
980 'url' => '/api/entries/exists?url=http://0.0.0.0/entry2', 982 // it returns a database id, we don't know it, so we only check it's greater than the lowest possible value
981 'expectedValue' => true, 983 $this->assertGreaterThan(1, $content['exists']);
982 ],
983 ];
984 } 984 }
985 985
986 /** 986 public function testGetEntriesExistsWithoutReturnId()
987 * @dataProvider dataForEntriesExistWithUrl
988 */
989 public function testGetEntriesExists($url, $expectedValue)
990 { 987 {
991 $this->client->request('GET', $url); 988 $this->client->request('GET', '/api/entries/exists?url=http://0.0.0.0/entry2');
992 989
993 $this->assertSame(200, $this->client->getResponse()->getStatusCode()); 990 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
994 991
995 $content = json_decode($this->client->getResponse()->getContent(), true); 992 $content = json_decode($this->client->getResponse()->getContent(), true);
996 993
997 $this->assertSame($expectedValue, $content['exists']); 994 $this->assertTrue($content['exists']);
998 } 995 }
999 996
1000 public function testGetEntriesExistsWithManyUrls() 997 public function testGetEntriesExistsWithManyUrls()
@@ -1009,7 +1006,8 @@ class EntryRestControllerTest extends WallabagApiTestCase
1009 1006
1010 $this->assertArrayHasKey($url1, $content); 1007 $this->assertArrayHasKey($url1, $content);
1011 $this->assertArrayHasKey($url2, $content); 1008 $this->assertArrayHasKey($url2, $content);
1012 $this->assertSame(2, $content[$url1]); 1009 // it returns a database id, we don't know it, so we only check it's greater than the lowest possible value
1010 $this->assertGreaterThan(1, $content[$url1]);
1013 $this->assertNull($content[$url2]); 1011 $this->assertNull($content[$url2]);
1014 } 1012 }
1015 1013
@@ -1051,7 +1049,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
1051 { 1049 {
1052 $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') 1050 $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager')
1053 ->getRepository('WallabagCoreBundle:Entry') 1051 ->getRepository('WallabagCoreBundle:Entry')
1054 ->findByUrlAndUserId('http://0.0.0.0/entry4', 1); 1052 ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getUserId());
1055 1053
1056 if (!$entry) { 1054 if (!$entry) {
1057 $this->markTestSkipped('No content found in db.'); 1055 $this->markTestSkipped('No content found in db.');
@@ -1087,7 +1085,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
1087 { 1085 {
1088 $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') 1086 $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager')
1089 ->getRepository('WallabagCoreBundle:Entry') 1087 ->getRepository('WallabagCoreBundle:Entry')
1090 ->findByUrlAndUserId('http://0.0.0.0/entry4', 1); 1088 ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getUserId());
1091 1089
1092 $tags = $entry->getTags(); 1090 $tags = $entry->getTags();
1093 1091
@@ -1111,7 +1109,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
1111 1109
1112 $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') 1110 $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager')
1113 ->getRepository('WallabagCoreBundle:Entry') 1111 ->getRepository('WallabagCoreBundle:Entry')
1114 ->findByUrlAndUserId('http://0.0.0.0/entry4', 1); 1112 ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getUserId());
1115 1113
1116 $tags = $entry->getTags(); 1114 $tags = $entry->getTags();
1117 $this->assertCount(4, $tags); 1115 $this->assertCount(4, $tags);
@@ -1131,7 +1129,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
1131 public function testDeleteEntriesTagsListAction() 1129 public function testDeleteEntriesTagsListAction()
1132 { 1130 {
1133 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); 1131 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
1134 $entry = new Entry($em->getReference(User::class, 1)); 1132 $entry = new Entry($em->getReference(User::class, $this->getUserId()));
1135 $entry->setUrl('http://0.0.0.0/test-entry'); 1133 $entry->setUrl('http://0.0.0.0/test-entry');
1136 $entry->addTag((new Tag())->setLabel('foo-tag')); 1134 $entry->addTag((new Tag())->setLabel('foo-tag'));
1137 $entry->addTag((new Tag())->setLabel('bar-tag')); 1135 $entry->addTag((new Tag())->setLabel('bar-tag'));
@@ -1199,7 +1197,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
1199 public function testDeleteEntriesListAction() 1197 public function testDeleteEntriesListAction()
1200 { 1198 {
1201 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); 1199 $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')); 1200 $em->persist((new Entry($em->getReference(User::class, $this->getUserId())))->setUrl('http://0.0.0.0/test-entry1'));
1203 1201
1204 $em->flush(); 1202 $em->flush();
1205 $em->clear(); 1203 $em->clear();
@@ -1257,7 +1255,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
1257 public function testRePostEntryAndReUsePublishedAt() 1255 public function testRePostEntryAndReUsePublishedAt()
1258 { 1256 {
1259 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); 1257 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
1260 $entry = new Entry($em->getReference(User::class, 1)); 1258 $entry = new Entry($em->getReference(User::class, $this->getUserId()));
1261 $entry->setTitle('Antoine de Caunes : « Je veux avoir le droit de tâtonner »'); 1259 $entry->setTitle('Antoine de Caunes : « Je veux avoir le droit de tâtonner »');
1262 $entry->setContent('hihi'); 1260 $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'); 1261 $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
3namespace Tests\Wallabag\ApiBundle\Controller;
4
5use Tests\Wallabag\ApiBundle\WallabagApiTestCase;
6
7class 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}
diff --git a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php
index bd351b18..d8928451 100644
--- a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php
+++ b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php
@@ -18,6 +18,18 @@ use Wallabag\CoreBundle\Command\InstallCommand;
18 18
19class InstallCommandTest extends WallabagCoreTestCase 19class InstallCommandTest extends WallabagCoreTestCase
20{ 20{
21 public static function setUpBeforeClass()
22 {
23 // disable doctrine-test-bundle
24 StaticDriver::setKeepStaticConnections(false);
25 }
26
27 public static function tearDownAfterClass()
28 {
29 // enable doctrine-test-bundle
30 StaticDriver::setKeepStaticConnections(true);
31 }
32
21 public function setUp() 33 public function setUp()
22 { 34 {
23 parent::setUp(); 35 parent::setUp();
@@ -51,9 +63,6 @@ class InstallCommandTest extends WallabagCoreTestCase
51 parent::setUp(); 63 parent::setUp();
52 } 64 }
53 65
54 // disable doctrine-test-bundle
55 StaticDriver::setKeepStaticConnections(false);
56
57 $this->resetDatabase($this->getClient()); 66 $this->resetDatabase($this->getClient());
58 } 67 }
59 68
@@ -62,6 +71,7 @@ class InstallCommandTest extends WallabagCoreTestCase
62 $databasePath = getenv('TEST_DATABASE_PATH'); 71 $databasePath = getenv('TEST_DATABASE_PATH');
63 // Remove variable environnement 72 // Remove variable environnement
64 putenv('TEST_DATABASE_PATH'); 73 putenv('TEST_DATABASE_PATH');
74
65 if ($databasePath && file_exists($databasePath)) { 75 if ($databasePath && file_exists($databasePath)) {
66 unlink($databasePath); 76 unlink($databasePath);
67 } else { 77 } else {
@@ -71,8 +81,6 @@ class InstallCommandTest extends WallabagCoreTestCase
71 $this->resetDatabase($client); 81 $this->resetDatabase($client);
72 } 82 }
73 83
74 // enable doctrine-test-bundle
75 StaticDriver::setKeepStaticConnections(true);
76 parent::tearDown(); 84 parent::tearDown();
77 } 85 }
78 86
diff --git a/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php b/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php
index b13f6519..c4bd6dac 100644
--- a/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php
+++ b/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php
@@ -26,7 +26,7 @@ class ReloadEntryCommandTest extends WallabagCoreTestCase
26 { 26 {
27 parent::setUp(); 27 parent::setUp();
28 28
29 $userRepository = $this->getClient()->getContainer()->get('wallabag_user.user_repository'); 29 $userRepository = $this->getClient()->getContainer()->get('wallabag_user.user_repository.test');
30 30
31 $user = $userRepository->findOneByUserName('admin'); 31 $user = $userRepository->findOneByUserName('admin');
32 $this->adminEntry = new Entry($user); 32 $this->adminEntry = new Entry($user);
@@ -60,7 +60,7 @@ class ReloadEntryCommandTest extends WallabagCoreTestCase
60 60
61 $reloadedEntries = $this->getClient() 61 $reloadedEntries = $this->getClient()
62 ->getContainer() 62 ->getContainer()
63 ->get('wallabag_core.entry_repository') 63 ->get('wallabag_core.entry_repository.test')
64 ->findById([$this->adminEntry->getId(), $this->bobEntry->getId()]); 64 ->findById([$this->adminEntry->getId(), $this->bobEntry->getId()]);
65 65
66 foreach ($reloadedEntries as $reloadedEntry) { 66 foreach ($reloadedEntries as $reloadedEntry) {
@@ -84,7 +84,7 @@ class ReloadEntryCommandTest extends WallabagCoreTestCase
84 'interactive' => false, 84 'interactive' => false,
85 ]); 85 ]);
86 86
87 $entryRepository = $this->getClient()->getContainer()->get('wallabag_core.entry_repository'); 87 $entryRepository = $this->getClient()->getContainer()->get('wallabag_core.entry_repository.test');
88 88
89 $reloadedAdminEntry = $entryRepository->find($this->adminEntry->getId()); 89 $reloadedAdminEntry = $entryRepository->find($this->adminEntry->getId());
90 $this->assertNotEmpty($reloadedAdminEntry->getContent()); 90 $this->assertNotEmpty($reloadedAdminEntry->getContent());
diff --git a/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php b/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php
index 9b34f2a0..ed383a2c 100644
--- a/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php
+++ b/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php
@@ -59,7 +59,8 @@ class ShowUserCommandTest extends WallabagCoreTestCase
59 $this->assertContains('Username: admin', $tester->getDisplay()); 59 $this->assertContains('Username: admin', $tester->getDisplay());
60 $this->assertContains('Email: bigboss@wallabag.org', $tester->getDisplay()); 60 $this->assertContains('Email: bigboss@wallabag.org', $tester->getDisplay());
61 $this->assertContains('Display name: Big boss', $tester->getDisplay()); 61 $this->assertContains('Display name: Big boss', $tester->getDisplay());
62 $this->assertContains('2FA activated: no', $tester->getDisplay()); 62 $this->assertContains('2FA (email) activated', $tester->getDisplay());
63 $this->assertContains('2FA (OTP) activated', $tester->getDisplay());
63 } 64 }
64 65
65 public function testShowUser() 66 public function testShowUser()
diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
index e07c57dd..1090a686 100644
--- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
@@ -1,6 +1,6 @@
1<?php 1<?php
2 2
3namespace tests\Wallabag\CoreBundle\Controller; 3namespace Tests\Wallabag\CoreBundle\Controller;
4 4
5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; 5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
6use Wallabag\AnnotationBundle\Entity\Annotation; 6use Wallabag\AnnotationBundle\Entity\Annotation;
@@ -849,7 +849,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
849 $entryArchived->setContent('Youhou'); 849 $entryArchived->setContent('Youhou');
850 $entryArchived->setTitle('Youhou'); 850 $entryArchived->setTitle('Youhou');
851 $entryArchived->addTag($tagArchived); 851 $entryArchived->addTag($tagArchived);
852 $entryArchived->setArchived(true); 852 $entryArchived->updateArchived(true);
853 $em->persist($entryArchived); 853 $em->persist($entryArchived);
854 854
855 $annotationArchived = new Annotation($user); 855 $annotationArchived = new Annotation($user);
@@ -965,4 +965,120 @@ class ConfigControllerTest extends WallabagCoreTestCase
965 965
966 $client->request('GET', '/config/view-mode'); 966 $client->request('GET', '/config/view-mode');
967 } 967 }
968
969 public function testChangeLocaleWithoutReferer()
970 {
971 $client = $this->getClient();
972
973 $client->request('GET', '/locale/de');
974 $client->followRedirect();
975
976 $this->assertSame('de', $client->getRequest()->getLocale());
977 $this->assertSame('de', $client->getContainer()->get('session')->get('_locale'));
978 }
979
980 public function testChangeLocaleWithReferer()
981 {
982 $client = $this->getClient();
983
984 $client->request('GET', '/login');
985 $client->request('GET', '/locale/de');
986 $client->followRedirect();
987
988 $this->assertSame('de', $client->getRequest()->getLocale());
989 $this->assertSame('de', $client->getContainer()->get('session')->get('_locale'));
990 }
991
992 public function testChangeLocaleToBadLocale()
993 {
994 $client = $this->getClient();
995
996 $client->request('GET', '/login');
997 $client->request('GET', '/locale/yuyuyuyu');
998 $client->followRedirect();
999
1000 $this->assertNotSame('yuyuyuyu', $client->getRequest()->getLocale());
1001 $this->assertNotSame('yuyuyuyu', $client->getContainer()->get('session')->get('_locale'));
1002 }
1003
1004 public function testUserEnable2faEmail()
1005 {
1006 $this->logInAs('admin');
1007 $client = $this->getClient();
1008
1009 $crawler = $client->request('GET', '/config/otp/email');
1010
1011 $this->assertSame(302, $client->getResponse()->getStatusCode());
1012
1013 $crawler = $client->followRedirect();
1014
1015 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text']));
1016 $this->assertContains('flashes.config.notice.otp_enabled', $alert[0]);
1017
1018 // restore user
1019 $em = $this->getEntityManager();
1020 $user = $em
1021 ->getRepository('WallabagUserBundle:User')
1022 ->findOneByUsername('admin');
1023
1024 $this->assertTrue($user->isEmailTwoFactor());
1025
1026 $user->setEmailTwoFactor(false);
1027 $em->persist($user);
1028 $em->flush();
1029 }
1030
1031 public function testUserEnable2faGoogle()
1032 {
1033 $this->logInAs('admin');
1034 $client = $this->getClient();
1035
1036 $crawler = $client->request('GET', '/config/otp/app');
1037
1038 $this->assertSame(200, $client->getResponse()->getStatusCode());
1039
1040 // restore user
1041 $em = $this->getEntityManager();
1042 $user = $em
1043 ->getRepository('WallabagUserBundle:User')
1044 ->findOneByUsername('admin');
1045
1046 $this->assertTrue($user->isGoogleTwoFactor());
1047 $this->assertGreaterThan(0, $user->getBackupCodes());
1048
1049 $user->setGoogleAuthenticatorSecret(false);
1050 $user->setBackupCodes(null);
1051 $em->persist($user);
1052 $em->flush();
1053 }
1054
1055 public function testUserEnable2faGoogleCancel()
1056 {
1057 $this->logInAs('admin');
1058 $client = $this->getClient();
1059
1060 $crawler = $client->request('GET', '/config/otp/app');
1061
1062 $this->assertSame(200, $client->getResponse()->getStatusCode());
1063
1064 // restore user
1065 $em = $this->getEntityManager();
1066 $user = $em
1067 ->getRepository('WallabagUserBundle:User')
1068 ->findOneByUsername('admin');
1069
1070 $this->assertTrue($user->isGoogleTwoFactor());
1071 $this->assertGreaterThan(0, $user->getBackupCodes());
1072
1073 $crawler = $client->request('GET', '/config/otp/app/cancel');
1074
1075 $this->assertSame(302, $client->getResponse()->getStatusCode());
1076
1077 $user = $em
1078 ->getRepository('WallabagUserBundle:User')
1079 ->findOneByUsername('admin');
1080
1081 $this->assertFalse($user->isGoogleTwoFactor());
1082 $this->assertEmpty($user->getBackupCodes());
1083 }
968} 1084}
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
index 479e0700..28291b5a 100644
--- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
@@ -522,9 +522,12 @@ class EntryControllerTest extends WallabagCoreTestCase
522 522
523 $crawler = $client->followRedirect(); 523 $crawler = $client->followRedirect();
524 524
525 $this->assertGreaterThan(1, $title = $crawler->filter('div[id=article] h1')->extract(['_text'])); 525 $title = $crawler->filter('div[id=article] h1')->extract(['_text']);
526 $this->assertGreaterThan(1, $title);
526 $this->assertContains('My updated title hehe :)', $title[0]); 527 $this->assertContains('My updated title hehe :)', $title[0]);
527 $this->assertSame(1, \count($stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text']))); 528
529 $stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text']);
530 $this->assertCount(1, $stats);
528 $this->assertNotContains('example.io', trim($stats[0])); 531 $this->assertNotContains('example.io', trim($stats[0]));
529 } 532 }
530 533
@@ -620,7 +623,7 @@ class EntryControllerTest extends WallabagCoreTestCase
620 $content->setMimetype('text/html'); 623 $content->setMimetype('text/html');
621 $content->setTitle('test title entry'); 624 $content->setTitle('test title entry');
622 $content->setContent('This is my content /o/'); 625 $content->setContent('This is my content /o/');
623 $content->setArchived(true); 626 $content->updateArchived(true);
624 $content->setLanguage('fr'); 627 $content->setLanguage('fr');
625 628
626 $em->persist($content); 629 $em->persist($content);
@@ -773,7 +776,7 @@ class EntryControllerTest extends WallabagCoreTestCase
773 776
774 $entry = new Entry($this->getLoggedInUser()); 777 $entry = new Entry($this->getLoggedInUser());
775 $entry->setUrl($this->url); 778 $entry->setUrl($this->url);
776 $entry->setArchived(false); 779 $entry->updateArchived(false);
777 $this->getEntityManager()->persist($entry); 780 $this->getEntityManager()->persist($entry);
778 $this->getEntityManager()->flush(); 781 $this->getEntityManager()->flush();
779 782
@@ -984,8 +987,13 @@ class EntryControllerTest extends WallabagCoreTestCase
984 $client->request('GET', '/share/' . $content->getId()); 987 $client->request('GET', '/share/' . $content->getId());
985 $this->assertSame(302, $client->getResponse()->getStatusCode()); 988 $this->assertSame(302, $client->getResponse()->getStatusCode());
986 989
987 // follow link with uid 990 $shareUrl = $client->getResponse()->getTargetUrl();
988 $crawler = $client->followRedirect(); 991
992 // use a new client to have a fresh empty session (instead of a logged one from the previous client)
993 $client->restart();
994
995 $client->request('GET', $shareUrl);
996
989 $this->assertSame(200, $client->getResponse()->getStatusCode()); 997 $this->assertSame(200, $client->getResponse()->getStatusCode());
990 $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control')); 998 $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control'));
991 $this->assertContains('public', $client->getResponse()->headers->get('cache-control')); 999 $this->assertContains('public', $client->getResponse()->headers->get('cache-control'));
@@ -1001,9 +1009,6 @@ class EntryControllerTest extends WallabagCoreTestCase
1001 $client->request('GET', '/share/' . $content->getUid()); 1009 $client->request('GET', '/share/' . $content->getUid());
1002 $this->assertSame(404, $client->getResponse()->getStatusCode()); 1010 $this->assertSame(404, $client->getResponse()->getStatusCode());
1003 1011
1004 $client->request('GET', '/view/' . $content->getId());
1005 $this->assertContains('no-cache', $client->getResponse()->headers->get('cache-control'));
1006
1007 // removing the share 1012 // removing the share
1008 $client->request('GET', '/share/delete/' . $content->getId()); 1013 $client->request('GET', '/share/delete/' . $content->getId());
1009 $this->assertSame(302, $client->getResponse()->getStatusCode()); 1014 $this->assertSame(302, $client->getResponse()->getStatusCode());
@@ -1244,7 +1249,7 @@ class EntryControllerTest extends WallabagCoreTestCase
1244 $entry = new Entry($this->getLoggedInUser()); 1249 $entry = new Entry($this->getLoggedInUser());
1245 $entry->setUrl('http://0.0.0.0/foo/baz/qux'); 1250 $entry->setUrl('http://0.0.0.0/foo/baz/qux');
1246 $entry->setTitle('Le manège'); 1251 $entry->setTitle('Le manège');
1247 $entry->setArchived(true); 1252 $entry->updateArchived(true);
1248 $this->getEntityManager()->persist($entry); 1253 $this->getEntityManager()->persist($entry);
1249 $this->getEntityManager()->flush(); 1254 $this->getEntityManager()->flush();
1250 1255
@@ -1274,7 +1279,7 @@ class EntryControllerTest extends WallabagCoreTestCase
1274 $entry = new Entry($this->getLoggedInUser()); 1279 $entry = new Entry($this->getLoggedInUser());
1275 $entry->setUrl('http://domain/qux'); 1280 $entry->setUrl('http://domain/qux');
1276 $entry->setTitle('Le manège'); 1281 $entry->setTitle('Le manège');
1277 $entry->setArchived(true); 1282 $entry->updateArchived(true);
1278 $this->getEntityManager()->persist($entry); 1283 $this->getEntityManager()->persist($entry);
1279 $this->getEntityManager()->flush(); 1284 $this->getEntityManager()->flush();
1280 1285
@@ -1325,10 +1330,6 @@ class EntryControllerTest extends WallabagCoreTestCase
1325 'http://www.hao123.com/shequ?__noscript__-=1', 1330 'http://www.hao123.com/shequ?__noscript__-=1',
1326 'zh_CN', 1331 'zh_CN',
1327 ], 1332 ],
1328 'ru' => [
1329 'https://www.kp.ru/daily/26879.7/3921982/',
1330 'ru',
1331 ],
1332 'pt_BR' => [ 1333 'pt_BR' => [
1333 'https://politica.estadao.com.br/noticias/eleicoes,campanha-catatonica,70002491983', 1334 'https://politica.estadao.com.br/noticias/eleicoes,campanha-catatonica,70002491983',
1334 'pt_BR', 1335 'pt_BR',
@@ -1494,4 +1495,30 @@ class EntryControllerTest extends WallabagCoreTestCase
1494 1495
1495 $this->assertSame(sprintf('/remove-tag/%s/%s', $entry->getId(), $tag->getId()), $link); 1496 $this->assertSame(sprintf('/remove-tag/%s/%s', $entry->getId(), $tag->getId()), $link);
1496 } 1497 }
1498
1499 public function testRandom()
1500 {
1501 $this->logInAs('admin');
1502 $client = $this->getClient();
1503
1504 $client->request('GET', '/unread/random');
1505 $this->assertSame(302, $client->getResponse()->getStatusCode());
1506 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Unread random');
1507
1508 $client->request('GET', '/starred/random');
1509 $this->assertSame(302, $client->getResponse()->getStatusCode());
1510 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Starred random');
1511
1512 $client->request('GET', '/archive/random');
1513 $this->assertSame(302, $client->getResponse()->getStatusCode());
1514 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Archive random');
1515
1516 $client->request('GET', '/untagged/random');
1517 $this->assertSame(302, $client->getResponse()->getStatusCode());
1518 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Untagged random');
1519
1520 $client->request('GET', '/all/random');
1521 $this->assertSame(302, $client->getResponse()->getStatusCode());
1522 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'All random');
1523 }
1497} 1524}
diff --git a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php
index 0c3d4c83..d7ce7c45 100644
--- a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php
@@ -180,7 +180,7 @@ class ExportControllerTest extends WallabagCoreTestCase
180 180
181 $this->assertGreaterThan(1, $csv); 181 $this->assertGreaterThan(1, $csv);
182 // +1 for title line 182 // +1 for title line
183 $this->assertSame(\count($contentInDB) + 1, \count($csv)); 183 $this->assertCount(\count($contentInDB) + 1, $csv);
184 $this->assertSame('Title;URL;Content;Tags;"MIME Type";Language;"Creation date"', $csv[0]); 184 $this->assertSame('Title;URL;Content;Tags;"MIME Type";Language;"Creation date"', $csv[0]);
185 $this->assertContains($contentInDB[0]['title'], $csv[1]); 185 $this->assertContains($contentInDB[0]['title'], $csv[1]);
186 $this->assertContains($contentInDB[0]['url'], $csv[1]); 186 $this->assertContains($contentInDB[0]['url'], $csv[1]);
diff --git a/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php b/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php
index 2af6e14f..afa90621 100644
--- a/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php
@@ -11,7 +11,7 @@ class RssControllerTest extends WallabagCoreTestCase
11 $doc = new \DOMDocument(); 11 $doc = new \DOMDocument();
12 $doc->loadXML($xml); 12 $doc->loadXML($xml);
13 13
14 $xpath = new \DOMXpath($doc); 14 $xpath = new \DOMXPath($doc);
15 15
16 if (null === $nb) { 16 if (null === $nb) {
17 $this->assertGreaterThan(0, $xpath->query('//item')->length); 17 $this->assertGreaterThan(0, $xpath->query('//item')->length);
diff --git a/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php b/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php
index 395208a2..b03c7550 100644
--- a/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php
@@ -26,7 +26,7 @@ class SecurityControllerTest extends WallabagCoreTestCase
26 $this->assertContains('config.form_rss.description', $crawler->filter('body')->extract(['_text'])[0]); 26 $this->assertContains('config.form_rss.description', $crawler->filter('body')->extract(['_text'])[0]);
27 } 27 }
28 28
29 public function testLoginWith2Factor() 29 public function testLoginWith2FactorEmail()
30 { 30 {
31 $client = $this->getClient(); 31 $client = $this->getClient();
32 32
@@ -42,7 +42,7 @@ class SecurityControllerTest extends WallabagCoreTestCase
42 $user = $em 42 $user = $em
43 ->getRepository('WallabagUserBundle:User') 43 ->getRepository('WallabagUserBundle:User')
44 ->findOneByUsername('admin'); 44 ->findOneByUsername('admin');
45 $user->setTwoFactorAuthentication(true); 45 $user->setEmailTwoFactor(true);
46 $em->persist($user); 46 $em->persist($user);
47 $em->flush(); 47 $em->flush();
48 48
@@ -54,12 +54,12 @@ class SecurityControllerTest extends WallabagCoreTestCase
54 $user = $em 54 $user = $em
55 ->getRepository('WallabagUserBundle:User') 55 ->getRepository('WallabagUserBundle:User')
56 ->findOneByUsername('admin'); 56 ->findOneByUsername('admin');
57 $user->setTwoFactorAuthentication(false); 57 $user->setEmailTwoFactor(false);
58 $em->persist($user); 58 $em->persist($user);
59 $em->flush(); 59 $em->flush();
60 } 60 }
61 61
62 public function testTrustedComputer() 62 public function testLoginWith2FactorGoogle()
63 { 63 {
64 $client = $this->getClient(); 64 $client = $this->getClient();
65 65
@@ -69,15 +69,27 @@ class SecurityControllerTest extends WallabagCoreTestCase
69 return; 69 return;
70 } 70 }
71 71
72 $client->followRedirects();
73
72 $em = $client->getContainer()->get('doctrine.orm.entity_manager'); 74 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
73 $user = $em 75 $user = $em
74 ->getRepository('WallabagUserBundle:User') 76 ->getRepository('WallabagUserBundle:User')
75 ->findOneByUsername('admin'); 77 ->findOneByUsername('admin');
78 $user->setGoogleAuthenticatorSecret('26LDIHYGHNELOQEM');
79 $em->persist($user);
80 $em->flush();
81
82 $this->logInAsUsingHttp('admin');
83 $crawler = $client->request('GET', '/config');
84 $this->assertContains('scheb_two_factor.trusted', $crawler->filter('body')->extract(['_text'])[0]);
76 85
77 $date = new \DateTime(); 86 // restore user
78 $user->addTrustedComputer('ABCDEF', $date->add(new \DateInterval('P1M'))); 87 $user = $em
79 $this->assertTrue($user->isTrustedComputer('ABCDEF')); 88 ->getRepository('WallabagUserBundle:User')
80 $this->assertFalse($user->isTrustedComputer('FEDCBA')); 89 ->findOneByUsername('admin');
90 $user->setGoogleAuthenticatorSecret(null);
91 $em->persist($user);
92 $em->flush();
81 } 93 }
82 94
83 public function testEnabledRegistration() 95 public function testEnabledRegistration()
diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
index 768f4c07..be17dcf5 100644
--- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
@@ -176,4 +176,49 @@ class TagControllerTest extends WallabagCoreTestCase
176 $em->remove($tag); 176 $em->remove($tag);
177 $em->flush(); 177 $em->flush();
178 } 178 }
179
180 public function testRenameTagUsingTheFormInsideTagList()
181 {
182 $this->logInAs('admin');
183 $client = $this->getClient();
184
185 $tag = new Tag();
186 $tag->setLabel($this->tagName);
187 $entry = new Entry($this->getLoggedInUser());
188 $entry->setUrl('http://0.0.0.0/foo');
189 $entry->addTag($tag);
190 $this->getEntityManager()->persist($entry);
191 $this->getEntityManager()->flush();
192 $this->getEntityManager()->clear();
193
194 // We make a first request to set an history and test redirection after tag deletion
195 $crawler = $client->request('GET', '/tag/list');
196 $form = $crawler->filter('#tag-' . $tag->getId() . ' form')->form();
197
198 $data = [
199 'tag[label]' => 'specific label',
200 ];
201
202 $client->submit($form, $data);
203 $this->assertSame(302, $client->getResponse()->getStatusCode());
204
205 $freshEntry = $client->getContainer()
206 ->get('doctrine.orm.entity_manager')
207 ->getRepository('WallabagCoreBundle:Entry')
208 ->find($entry->getId());
209
210 $tags = $freshEntry->getTags()->toArray();
211 foreach ($tags as $key => $item) {
212 $tags[$key] = $item->getLabel();
213 }
214
215 $this->assertFalse(array_search($tag->getLabel(), $tags, true), 'Previous tag is not attach to entry anymore.');
216
217 $newTag = $client->getContainer()
218 ->get('doctrine.orm.entity_manager')
219 ->getRepository('WallabagCoreBundle:Tag')
220 ->findOneByLabel('specific label');
221 $this->assertInstanceOf(Tag::class, $newTag, 'Tag "specific label" exists.');
222 $this->assertTrue($newTag->hasEntry($freshEntry), 'Tag "specific label" is assigned to the entry.');
223 }
179} 224}
diff --git a/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php b/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php
index 93edfde8..ff0a9602 100644
--- a/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php
+++ b/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php
@@ -56,4 +56,27 @@ class UserLocaleListenerTest extends TestCase
56 56
57 $this->assertNull($session->get('_locale')); 57 $this->assertNull($session->get('_locale'));
58 } 58 }
59
60 public function testWithLanguageFromSession()
61 {
62 $session = new Session(new MockArraySessionStorage());
63 $listener = new UserLocaleListener($session);
64 $session->set('_locale', 'de');
65
66 $user = new User();
67 $user->setEnabled(true);
68
69 $config = new Config($user);
70 $config->setLanguage('fr');
71
72 $user->setConfig($config);
73
74 $userToken = new UsernamePasswordToken($user, '', 'test');
75 $request = Request::create('/');
76 $event = new InteractiveLoginEvent($request, $userToken);
77
78 $listener->onInteractiveLogin($event);
79
80 $this->assertSame('de', $session->get('_locale'));
81 }
59} 82}
diff --git a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php
index 1173fc3d..7beccd30 100644
--- a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php
+++ b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php
@@ -134,4 +134,72 @@ class GrabySiteConfigBuilderTest extends TestCase
134 134
135 $this->assertCount(1, $records, 'One log was recorded'); 135 $this->assertCount(1, $records, 'One log was recorded');
136 } 136 }
137
138 public function testBuildConfigWithBadExtraFields()
139 {
140 /* @var \Graby\SiteConfig\ConfigBuilder|\PHPUnit_Framework_MockObject_MockObject */
141 $grabyConfigBuilderMock = $this->getMockBuilder('Graby\SiteConfig\ConfigBuilder')
142 ->disableOriginalConstructor()
143 ->getMock();
144
145 $grabySiteConfig = new GrabySiteConfig();
146 $grabySiteConfig->requires_login = true;
147 $grabySiteConfig->login_uri = 'http://www.example.com/login';
148 $grabySiteConfig->login_username_field = 'login';
149 $grabySiteConfig->login_password_field = 'password';
150 $grabySiteConfig->login_extra_fields = ['field'];
151 $grabySiteConfig->not_logged_in_xpath = '//div[@class="need-login"]';
152
153 $grabyConfigBuilderMock
154 ->method('buildForHost')
155 ->with('example.com')
156 ->will($this->returnValue($grabySiteConfig));
157
158 $logger = new Logger('foo');
159 $handler = new TestHandler();
160 $logger->pushHandler($handler);
161
162 $siteCrentialRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\SiteCredentialRepository')
163 ->disableOriginalConstructor()
164 ->getMock();
165 $siteCrentialRepo->expects($this->once())
166 ->method('findOneByHostAndUser')
167 ->with('example.com', 1)
168 ->willReturn(['username' => 'foo', 'password' => 'bar']);
169
170 $user = $this->getMockBuilder('Wallabag\UserBundle\Entity\User')
171 ->disableOriginalConstructor()
172 ->getMock();
173 $user->expects($this->once())
174 ->method('getId')
175 ->willReturn(1);
176
177 $token = new UsernamePasswordToken($user, 'pass', 'provider');
178
179 $tokenStorage = new TokenStorage();
180 $tokenStorage->setToken($token);
181
182 $this->builder = new GrabySiteConfigBuilder(
183 $grabyConfigBuilderMock,
184 $tokenStorage,
185 $siteCrentialRepo,
186 $logger
187 );
188
189 $config = $this->builder->buildForHost('www.example.com');
190
191 $this->assertSame('example.com', $config->getHost());
192 $this->assertTrue($config->requiresLogin());
193 $this->assertSame('http://www.example.com/login', $config->getLoginUri());
194 $this->assertSame('login', $config->getUsernameField());
195 $this->assertSame('password', $config->getPasswordField());
196 $this->assertSame([], $config->getExtraFields());
197 $this->assertSame('//div[@class="need-login"]', $config->getNotLoggedInXpath());
198 $this->assertSame('foo', $config->getUsername());
199 $this->assertSame('bar', $config->getPassword());
200
201 $records = $handler->getRecords();
202
203 $this->assertCount(1, $records, 'One log was recorded');
204 }
137} 205}
diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
index 3dd9273c..508adb1b 100644
--- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
+++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
@@ -163,7 +163,7 @@ class ContentProxyTest extends TestCase
163 163
164 $this->assertSame('http://1.1.1.1', $entry->getUrl()); 164 $this->assertSame('http://1.1.1.1', $entry->getUrl());
165 $this->assertSame('this is my title', $entry->getTitle()); 165 $this->assertSame('this is my title', $entry->getTitle());
166 $this->assertContains('this is my content', $entry->getContent()); 166 $this->assertContains('content', $entry->getContent());
167 $this->assertSame('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture()); 167 $this->assertSame('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture());
168 $this->assertSame('text/html', $entry->getMimetype()); 168 $this->assertSame('text/html', $entry->getMimetype());
169 $this->assertSame('fr', $entry->getLanguage()); 169 $this->assertSame('fr', $entry->getLanguage());
@@ -205,7 +205,7 @@ class ContentProxyTest extends TestCase
205 205
206 $this->assertSame('http://1.1.1.1', $entry->getUrl()); 206 $this->assertSame('http://1.1.1.1', $entry->getUrl());
207 $this->assertSame('this is my title', $entry->getTitle()); 207 $this->assertSame('this is my title', $entry->getTitle());
208 $this->assertContains('this is my content', $entry->getContent()); 208 $this->assertContains('content', $entry->getContent());
209 $this->assertNull($entry->getPreviewPicture()); 209 $this->assertNull($entry->getPreviewPicture());
210 $this->assertSame('text/html', $entry->getMimetype()); 210 $this->assertSame('text/html', $entry->getMimetype());
211 $this->assertSame('fr', $entry->getLanguage()); 211 $this->assertSame('fr', $entry->getLanguage());
@@ -247,7 +247,7 @@ class ContentProxyTest extends TestCase
247 247
248 $this->assertSame('http://1.1.1.1', $entry->getUrl()); 248 $this->assertSame('http://1.1.1.1', $entry->getUrl());
249 $this->assertSame('this is my title', $entry->getTitle()); 249 $this->assertSame('this is my title', $entry->getTitle());
250 $this->assertContains('this is my content', $entry->getContent()); 250 $this->assertContains('content', $entry->getContent());
251 $this->assertSame('text/html', $entry->getMimetype()); 251 $this->assertSame('text/html', $entry->getMimetype());
252 $this->assertNull($entry->getLanguage()); 252 $this->assertNull($entry->getLanguage());
253 $this->assertSame('200', $entry->getHttpStatus()); 253 $this->assertSame('200', $entry->getHttpStatus());
@@ -296,7 +296,7 @@ class ContentProxyTest extends TestCase
296 296
297 $this->assertSame('http://1.1.1.1', $entry->getUrl()); 297 $this->assertSame('http://1.1.1.1', $entry->getUrl());
298 $this->assertSame('this is my title', $entry->getTitle()); 298 $this->assertSame('this is my title', $entry->getTitle());
299 $this->assertContains('this is my content', $entry->getContent()); 299 $this->assertContains('content', $entry->getContent());
300 $this->assertNull($entry->getPreviewPicture()); 300 $this->assertNull($entry->getPreviewPicture());
301 $this->assertSame('text/html', $entry->getMimetype()); 301 $this->assertSame('text/html', $entry->getMimetype());
302 $this->assertSame('fr', $entry->getLanguage()); 302 $this->assertSame('fr', $entry->getLanguage());
@@ -332,7 +332,7 @@ class ContentProxyTest extends TestCase
332 332
333 $this->assertSame('http://1.1.1.1', $entry->getUrl()); 333 $this->assertSame('http://1.1.1.1', $entry->getUrl());
334 $this->assertSame('this is my title', $entry->getTitle()); 334 $this->assertSame('this is my title', $entry->getTitle());
335 $this->assertContains('this is my content', $entry->getContent()); 335 $this->assertContains('content', $entry->getContent());
336 $this->assertSame('text/html', $entry->getMimetype()); 336 $this->assertSame('text/html', $entry->getMimetype());
337 $this->assertSame('fr', $entry->getLanguage()); 337 $this->assertSame('fr', $entry->getLanguage());
338 $this->assertSame(4.0, $entry->getReadingTime()); 338 $this->assertSame(4.0, $entry->getReadingTime());
@@ -371,7 +371,7 @@ class ContentProxyTest extends TestCase
371 371
372 $this->assertSame('http://1.1.1.1', $entry->getUrl()); 372 $this->assertSame('http://1.1.1.1', $entry->getUrl());
373 $this->assertSame('this is my title', $entry->getTitle()); 373 $this->assertSame('this is my title', $entry->getTitle());
374 $this->assertContains('this is my content', $entry->getContent()); 374 $this->assertContains('content', $entry->getContent());
375 $this->assertSame('text/html', $entry->getMimetype()); 375 $this->assertSame('text/html', $entry->getMimetype());
376 $this->assertSame('fr', $entry->getLanguage()); 376 $this->assertSame('fr', $entry->getLanguage());
377 $this->assertSame(4.0, $entry->getReadingTime()); 377 $this->assertSame(4.0, $entry->getReadingTime());
@@ -406,7 +406,7 @@ class ContentProxyTest extends TestCase
406 406
407 $this->assertSame('http://1.1.1.1', $entry->getUrl()); 407 $this->assertSame('http://1.1.1.1', $entry->getUrl());
408 $this->assertSame('this is my title', $entry->getTitle()); 408 $this->assertSame('this is my title', $entry->getTitle());
409 $this->assertContains('this is my content', $entry->getContent()); 409 $this->assertContains('content', $entry->getContent());
410 $this->assertSame('text/html', $entry->getMimetype()); 410 $this->assertSame('text/html', $entry->getMimetype());
411 $this->assertSame('fr', $entry->getLanguage()); 411 $this->assertSame('fr', $entry->getLanguage());
412 $this->assertSame(4.0, $entry->getReadingTime()); 412 $this->assertSame(4.0, $entry->getReadingTime());
diff --git a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php
index 04e1a59c..29e12cbe 100644
--- a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php
+++ b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php
@@ -17,6 +17,9 @@ class RedirectTest extends TestCase
17 /** @var Redirect */ 17 /** @var Redirect */
18 private $redirect; 18 private $redirect;
19 19
20 /** @var UsernamePasswordToken */
21 private $token;
22
20 public function setUp() 23 public function setUp()
21 { 24 {
22 $this->routerMock = $this->getMockBuilder('Symfony\Component\Routing\Router') 25 $this->routerMock = $this->getMockBuilder('Symfony\Component\Routing\Router')
diff --git a/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php b/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php
index b044a700..800af5c9 100644
--- a/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php
+++ b/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php
@@ -1,6 +1,6 @@
1<?php 1<?php
2 2
3namespace Tests\Wallabag\CoreBundle\Command; 3namespace Tests\Wallabag\CoreBundle\ParamConverter;
4 4
5use PHPUnit\Framework\TestCase; 5use PHPUnit\Framework\TestCase;
6use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; 6use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
diff --git a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php
index 6e1163c5..816d22f4 100644
--- a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php
+++ b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php
@@ -84,8 +84,8 @@ abstract class WallabagCoreTestCase extends WebTestCase
84 $container = $this->client->getContainer(); 84 $container = $this->client->getContainer();
85 $session = $container->get('session'); 85 $session = $container->get('session');
86 86
87 $userManager = $container->get('fos_user.user_manager'); 87 $userManager = $container->get('fos_user.user_manager.test');
88 $loginManager = $container->get('fos_user.security.login_manager'); 88 $loginManager = $container->get('fos_user.security.login_manager.test');
89 $firewallName = $container->getParameter('fos_user.firewall_name'); 89 $firewallName = $container->getParameter('fos_user.firewall_name');
90 90
91 $user = $userManager->findUserBy(['username' => $username]); 91 $user = $userManager->findUserBy(['username' => $username]);
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',
diff --git a/tests/Wallabag/ImportBundle/Consumer/AMQPEntryConsumerTest.php b/tests/Wallabag/ImportBundle/Consumer/AMQPEntryConsumerTest.php
index b2141c04..b7f6192d 100644
--- a/tests/Wallabag/ImportBundle/Consumer/AMQPEntryConsumerTest.php
+++ b/tests/Wallabag/ImportBundle/Consumer/AMQPEntryConsumerTest.php
@@ -1,6 +1,6 @@
1<?php 1<?php
2 2
3namespace Tests\Wallabag\ImportBundle\Consumer\AMQP; 3namespace Tests\Wallabag\ImportBundle\Consumer;
4 4
5use PhpAmqpLib\Message\AMQPMessage; 5use PhpAmqpLib\Message\AMQPMessage;
6use PHPUnit\Framework\TestCase; 6use PHPUnit\Framework\TestCase;
diff --git a/tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php b/tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php
index 61337e47..e1bd8827 100644
--- a/tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php
+++ b/tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php
@@ -1,6 +1,6 @@
1<?php 1<?php
2 2
3namespace Tests\Wallabag\ImportBundle\Consumer\AMQP; 3namespace Tests\Wallabag\ImportBundle\Consumer;
4 4
5use PHPUnit\Framework\TestCase; 5use PHPUnit\Framework\TestCase;
6use Wallabag\CoreBundle\Entity\Entry; 6use Wallabag\CoreBundle\Entity\Entry;
diff --git a/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php
index cd3e41e9..d3ffbb6d 100644
--- a/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php
+++ b/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php
@@ -121,7 +121,7 @@ class ChromeControllerTest extends WallabagCoreTestCase
121 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); 121 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
122 $this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for http://www.usinenouvelle.com is ok'); 122 $this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for http://www.usinenouvelle.com is ok');
123 $this->assertNotEmpty($content->getLanguage(), 'Language for http://www.usinenouvelle.com is ok'); 123 $this->assertNotEmpty($content->getLanguage(), 'Language for http://www.usinenouvelle.com is ok');
124 $this->assertSame(1, \count($content->getTags())); 124 $this->assertCount(1, $content->getTags());
125 125
126 $createdAt = $content->getCreatedAt(); 126 $createdAt = $content->getCreatedAt();
127 $this->assertSame('2011', $createdAt->format('Y')); 127 $this->assertSame('2011', $createdAt->format('Y'));
diff --git a/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php
index dc5ed6d0..3e64f2e5 100644
--- a/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php
+++ b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php
@@ -122,7 +122,7 @@ class FirefoxControllerTest extends WallabagCoreTestCase
122 $this->assertNotEmpty($content->getMimetype(), 'Mimetype for http://lexpansion.lexpress.fr is ok'); 122 $this->assertNotEmpty($content->getMimetype(), 'Mimetype for http://lexpansion.lexpress.fr is ok');
123 $this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for http://lexpansion.lexpress.fr is ok'); 123 $this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for http://lexpansion.lexpress.fr is ok');
124 $this->assertNotEmpty($content->getLanguage(), 'Language for http://lexpansion.lexpress.fr is ok'); 124 $this->assertNotEmpty($content->getLanguage(), 'Language for http://lexpansion.lexpress.fr is ok');
125 $this->assertSame(3, \count($content->getTags())); 125 $this->assertCount(3, $content->getTags());
126 126
127 $content = $client->getContainer() 127 $content = $client->getContainer()
128 ->get('doctrine.orm.entity_manager') 128 ->get('doctrine.orm.entity_manager')
diff --git a/tests/Wallabag/ImportBundle/Controller/InstapaperControllerTest.php b/tests/Wallabag/ImportBundle/Controller/InstapaperControllerTest.php
index 7390fa88..05347767 100644
--- a/tests/Wallabag/ImportBundle/Controller/InstapaperControllerTest.php
+++ b/tests/Wallabag/ImportBundle/Controller/InstapaperControllerTest.php
@@ -124,7 +124,7 @@ class InstapaperControllerTest extends WallabagCoreTestCase
124 $this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for https://www.liberation.fr is ok'); 124 $this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for https://www.liberation.fr is ok');
125 $this->assertNotEmpty($content->getLanguage(), 'Language for https://www.liberation.fr is ok'); 125 $this->assertNotEmpty($content->getLanguage(), 'Language for https://www.liberation.fr is ok');
126 $this->assertContains('foot', $content->getTags(), 'It includes the "foot" tag'); 126 $this->assertContains('foot', $content->getTags(), 'It includes the "foot" tag');
127 $this->assertSame(1, \count($content->getTags())); 127 $this->assertCount(1, $content->getTags());
128 $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); 128 $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt());
129 129
130 $content = $client->getContainer() 130 $content = $client->getContainer()
@@ -138,7 +138,7 @@ class InstapaperControllerTest extends WallabagCoreTestCase
138 $this->assertContains('foot', $content->getTags()); 138 $this->assertContains('foot', $content->getTags());
139 $this->assertContains('test_tag', $content->getTags()); 139 $this->assertContains('test_tag', $content->getTags());
140 140
141 $this->assertSame(2, \count($content->getTags())); 141 $this->assertCount(2, $content->getTags());
142 } 142 }
143 143
144 public function testImportInstapaperWithFileAndMarkAllAsRead() 144 public function testImportInstapaperWithFileAndMarkAllAsRead()
diff --git a/tests/Wallabag/ImportBundle/Controller/PinboardControllerTest.php b/tests/Wallabag/ImportBundle/Controller/PinboardControllerTest.php
index 80819f45..15646d55 100644
--- a/tests/Wallabag/ImportBundle/Controller/PinboardControllerTest.php
+++ b/tests/Wallabag/ImportBundle/Controller/PinboardControllerTest.php
@@ -127,7 +127,7 @@ class PinboardControllerTest extends WallabagCoreTestCase
127 $this->assertContains('foot', $tags, 'It includes the "foot" tag'); 127 $this->assertContains('foot', $tags, 'It includes the "foot" tag');
128 $this->assertContains('varnish', $tags, 'It includes the "varnish" tag'); 128 $this->assertContains('varnish', $tags, 'It includes the "varnish" tag');
129 $this->assertContains('php', $tags, 'It includes the "php" tag'); 129 $this->assertContains('php', $tags, 'It includes the "php" tag');
130 $this->assertSame(3, \count($tags)); 130 $this->assertCount(3, $tags);
131 131
132 $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); 132 $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt());
133 $this->assertSame('2016-10-26', $content->getCreatedAt()->format('Y-m-d')); 133 $this->assertSame('2016-10-26', $content->getCreatedAt()->format('Y-m-d'));
diff --git a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php
index 5619659a..4f2f4053 100644
--- a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php
+++ b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php
@@ -125,7 +125,7 @@ class ReadabilityControllerTest extends WallabagCoreTestCase
125 125
126 $tags = $content->getTags(); 126 $tags = $content->getTags();
127 $this->assertContains('foot', $tags, 'It includes the "foot" tag'); 127 $this->assertContains('foot', $tags, 'It includes the "foot" tag');
128 $this->assertSame(1, \count($tags)); 128 $this->assertCount(1, $tags);
129 129
130 $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); 130 $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt());
131 $this->assertSame('2016-09-08', $content->getCreatedAt()->format('Y-m-d')); 131 $this->assertSame('2016-09-08', $content->getCreatedAt()->format('Y-m-d'));
diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php
index c67941a7..1f57939d 100644
--- a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php
+++ b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php
@@ -127,7 +127,7 @@ class WallabagV1ControllerTest extends WallabagCoreTestCase
127 $tags = $content->getTags(); 127 $tags = $content->getTags();
128 $this->assertContains('foot', $tags, 'It includes the "foot" tag'); 128 $this->assertContains('foot', $tags, 'It includes the "foot" tag');
129 $this->assertContains('framabag', $tags, 'It includes the "framabag" tag'); 129 $this->assertContains('framabag', $tags, 'It includes the "framabag" tag');
130 $this->assertSame(2, \count($tags)); 130 $this->assertCount(2, $tags);
131 131
132 $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); 132 $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt());
133 } 133 }
diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php
index 822656ba..b606e26a 100644
--- a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php
+++ b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php
@@ -128,7 +128,7 @@ class WallabagV2ControllerTest extends WallabagCoreTestCase
128 128
129 $tags = $content->getTags(); 129 $tags = $content->getTags();
130 $this->assertContains('foot', $tags, 'It includes the "foot" tag'); 130 $this->assertContains('foot', $tags, 'It includes the "foot" tag');
131 $this->assertSame(1, \count($tags)); 131 $this->assertCount(1, $tags);
132 132
133 $content = $client->getContainer() 133 $content = $client->getContainer()
134 ->get('doctrine.orm.entity_manager') 134 ->get('doctrine.orm.entity_manager')
@@ -147,7 +147,7 @@ class WallabagV2ControllerTest extends WallabagCoreTestCase
147 $this->assertContains('foot', $tags, 'It includes the "foot" tag'); 147 $this->assertContains('foot', $tags, 'It includes the "foot" tag');
148 $this->assertContains('mediapart', $tags, 'It includes the "mediapart" tag'); 148 $this->assertContains('mediapart', $tags, 'It includes the "mediapart" tag');
149 $this->assertContains('blog', $tags, 'It includes the "blog" tag'); 149 $this->assertContains('blog', $tags, 'It includes the "blog" tag');
150 $this->assertSame(3, \count($tags)); 150 $this->assertCount(3, $tags);
151 151
152 $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); 152 $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt());
153 $this->assertSame('2016-09-08', $content->getCreatedAt()->format('Y-m-d')); 153 $this->assertSame('2016-09-08', $content->getCreatedAt()->format('Y-m-d'));
diff --git a/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php b/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php
index adc2cf09..f44e6fbf 100644
--- a/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php
+++ b/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php
@@ -1,6 +1,6 @@
1<?php 1<?php
2 2
3namespace Wallabag\UserBundle\Tests\Controller; 3namespace Tests\Wallabag\UserBundle\Controller;
4 4
5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; 5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
6 6
diff --git a/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php b/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php
index 2b540fdf..c13bfbea 100644
--- a/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php
+++ b/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php
@@ -8,6 +8,8 @@ use PHPUnit\Framework\TestCase;
8use Symfony\Component\EventDispatcher\EventDispatcher; 8use Symfony\Component\EventDispatcher\EventDispatcher;
9use Symfony\Component\HttpFoundation\Request; 9use Symfony\Component\HttpFoundation\Request;
10use Symfony\Component\HttpFoundation\Response; 10use Symfony\Component\HttpFoundation\Response;
11use Symfony\Component\HttpFoundation\Session\Session;
12use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
11use Wallabag\CoreBundle\Entity\Config; 13use Wallabag\CoreBundle\Entity\Config;
12use Wallabag\UserBundle\Entity\User; 14use Wallabag\UserBundle\Entity\User;
13use Wallabag\UserBundle\EventListener\CreateConfigListener; 15use Wallabag\UserBundle\EventListener\CreateConfigListener;
@@ -22,6 +24,7 @@ class CreateConfigListenerTest extends TestCase
22 24
23 protected function setUp() 25 protected function setUp()
24 { 26 {
27 $session = new Session(new MockArraySessionStorage());
25 $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') 28 $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
26 ->disableOriginalConstructor() 29 ->disableOriginalConstructor()
27 ->getMock(); 30 ->getMock();
@@ -34,7 +37,8 @@ class CreateConfigListenerTest extends TestCase
34 'fr', 37 'fr',
35 1, 38 1,
36 1, 39 1,
37 1 40 1,
41 $session
38 ); 42 );
39 43
40 $this->dispatcher = new EventDispatcher(); 44 $this->dispatcher = new EventDispatcher();
diff --git a/tests/Wallabag/UserBundle/Mailer/AuthCodeMailerTest.php b/tests/Wallabag/UserBundle/Mailer/AuthCodeMailerTest.php
index aa176068..1713c10c 100644
--- a/tests/Wallabag/UserBundle/Mailer/AuthCodeMailerTest.php
+++ b/tests/Wallabag/UserBundle/Mailer/AuthCodeMailerTest.php
@@ -6,22 +6,6 @@ use PHPUnit\Framework\TestCase;
6use Wallabag\UserBundle\Entity\User; 6use Wallabag\UserBundle\Entity\User;
7use Wallabag\UserBundle\Mailer\AuthCodeMailer; 7use Wallabag\UserBundle\Mailer\AuthCodeMailer;
8 8
9/**
10 * @see https://www.pmg.com/blog/integration-testing-swift-mailer/
11 */
12final class CountableMemorySpool extends \Swift_MemorySpool implements \Countable
13{
14 public function count()
15 {
16 return \count($this->messages);
17 }
18
19 public function getMessages()
20 {
21 return $this->messages;
22 }
23}
24
25class AuthCodeMailerTest extends TestCase 9class AuthCodeMailerTest extends TestCase
26{ 10{
27 protected $mailer; 11 protected $mailer;
@@ -49,7 +33,7 @@ TWIG;
49 public function testSendEmail() 33 public function testSendEmail()
50 { 34 {
51 $user = new User(); 35 $user = new User();
52 $user->setTwoFactorAuthentication(true); 36 $user->setEmailTwoFactor(true);
53 $user->setEmailAuthCode(666666); 37 $user->setEmailAuthCode(666666);
54 $user->setEmail('test@wallabag.io'); 38 $user->setEmail('test@wallabag.io');
55 $user->setName('Bob'); 39 $user->setName('Bob');
diff --git a/tests/Wallabag/UserBundle/Mailer/CountableMemorySpool.php b/tests/Wallabag/UserBundle/Mailer/CountableMemorySpool.php
new file mode 100644
index 00000000..53f240a1
--- /dev/null
+++ b/tests/Wallabag/UserBundle/Mailer/CountableMemorySpool.php
@@ -0,0 +1,19 @@
1<?php
2
3namespace Tests\Wallabag\UserBundle\Mailer;
4
5/**
6 * @see https://www.pmg.com/blog/integration-testing-swift-mailer/
7 */
8final class CountableMemorySpool extends \Swift_MemorySpool implements \Countable
9{
10 public function count()
11 {
12 return \count($this->messages);
13 }
14
15 public function getMessages()
16 {
17 return $this->messages;
18 }
19}