]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
Merge remote-tracking branch 'origin/master' into 2.4
[github/wallabag/wallabag.git] / tests / Wallabag / CoreBundle / Controller / ConfigControllerTest.php
index e4bf0998810e6e2f4f3c03bab839921c3efb61ee..1090a686bdd1ea1e2158755af568974f27e82e8f 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-namespace tests\Wallabag\CoreBundle\Controller;
+namespace Tests\Wallabag\CoreBundle\Controller;
 
 use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
 use Wallabag\AnnotationBundle\Entity\Annotation;
@@ -742,7 +742,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
         $em->persist($tag);
 
         $entry = new Entry($user);
-        $entry->setUrl('http://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html');
+        $entry->setUrl('https://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html');
         $entry->setContent('Youhou');
         $entry->setTitle('Youhou');
         $entry->addTag($tag);
@@ -827,7 +827,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
         $em->persist($tag);
 
         $entry = new Entry($user);
-        $entry->setUrl('http://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html');
+        $entry->setUrl('https://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html');
         $entry->setContent('Youhou');
         $entry->setTitle('Youhou');
         $entry->addTag($tag);
@@ -845,11 +845,11 @@ class ConfigControllerTest extends WallabagCoreTestCase
         $em->persist($tagArchived);
 
         $entryArchived = new Entry($user);
-        $entryArchived->setUrl('http://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html');
+        $entryArchived->setUrl('https://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html');
         $entryArchived->setContent('Youhou');
         $entryArchived->setTitle('Youhou');
         $entryArchived->addTag($tagArchived);
-        $entryArchived->setArchived(true);
+        $entryArchived->updateArchived(true);
         $em->persist($entryArchived);
 
         $annotationArchived = new Annotation($user);
@@ -903,7 +903,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
         $em->persist($tag);
 
         $entry = new Entry($user);
-        $entry->setUrl('http://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html');
+        $entry->setUrl('https://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html');
         $entry->setContent('Youhou');
         $entry->setTitle('Youhou');
         $entry->addTag($tag);
@@ -965,4 +965,120 @@ class ConfigControllerTest extends WallabagCoreTestCase
 
         $client->request('GET', '/config/view-mode');
     }
+
+    public function testChangeLocaleWithoutReferer()
+    {
+        $client = $this->getClient();
+
+        $client->request('GET', '/locale/de');
+        $client->followRedirect();
+
+        $this->assertSame('de', $client->getRequest()->getLocale());
+        $this->assertSame('de', $client->getContainer()->get('session')->get('_locale'));
+    }
+
+    public function testChangeLocaleWithReferer()
+    {
+        $client = $this->getClient();
+
+        $client->request('GET', '/login');
+        $client->request('GET', '/locale/de');
+        $client->followRedirect();
+
+        $this->assertSame('de', $client->getRequest()->getLocale());
+        $this->assertSame('de', $client->getContainer()->get('session')->get('_locale'));
+    }
+
+    public function testChangeLocaleToBadLocale()
+    {
+        $client = $this->getClient();
+
+        $client->request('GET', '/login');
+        $client->request('GET', '/locale/yuyuyuyu');
+        $client->followRedirect();
+
+        $this->assertNotSame('yuyuyuyu', $client->getRequest()->getLocale());
+        $this->assertNotSame('yuyuyuyu', $client->getContainer()->get('session')->get('_locale'));
+    }
+
+    public function testUserEnable2faEmail()
+    {
+        $this->logInAs('admin');
+        $client = $this->getClient();
+
+        $crawler = $client->request('GET', '/config/otp/email');
+
+        $this->assertSame(302, $client->getResponse()->getStatusCode());
+
+        $crawler = $client->followRedirect();
+
+        $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text']));
+        $this->assertContains('flashes.config.notice.otp_enabled', $alert[0]);
+
+        // restore user
+        $em = $this->getEntityManager();
+        $user = $em
+            ->getRepository('WallabagUserBundle:User')
+            ->findOneByUsername('admin');
+
+        $this->assertTrue($user->isEmailTwoFactor());
+
+        $user->setEmailTwoFactor(false);
+        $em->persist($user);
+        $em->flush();
+    }
+
+    public function testUserEnable2faGoogle()
+    {
+        $this->logInAs('admin');
+        $client = $this->getClient();
+
+        $crawler = $client->request('GET', '/config/otp/app');
+
+        $this->assertSame(200, $client->getResponse()->getStatusCode());
+
+        // restore user
+        $em = $this->getEntityManager();
+        $user = $em
+            ->getRepository('WallabagUserBundle:User')
+            ->findOneByUsername('admin');
+
+        $this->assertTrue($user->isGoogleTwoFactor());
+        $this->assertGreaterThan(0, $user->getBackupCodes());
+
+        $user->setGoogleAuthenticatorSecret(false);
+        $user->setBackupCodes(null);
+        $em->persist($user);
+        $em->flush();
+    }
+
+    public function testUserEnable2faGoogleCancel()
+    {
+        $this->logInAs('admin');
+        $client = $this->getClient();
+
+        $crawler = $client->request('GET', '/config/otp/app');
+
+        $this->assertSame(200, $client->getResponse()->getStatusCode());
+
+        // restore user
+        $em = $this->getEntityManager();
+        $user = $em
+            ->getRepository('WallabagUserBundle:User')
+            ->findOneByUsername('admin');
+
+        $this->assertTrue($user->isGoogleTwoFactor());
+        $this->assertGreaterThan(0, $user->getBackupCodes());
+
+        $crawler = $client->request('GET', '/config/otp/app/cancel');
+
+        $this->assertSame(302, $client->getResponse()->getStatusCode());
+
+        $user = $em
+            ->getRepository('WallabagUserBundle:User')
+            ->findOneByUsername('admin');
+
+        $this->assertFalse($user->isGoogleTwoFactor());
+        $this->assertEmpty($user->getBackupCodes());
+    }
 }