aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2016-02-22 13:33:22 +0100
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-02-22 13:33:22 +0100
commitb6c00b0b807108cd54ab32fa73f9c196f4f12d97 (patch)
tree6a716b3cd7380202b977e353dbcd97adef6849fa /src
parente5b527096220f9c94a745275a27cd4b2c106ee2c (diff)
downloadwallabag-b6c00b0b807108cd54ab32fa73f9c196f4f12d97.tar.gz
wallabag-b6c00b0b807108cd54ab32fa73f9c196f4f12d97.tar.zst
wallabag-b6c00b0b807108cd54ab32fa73f9c196f4f12d97.zip
Add tests
Diffstat (limited to 'src')
-rw-r--r--src/Wallabag/CoreBundle/Controller/ConfigController.php14
-rw-r--r--src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php30
2 files changed, 35 insertions, 9 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php
index 87196b0e..1791eac2 100644
--- a/src/Wallabag/CoreBundle/Controller/ConfigController.php
+++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php
@@ -58,20 +58,16 @@ class ConfigController extends Controller
58 58
59 if ($pwdForm->isValid()) { 59 if ($pwdForm->isValid()) {
60 if ($this->get('craue_config')->get('demo_mode_enabled') && $this->get('craue_config')->get('demo_mode_username') === $user->getUsername()) { 60 if ($this->get('craue_config')->get('demo_mode_enabled') && $this->get('craue_config')->get('demo_mode_username') === $user->getUsername()) {
61 $this->get('session')->getFlashBag()->add( 61 $message = 'In demonstration mode, you can\'t change password for this user.';
62 'notice',
63 'In demonstration mode, you can\'t change password for this user.'
64 );
65 } else { 62 } else {
63 $message = 'Password updated';
64
66 $user->setPlainPassword($pwdForm->get('new_password')->getData()); 65 $user->setPlainPassword($pwdForm->get('new_password')->getData());
67 $userManager->updateUser($user, true); 66 $userManager->updateUser($user, true);
68
69 $this->get('session')->getFlashBag()->add(
70 'notice',
71 'Password updated'
72 );
73 } 67 }
74 68
69 $this->get('session')->getFlashBag()->add('notice', $message);
70
75 return $this->redirect($this->generateUrl('config').'#set4'); 71 return $this->redirect($this->generateUrl('config').'#set4');
76 } 72 }
77 73
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php
index 6c370a2d..2af93ffe 100644
--- a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php
+++ b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php
@@ -577,4 +577,34 @@ class ConfigControllerTest extends WallabagCoreTestCase
577 $this->assertEquals(403, $client->getResponse()->getStatusCode()); 577 $this->assertEquals(403, $client->getResponse()->getStatusCode());
578 $this->assertContains('You can not access this tagging ryle', $client->getResponse()->getContent()); 578 $this->assertContains('You can not access this tagging ryle', $client->getResponse()->getContent());
579 } 579 }
580
581 public function testDemoMode()
582 {
583 $this->logInAs('admin');
584 $client = $this->getClient();
585
586 $config = $client->getContainer()->get('craue_config');
587 $config->set('demo_mode_enabled', 1);
588 $config->set('demo_mode_username', 'admin');
589
590 $crawler = $client->request('GET', '/config');
591
592 $this->assertEquals(200, $client->getResponse()->getStatusCode());
593
594 $form = $crawler->filter('button[id=change_passwd_save]')->form();
595
596 $data = array(
597 'change_passwd[old_password]' => 'mypassword',
598 'change_passwd[new_password][first]' => 'mypassword',
599 'change_passwd[new_password][second]' => 'mypassword',
600 );
601
602 $client->submit($form, $data);
603
604 $this->assertEquals(302, $client->getResponse()->getStatusCode());
605 $this->assertContains('In demonstration mode, you can\'t change password for this user.', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
606
607 $config->set('demo_mode_enabled', 0);
608 $config->set('demo_mode_username', 'wallabag');
609 }
580} 610}