3 namespace Wallabag\CoreBundle\Tests\Controller
;
5 use Wallabag\CoreBundle\Tests\WallabagTestCase
;
7 class ConfigControllerTest
extends WallabagTestCase
9 public function testLogin()
11 $client = $this->getClient();
13 $client->request('GET', '/new');
15 $this->assertEquals(302, $client->getResponse()->getStatusCode());
16 $this->assertContains('login', $client->getResponse()->headers
->get('location'));
19 public function testIndex()
21 $this->logInAs('admin');
22 $client = $this->getClient();
24 $crawler = $client->request('GET', '/config');
26 $this->assertEquals(200, $client->getResponse()->getStatusCode());
28 $this->assertCount(1, $crawler->filter('button[id=config_save]'));
29 $this->assertCount(1, $crawler->filter('button[id=change_passwd_save]'));
30 $this->assertCount(1, $crawler->filter('button[id=user_save]'));
33 public function testUpdate()
35 $this->logInAs('admin');
36 $client = $this->getClient();
38 $crawler = $client->request('GET', '/config');
40 $this->assertEquals(200, $client->getResponse()->getStatusCode());
42 $form = $crawler->filter('button[id=config_save]')->form();
45 'config[theme]' => 'baggy',
46 'config[items_per_page]' => '30',
47 'config[language]' => 'fr_FR',
50 $client->submit($form, $data);
52 $this->assertEquals(302, $client->getResponse()->getStatusCode());
54 $crawler = $client->followRedirect();
56 $this->assertGreaterThan(1, $alert = $crawler->filter('div.flash-notice')->extract(array('_text')));
57 $this->assertContains('Config saved', $alert[0]);
60 public function dataForUpdateFailed()
64 'config[theme]' => 'baggy',
65 'config[items_per_page]' => '',
66 'config[language]' => 'fr_FR',
69 'config[theme]' => 'baggy',
70 'config[items_per_page]' => '12',
71 'config[language]' => '',
77 * @dataProvider dataForUpdateFailed
79 public function testUpdateFailed($data)
81 $this->logInAs('admin');
82 $client = $this->getClient();
84 $crawler = $client->request('GET', '/config');
86 $this->assertEquals(200, $client->getResponse()->getStatusCode());
88 $form = $crawler->filter('button[id=config_save]')->form();
90 $crawler = $client->submit($form, $data);
92 $this->assertEquals(200, $client->getResponse()->getStatusCode());
94 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(array('_text')));
95 $this->assertContains('This value should not be blank', $alert[0]);
98 public function dataForChangePasswordFailed()
103 'change_passwd[old_password]' => 'baggy',
104 'change_passwd[new_password][first]' => '',
105 'change_passwd[new_password][second]' => '',
107 'Wrong value for your current password',
111 'change_passwd[old_password]' => 'mypassword',
112 'change_passwd[new_password][first]' => '',
113 'change_passwd[new_password][second]' => '',
115 'This value should not be blank',
119 'change_passwd[old_password]' => 'mypassword',
120 'change_passwd[new_password][first]' => 'hop',
121 'change_passwd[new_password][second]' => '',
123 'The password fields must match',
127 'change_passwd[old_password]' => 'mypassword',
128 'change_passwd[new_password][first]' => 'hop',
129 'change_passwd[new_password][second]' => 'hop',
131 'Password should by at least',
137 * @dataProvider dataForChangePasswordFailed
139 public function testChangePasswordFailed($data, $expectedMessage)
141 $this->logInAs('admin');
142 $client = $this->getClient();
144 $crawler = $client->request('GET', '/config');
146 $this->assertEquals(200, $client->getResponse()->getStatusCode());
148 $form = $crawler->filter('button[id=change_passwd_save]')->form();
150 $crawler = $client->submit($form, $data);
152 $this->assertEquals(200, $client->getResponse()->getStatusCode());
154 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(array('_text')));
155 $this->assertContains($expectedMessage, $alert[0]);
158 public function testChangePassword()
160 $this->logInAs('admin');
161 $client = $this->getClient();
163 $crawler = $client->request('GET', '/config');
165 $this->assertEquals(200, $client->getResponse()->getStatusCode());
167 $form = $crawler->filter('button[id=change_passwd_save]')->form();
170 'change_passwd[old_password]' => 'mypassword',
171 'change_passwd[new_password][first]' => 'mypassword',
172 'change_passwd[new_password][second]' => 'mypassword',
175 $client->submit($form, $data);
177 $this->assertEquals(302, $client->getResponse()->getStatusCode());
179 $crawler = $client->followRedirect();
181 $this->assertGreaterThan(1, $alert = $crawler->filter('div.flash-notice')->extract(array('_text')));
182 $this->assertContains('Password updated', $alert[0]);
185 public function dataForUserFailed()
190 'user[username]' => '',
194 'This value should not be blank.',
198 'user[username]' => 'ad',
202 'This value is too short.',
206 'user[username]' => 'admin',
208 'user[email]' => 'test',
210 'This value is not a valid email address.',
216 * @dataProvider dataForUserFailed
218 public function testUserFailed($data, $expectedMessage)
220 $this->logInAs('admin');
221 $client = $this->getClient();
223 $crawler = $client->request('GET', '/config');
225 $this->assertEquals(200, $client->getResponse()->getStatusCode());
227 $form = $crawler->filter('button[id=user_save]')->form();
229 $crawler = $client->submit($form, $data);
231 $this->assertEquals(200, $client->getResponse()->getStatusCode());
233 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(array('_text')));
234 $this->assertContains($expectedMessage, $alert[0]);
237 public function testUserUpdate()
239 $this->logInAs('admin');
240 $client = $this->getClient();
242 $crawler = $client->request('GET', '/config');
244 $this->assertEquals(200, $client->getResponse()->getStatusCode());
246 $form = $crawler->filter('button[id=user_save]')->form();
249 'user[username]' => 'admin',
250 'user[name]' => 'new name',
251 'user[email]' => 'admin@wallabag.io',
254 $client->submit($form, $data);
256 $this->assertEquals(302, $client->getResponse()->getStatusCode());
258 $crawler = $client->followRedirect();
260 $this->assertGreaterThan(1, $alert = $crawler->filter('div.flash-notice')->extract(array('_text')));
261 $this->assertContains('Information updated', $alert[0]);
264 public function dataForNewUserFailed()
269 'new_user[username]' => '',
270 'new_user[password]' => '',
271 'new_user[email]' => '',
273 'This value should not be blank.',
277 'new_user[username]' => 'ad',
278 'new_user[password]' => '',
279 'new_user[email]' => '',
281 'This value is too short.',
285 'new_user[username]' => 'wallace',
286 'new_user[password]' => '',
287 'new_user[email]' => 'test',
289 'This value is not a valid email address.',
293 'new_user[username]' => 'wallace',
294 'new_user[password]' => 'admin',
295 'new_user[email]' => 'wallace@wallace.me',
297 'Password should by at least',
303 * @dataProvider dataForNewUserFailed
305 public function testNewUserFailed($data, $expectedMessage)
307 $this->logInAs('admin');
308 $client = $this->getClient();
310 $crawler = $client->request('GET', '/config');
312 $this->assertEquals(200, $client->getResponse()->getStatusCode());
314 $form = $crawler->filter('button[id=new_user_save]')->form();
316 $crawler = $client->submit($form, $data);
318 $this->assertEquals(200, $client->getResponse()->getStatusCode());
320 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(array('_text')));
321 $this->assertContains($expectedMessage, $alert[0]);
324 public function testNewUserCreated()
326 $this->logInAs('admin');
327 $client = $this->getClient();
329 $crawler = $client->request('GET', '/config');
331 $this->assertEquals(200, $client->getResponse()->getStatusCode());
333 $form = $crawler->filter('button[id=new_user_save]')->form();
336 'new_user[username]' => 'wallace',
337 'new_user[password]' => 'wallace1',
338 'new_user[email]' => 'wallace@wallace.me',
341 $client->submit($form, $data);
343 $this->assertEquals(302, $client->getResponse()->getStatusCode());
345 $crawler = $client->followRedirect();
347 $this->assertGreaterThan(1, $alert = $crawler->filter('div.flash-notice')->extract(array('_text')));
348 $this->assertContains('User "wallace" added', $alert[0]);