diff options
author | Jeremy <jeremy.benoist@gmail.com> | 2015-02-17 21:03:23 +0100 |
---|---|---|
committer | Jeremy <jeremy.benoist@gmail.com> | 2015-02-17 21:03:23 +0100 |
commit | d9085c63e35bb708f560722fff5f4f5ad322c27b (patch) | |
tree | 73e2183afe218442ce44faffe469e31f630d89d9 /src/Wallabag/CoreBundle/Tests/Controller | |
parent | 7781faa0b0749b0d9842fddec3e337db04d44a10 (diff) | |
download | wallabag-d9085c63e35bb708f560722fff5f4f5ad322c27b.tar.gz wallabag-d9085c63e35bb708f560722fff5f4f5ad322c27b.tar.zst wallabag-d9085c63e35bb708f560722fff5f4f5ad322c27b.zip |
Handle password change
Diffstat (limited to 'src/Wallabag/CoreBundle/Tests/Controller')
-rw-r--r-- | src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php | 94 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php | 8 |
2 files changed, 95 insertions, 7 deletions
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php index 30809a04..4aceed15 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php | |||
@@ -26,7 +26,8 @@ class ConfigControllerTest extends WallabagTestCase | |||
26 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 26 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); |
27 | 27 | ||
28 | $this->assertCount(1, $crawler->filter('input[type=number]')); | 28 | $this->assertCount(1, $crawler->filter('input[type=number]')); |
29 | $this->assertCount(1, $crawler->filter('button[type=submit]')); | 29 | $this->assertCount(1, $crawler->filter('button[id=config_save]')); |
30 | $this->assertCount(1, $crawler->filter('button[id=change_passwd_save]')); | ||
30 | } | 31 | } |
31 | 32 | ||
32 | public function testUpdate() | 33 | public function testUpdate() |
@@ -38,7 +39,7 @@ class ConfigControllerTest extends WallabagTestCase | |||
38 | 39 | ||
39 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 40 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); |
40 | 41 | ||
41 | $form = $crawler->filter('button[type=submit]')->form(); | 42 | $form = $crawler->filter('button[id=config_save]')->form(); |
42 | 43 | ||
43 | $data = array( | 44 | $data = array( |
44 | 'config[theme]' => 'baggy', | 45 | 'config[theme]' => 'baggy', |
@@ -84,7 +85,7 @@ class ConfigControllerTest extends WallabagTestCase | |||
84 | 85 | ||
85 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 86 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); |
86 | 87 | ||
87 | $form = $crawler->filter('button[type=submit]')->form(); | 88 | $form = $crawler->filter('button[id=config_save]')->form(); |
88 | 89 | ||
89 | $crawler = $client->submit($form, $data); | 90 | $crawler = $client->submit($form, $data); |
90 | 91 | ||
@@ -93,4 +94,91 @@ class ConfigControllerTest extends WallabagTestCase | |||
93 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(array('_text'))); | 94 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(array('_text'))); |
94 | $this->assertContains('This value should not be blank', $alert[0]); | 95 | $this->assertContains('This value should not be blank', $alert[0]); |
95 | } | 96 | } |
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 | } | ||
96 | } | 184 | } |
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php index d77e2303..fcfa8ccf 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php | |||
@@ -47,7 +47,7 @@ class WallabagRestControllerTest extends WallabagTestCase | |||
47 | $client->request('GET', '/api/salts/admin.json'); | 47 | $client->request('GET', '/api/salts/admin.json'); |
48 | $salt = json_decode($client->getResponse()->getContent()); | 48 | $salt = json_decode($client->getResponse()->getContent()); |
49 | 49 | ||
50 | $headers = $this->generateHeaders('admin', 'test', $salt[0]); | 50 | $headers = $this->generateHeaders('admin', 'mypassword', $salt[0]); |
51 | 51 | ||
52 | $entry = $client->getContainer() | 52 | $entry = $client->getContainer() |
53 | ->get('doctrine.orm.entity_manager') | 53 | ->get('doctrine.orm.entity_manager') |
@@ -73,7 +73,7 @@ class WallabagRestControllerTest extends WallabagTestCase | |||
73 | $client->request('GET', '/api/salts/admin.json'); | 73 | $client->request('GET', '/api/salts/admin.json'); |
74 | $salt = json_decode($client->getResponse()->getContent()); | 74 | $salt = json_decode($client->getResponse()->getContent()); |
75 | 75 | ||
76 | $headers = $this->generateHeaders('admin', 'test', $salt[0]); | 76 | $headers = $this->generateHeaders('admin', 'mypassword', $salt[0]); |
77 | 77 | ||
78 | $entry = $client->getContainer() | 78 | $entry = $client->getContainer() |
79 | ->get('doctrine.orm.entity_manager') | 79 | ->get('doctrine.orm.entity_manager') |
@@ -101,7 +101,7 @@ class WallabagRestControllerTest extends WallabagTestCase | |||
101 | $client->request('GET', '/api/salts/admin.json'); | 101 | $client->request('GET', '/api/salts/admin.json'); |
102 | $salt = json_decode($client->getResponse()->getContent()); | 102 | $salt = json_decode($client->getResponse()->getContent()); |
103 | 103 | ||
104 | $headers = $this->generateHeaders('admin', 'test', $salt[0]); | 104 | $headers = $this->generateHeaders('admin', 'mypassword', $salt[0]); |
105 | 105 | ||
106 | $client->request('GET', '/api/entries', array(), array(), $headers); | 106 | $client->request('GET', '/api/entries', array(), array(), $headers); |
107 | 107 | ||
@@ -125,7 +125,7 @@ class WallabagRestControllerTest extends WallabagTestCase | |||
125 | $client->request('GET', '/api/salts/admin.json'); | 125 | $client->request('GET', '/api/salts/admin.json'); |
126 | $salt = json_decode($client->getResponse()->getContent()); | 126 | $salt = json_decode($client->getResponse()->getContent()); |
127 | 127 | ||
128 | $headers = $this->generateHeaders('admin', 'test', $salt[0]); | 128 | $headers = $this->generateHeaders('admin', 'mypassword', $salt[0]); |
129 | 129 | ||
130 | $entry = $client->getContainer() | 130 | $entry = $client->getContainer() |
131 | ->get('doctrine.orm.entity_manager') | 131 | ->get('doctrine.orm.entity_manager') |