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('input[type=number]'));
29 $this->assertCount(1, $crawler->filter('button[id=config_save]'));
30 $this->assertCount(1, $crawler->filter('button[id=change_passwd_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 6 chars long'
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]);