]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Add tests 1683/head
authorJeremy Benoist <jeremy.benoist@gmail.com>
Mon, 22 Feb 2016 12:33:22 +0000 (13:33 +0100)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Mon, 22 Feb 2016 12:33:22 +0000 (13:33 +0100)
src/Wallabag/CoreBundle/Controller/ConfigController.php
src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php

index 87196b0ec3f2bb9d1794069a46dd24c2237be49d..1791eac23719e09ba34929ab0dd36ef162599107 100644 (file)
@@ -58,20 +58,16 @@ class ConfigController extends Controller
 
         if ($pwdForm->isValid()) {
             if ($this->get('craue_config')->get('demo_mode_enabled') && $this->get('craue_config')->get('demo_mode_username') === $user->getUsername()) {
-                $this->get('session')->getFlashBag()->add(
-                    'notice',
-                    'In demonstration mode, you can\'t change password for this user.'
-                );
+                $message = 'In demonstration mode, you can\'t change password for this user.';
             } else {
+                $message = 'Password updated';
+
                 $user->setPlainPassword($pwdForm->get('new_password')->getData());
                 $userManager->updateUser($user, true);
-
-                $this->get('session')->getFlashBag()->add(
-                    'notice',
-                    'Password updated'
-                );
             }
 
+            $this->get('session')->getFlashBag()->add('notice', $message);
+
             return $this->redirect($this->generateUrl('config').'#set4');
         }
 
index 6c370a2d8373781d4d997a488fe1405f1ff4e81b..2af93ffecffe7051dfc114a453b297def5b86189 100644 (file)
@@ -577,4 +577,34 @@ class ConfigControllerTest extends WallabagCoreTestCase
         $this->assertEquals(403, $client->getResponse()->getStatusCode());
         $this->assertContains('You can not access this tagging ryle', $client->getResponse()->getContent());
     }
+
+    public function testDemoMode()
+    {
+        $this->logInAs('admin');
+        $client = $this->getClient();
+
+        $config = $client->getContainer()->get('craue_config');
+        $config->set('demo_mode_enabled', 1);
+        $config->set('demo_mode_username', 'admin');
+
+        $crawler = $client->request('GET', '/config');
+
+        $this->assertEquals(200, $client->getResponse()->getStatusCode());
+
+        $form = $crawler->filter('button[id=change_passwd_save]')->form();
+
+        $data = array(
+            'change_passwd[old_password]' => 'mypassword',
+            'change_passwd[new_password][first]' => 'mypassword',
+            'change_passwd[new_password][second]' => 'mypassword',
+        );
+
+        $client->submit($form, $data);
+
+        $this->assertEquals(302, $client->getResponse()->getStatusCode());
+        $this->assertContains('In demonstration mode, you can\'t change password for this user.', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
+
+        $config->set('demo_mode_enabled', 0);
+        $config->set('demo_mode_username', 'wallabag');
+    }
 }