]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php
Handle password change
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Tests / Controller / ConfigControllerTest.php
CommitLineData
4d85d7e9
J
1<?php
2
3namespace Wallabag\CoreBundle\Tests\Controller;
4
5use Wallabag\CoreBundle\Tests\WallabagTestCase;
6
7class ConfigControllerTest extends WallabagTestCase
8{
9 public function testLogin()
10 {
11 $client = $this->getClient();
12
13 $client->request('GET', '/new');
14
15 $this->assertEquals(302, $client->getResponse()->getStatusCode());
16 $this->assertContains('login', $client->getResponse()->headers->get('location'));
17 }
18
19 public function testIndex()
20 {
21 $this->logInAs('admin');
22 $client = $this->getClient();
23
24 $crawler = $client->request('GET', '/config');
25
26 $this->assertEquals(200, $client->getResponse()->getStatusCode());
27
28 $this->assertCount(1, $crawler->filter('input[type=number]'));
d9085c63
J
29 $this->assertCount(1, $crawler->filter('button[id=config_save]'));
30 $this->assertCount(1, $crawler->filter('button[id=change_passwd_save]'));
4d85d7e9
J
31 }
32
33 public function testUpdate()
34 {
35 $this->logInAs('admin');
36 $client = $this->getClient();
37
38 $crawler = $client->request('GET', '/config');
39
40 $this->assertEquals(200, $client->getResponse()->getStatusCode());
41
d9085c63 42 $form = $crawler->filter('button[id=config_save]')->form();
4d85d7e9
J
43
44 $data = array(
45 'config[theme]' => 'baggy',
46 'config[items_per_page]' => '30',
47 'config[language]' => 'fr_FR',
48 );
49
50 $client->submit($form, $data);
51
52 $this->assertEquals(302, $client->getResponse()->getStatusCode());
53
54 $crawler = $client->followRedirect();
55
56 $this->assertGreaterThan(1, $alert = $crawler->filter('div.flash-notice')->extract(array('_text')));
57 $this->assertContains('Config saved', $alert[0]);
58 }
59
60 public function dataForUpdateFailed()
61 {
62 return array(
63 array(array(
64 'config[theme]' => 'baggy',
65 'config[items_per_page]' => '',
66 'config[language]' => 'fr_FR',
67 )),
68 array(array(
69 'config[theme]' => 'baggy',
70 'config[items_per_page]' => '12',
71 'config[language]' => '',
72 )),
73 );
74 }
75
76 /**
77 * @dataProvider dataForUpdateFailed
78 */
79 public function testUpdateFailed($data)
80 {
81 $this->logInAs('admin');
82 $client = $this->getClient();
83
84 $crawler = $client->request('GET', '/config');
85
86 $this->assertEquals(200, $client->getResponse()->getStatusCode());
87
d9085c63 88 $form = $crawler->filter('button[id=config_save]')->form();
4d85d7e9
J
89
90 $crawler = $client->submit($form, $data);
91
92 $this->assertEquals(200, $client->getResponse()->getStatusCode());
93
94 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(array('_text')));
95 $this->assertContains('This value should not be blank', $alert[0]);
96 }
d9085c63
J
97
98 public function dataForChangePasswordFailed()
99 {
100 return array(
101 array(
102 array(
103 'change_passwd[old_password]' => 'baggy',
104 'change_passwd[new_password][first]' => '',
105 'change_passwd[new_password][second]' => '',
106 ),
107 'Wrong value for your current password'
108 ),
109 array(
110 array(
111 'change_passwd[old_password]' => 'mypassword',
112 'change_passwd[new_password][first]' => '',
113 'change_passwd[new_password][second]' => '',
114 ),
115 'This value should not be blank'
116 ),
117 array(
118 array(
119 'change_passwd[old_password]' => 'mypassword',
120 'change_passwd[new_password][first]' => 'hop',
121 'change_passwd[new_password][second]' => '',
122 ),
123 'The password fields must match'
124 ),
125 array(
126 array(
127 'change_passwd[old_password]' => 'mypassword',
128 'change_passwd[new_password][first]' => 'hop',
129 'change_passwd[new_password][second]' => 'hop',
130 ),
131 'Password should by at least 6 chars long'
132 ),
133 );
134 }
135
136 /**
137 * @dataProvider dataForChangePasswordFailed
138 */
139 public function testChangePasswordFailed($data, $expectedMessage)
140 {
141 $this->logInAs('admin');
142 $client = $this->getClient();
143
144 $crawler = $client->request('GET', '/config');
145
146 $this->assertEquals(200, $client->getResponse()->getStatusCode());
147
148 $form = $crawler->filter('button[id=change_passwd_save]')->form();
149
150 $crawler = $client->submit($form, $data);
151
152 $this->assertEquals(200, $client->getResponse()->getStatusCode());
153
154 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(array('_text')));
155 $this->assertContains($expectedMessage, $alert[0]);
156 }
157
158 public function testChangePassword()
159 {
160 $this->logInAs('admin');
161 $client = $this->getClient();
162
163 $crawler = $client->request('GET', '/config');
164
165 $this->assertEquals(200, $client->getResponse()->getStatusCode());
166
167 $form = $crawler->filter('button[id=change_passwd_save]')->form();
168
169 $data = array(
170 'change_passwd[old_password]' => 'mypassword',
171 'change_passwd[new_password][first]' => 'mypassword',
172 'change_passwd[new_password][second]' => 'mypassword',
173 );
174
175 $client->submit($form, $data);
176
177 $this->assertEquals(302, $client->getResponse()->getStatusCode());
178
179 $crawler = $client->followRedirect();
180
181 $this->assertGreaterThan(1, $alert = $crawler->filter('div.flash-notice')->extract(array('_text')));
182 $this->assertContains('Password updated', $alert[0]);
183 }
4d85d7e9 184}