]>
Commit | Line | Data |
---|---|---|
4d85d7e9 J |
1 | <?php |
2 | ||
1e0d8ad7 | 3 | namespace Tests\Wallabag\CoreBundle\Controller; |
4d85d7e9 | 4 | |
34be2d5d | 5 | use Symfony\Component\HttpFoundation\File\UploadedFile; |
23634d5d | 6 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; |
f808b016 | 7 | use Wallabag\AnnotationBundle\Entity\Annotation; |
c3396c65 | 8 | use Wallabag\CoreBundle\Entity\Config; |
206bade5 JB |
9 | use Wallabag\CoreBundle\Entity\Entry; |
10 | use Wallabag\CoreBundle\Entity\Tag; | |
f808b016 | 11 | use Wallabag\UserBundle\Entity\User; |
4d85d7e9 | 12 | |
769e19dc | 13 | class ConfigControllerTest extends WallabagCoreTestCase |
4d85d7e9 J |
14 | { |
15 | public function testLogin() | |
16 | { | |
17 | $client = $this->getClient(); | |
18 | ||
19 | $client->request('GET', '/new'); | |
20 | ||
f808b016 | 21 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
4d85d7e9 J |
22 | $this->assertContains('login', $client->getResponse()->headers->get('location')); |
23 | } | |
24 | ||
25 | public function testIndex() | |
26 | { | |
27 | $this->logInAs('admin'); | |
28 | $client = $this->getClient(); | |
29 | ||
30 | $crawler = $client->request('GET', '/config'); | |
31 | ||
f808b016 | 32 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
4d85d7e9 | 33 | |
d9085c63 J |
34 | $this->assertCount(1, $crawler->filter('button[id=config_save]')); |
35 | $this->assertCount(1, $crawler->filter('button[id=change_passwd_save]')); | |
c844dc0c | 36 | $this->assertCount(1, $crawler->filter('button[id=update_user_save]')); |
531c8d0a | 37 | $this->assertCount(1, $crawler->filter('button[id=feed_config_save]')); |
4d85d7e9 J |
38 | } |
39 | ||
40 | public function testUpdate() | |
41 | { | |
42 | $this->logInAs('admin'); | |
43 | $client = $this->getClient(); | |
44 | ||
45 | $crawler = $client->request('GET', '/config'); | |
46 | ||
f808b016 | 47 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
4d85d7e9 | 48 | |
d9085c63 | 49 | $form = $crawler->filter('button[id=config_save]')->form(); |
4d85d7e9 | 50 | |
4094ea47 | 51 | $data = [ |
23ff8d36 | 52 | 'config[theme]' => 'baggy', |
4d85d7e9 | 53 | 'config[items_per_page]' => '30', |
41022cb2 | 54 | 'config[reading_speed]' => '100', |
a42f38d9 | 55 | 'config[action_mark_as_read]' => '0', |
c89d35e8 | 56 | 'config[language]' => 'en', |
4094ea47 | 57 | ]; |
4d85d7e9 J |
58 | |
59 | $client->submit($form, $data); | |
60 | ||
f808b016 | 61 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
4d85d7e9 J |
62 | |
63 | $crawler = $client->followRedirect(); | |
64 | ||
bf3dc999 | 65 | $this->assertContains('flashes.config.notice.config_saved', $crawler->filter('body')->extract(['_text'])[0]); |
4d85d7e9 J |
66 | } |
67 | ||
c4c062cc NL |
68 | public function testChangeReadingSpeed() |
69 | { | |
70 | $this->logInAs('admin'); | |
7ab5eb95 | 71 | $this->useTheme('baggy'); |
c4c062cc NL |
72 | $client = $this->getClient(); |
73 | ||
7ab5eb95 | 74 | $entry = new Entry($this->getLoggedInUser()); |
75 | $entry->setUrl('http://0.0.0.0/test-entry1') | |
76 | ->setReadingTime(22); | |
77 | $this->getEntityManager()->persist($entry); | |
78 | ||
79 | $this->getEntityManager()->flush(); | |
80 | $this->getEntityManager()->clear(); | |
81 | ||
c4c062cc NL |
82 | $crawler = $client->request('GET', '/unread/list'); |
83 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
84 | $dataFilters = [ | |
85 | 'entry_filter[readingTime][right_number]' => 22, | |
86 | 'entry_filter[readingTime][left_number]' => 22, | |
87 | ]; | |
88 | $crawler = $client->submit($form, $dataFilters); | |
89 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
90 | ||
91 | // Change reading speed | |
92 | $crawler = $client->request('GET', '/config'); | |
93 | $form = $crawler->filter('button[id=config_save]')->form(); | |
94 | $data = [ | |
41022cb2 | 95 | 'config[reading_speed]' => '400', |
c4c062cc NL |
96 | ]; |
97 | $client->submit($form, $data); | |
98 | ||
99 | // Is the entry still available via filters? | |
100 | $crawler = $client->request('GET', '/unread/list'); | |
101 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
102 | $crawler = $client->submit($form, $dataFilters); | |
103 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | |
104 | ||
105 | // Restore old configuration | |
106 | $crawler = $client->request('GET', '/config'); | |
107 | $form = $crawler->filter('button[id=config_save]')->form(); | |
108 | $data = [ | |
41022cb2 | 109 | 'config[reading_speed]' => '100', |
c4c062cc NL |
110 | ]; |
111 | $client->submit($form, $data); | |
112 | } | |
113 | ||
4d85d7e9 J |
114 | public function dataForUpdateFailed() |
115 | { | |
4094ea47 JB |
116 | return [ |
117 | [[ | |
23ff8d36 | 118 | 'config[theme]' => 'baggy', |
4d85d7e9 | 119 | 'config[items_per_page]' => '', |
c89d35e8 | 120 | 'config[language]' => 'en', |
4094ea47 JB |
121 | ]], |
122 | ]; | |
4d85d7e9 J |
123 | } |
124 | ||
125 | /** | |
126 | * @dataProvider dataForUpdateFailed | |
127 | */ | |
128 | public function testUpdateFailed($data) | |
129 | { | |
130 | $this->logInAs('admin'); | |
131 | $client = $this->getClient(); | |
132 | ||
133 | $crawler = $client->request('GET', '/config'); | |
134 | ||
f808b016 | 135 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
4d85d7e9 | 136 | |
d9085c63 | 137 | $form = $crawler->filter('button[id=config_save]')->form(); |
4d85d7e9 J |
138 | |
139 | $crawler = $client->submit($form, $data); | |
140 | ||
f808b016 | 141 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
4d85d7e9 | 142 | |
4094ea47 | 143 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); |
4d85d7e9 J |
144 | $this->assertContains('This value should not be blank', $alert[0]); |
145 | } | |
d9085c63 J |
146 | |
147 | public function dataForChangePasswordFailed() | |
148 | { | |
4094ea47 JB |
149 | return [ |
150 | [ | |
151 | [ | |
4ab58dcf | 152 | 'change_passwd[old_password]' => 'material', |
d9085c63 J |
153 | 'change_passwd[new_password][first]' => '', |
154 | 'change_passwd[new_password][second]' => '', | |
4094ea47 | 155 | ], |
0d42217e | 156 | 'validator.password_wrong_value', |
4094ea47 JB |
157 | ], |
158 | [ | |
159 | [ | |
d9085c63 J |
160 | 'change_passwd[old_password]' => 'mypassword', |
161 | 'change_passwd[new_password][first]' => '', | |
162 | 'change_passwd[new_password][second]' => '', | |
4094ea47 | 163 | ], |
c0d9eba0 | 164 | 'This value should not be blank', |
4094ea47 JB |
165 | ], |
166 | [ | |
167 | [ | |
d9085c63 J |
168 | 'change_passwd[old_password]' => 'mypassword', |
169 | 'change_passwd[new_password][first]' => 'hop', | |
170 | 'change_passwd[new_password][second]' => '', | |
4094ea47 | 171 | ], |
0d42217e | 172 | 'validator.password_must_match', |
4094ea47 JB |
173 | ], |
174 | [ | |
175 | [ | |
d9085c63 J |
176 | 'change_passwd[old_password]' => 'mypassword', |
177 | 'change_passwd[new_password][first]' => 'hop', | |
178 | 'change_passwd[new_password][second]' => 'hop', | |
4094ea47 | 179 | ], |
0d42217e | 180 | 'validator.password_too_short', |
4094ea47 JB |
181 | ], |
182 | ]; | |
d9085c63 J |
183 | } |
184 | ||
185 | /** | |
186 | * @dataProvider dataForChangePasswordFailed | |
187 | */ | |
188 | public function testChangePasswordFailed($data, $expectedMessage) | |
189 | { | |
190 | $this->logInAs('admin'); | |
191 | $client = $this->getClient(); | |
192 | ||
193 | $crawler = $client->request('GET', '/config'); | |
194 | ||
f808b016 | 195 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
d9085c63 J |
196 | |
197 | $form = $crawler->filter('button[id=change_passwd_save]')->form(); | |
198 | ||
199 | $crawler = $client->submit($form, $data); | |
200 | ||
f808b016 | 201 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
d9085c63 | 202 | |
4094ea47 | 203 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); |
d9085c63 J |
204 | $this->assertContains($expectedMessage, $alert[0]); |
205 | } | |
206 | ||
207 | public function testChangePassword() | |
208 | { | |
209 | $this->logInAs('admin'); | |
210 | $client = $this->getClient(); | |
211 | ||
212 | $crawler = $client->request('GET', '/config'); | |
213 | ||
f808b016 | 214 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
d9085c63 J |
215 | |
216 | $form = $crawler->filter('button[id=change_passwd_save]')->form(); | |
217 | ||
4094ea47 | 218 | $data = [ |
d9085c63 J |
219 | 'change_passwd[old_password]' => 'mypassword', |
220 | 'change_passwd[new_password][first]' => 'mypassword', | |
221 | 'change_passwd[new_password][second]' => 'mypassword', | |
4094ea47 | 222 | ]; |
d9085c63 J |
223 | |
224 | $client->submit($form, $data); | |
225 | ||
f808b016 | 226 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
d9085c63 J |
227 | |
228 | $crawler = $client->followRedirect(); | |
229 | ||
bf3dc999 | 230 | $this->assertContains('flashes.config.notice.password_updated', $crawler->filter('body')->extract(['_text'])[0]); |
d9085c63 | 231 | } |
c0d9eba0 J |
232 | |
233 | public function dataForUserFailed() | |
234 | { | |
4094ea47 JB |
235 | return [ |
236 | [ | |
237 | [ | |
c844dc0c J |
238 | 'update_user[name]' => '', |
239 | 'update_user[email]' => '', | |
4094ea47 | 240 | ], |
0d42217e | 241 | 'fos_user.email.blank', |
4094ea47 JB |
242 | ], |
243 | [ | |
244 | [ | |
c844dc0c J |
245 | 'update_user[name]' => '', |
246 | 'update_user[email]' => 'test', | |
4094ea47 | 247 | ], |
0d42217e | 248 | 'fos_user.email.invalid', |
4094ea47 JB |
249 | ], |
250 | ]; | |
c0d9eba0 J |
251 | } |
252 | ||
253 | /** | |
254 | * @dataProvider dataForUserFailed | |
255 | */ | |
256 | public function testUserFailed($data, $expectedMessage) | |
257 | { | |
258 | $this->logInAs('admin'); | |
259 | $client = $this->getClient(); | |
260 | ||
261 | $crawler = $client->request('GET', '/config'); | |
262 | ||
f808b016 | 263 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
c0d9eba0 | 264 | |
c844dc0c | 265 | $form = $crawler->filter('button[id=update_user_save]')->form(); |
c0d9eba0 J |
266 | |
267 | $crawler = $client->submit($form, $data); | |
268 | ||
f808b016 | 269 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
c0d9eba0 | 270 | |
4094ea47 | 271 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); |
c0d9eba0 J |
272 | $this->assertContains($expectedMessage, $alert[0]); |
273 | } | |
274 | ||
275 | public function testUserUpdate() | |
276 | { | |
277 | $this->logInAs('admin'); | |
278 | $client = $this->getClient(); | |
279 | ||
280 | $crawler = $client->request('GET', '/config'); | |
281 | ||
f808b016 | 282 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
c0d9eba0 | 283 | |
c844dc0c | 284 | $form = $crawler->filter('button[id=update_user_save]')->form(); |
c0d9eba0 | 285 | |
4094ea47 | 286 | $data = [ |
c844dc0c J |
287 | 'update_user[name]' => 'new name', |
288 | 'update_user[email]' => 'admin@wallabag.io', | |
4094ea47 | 289 | ]; |
c0d9eba0 J |
290 | |
291 | $client->submit($form, $data); | |
292 | ||
f808b016 | 293 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
c0d9eba0 J |
294 | |
295 | $crawler = $client->followRedirect(); | |
296 | ||
4094ea47 | 297 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); |
4204a06b | 298 | $this->assertContains('flashes.config.notice.user_updated', $alert[0]); |
c0d9eba0 | 299 | } |
e4977b8a | 300 | |
531c8d0a | 301 | public function testFeedUpdateResetToken() |
371ac69a J |
302 | { |
303 | $this->logInAs('admin'); | |
304 | $client = $this->getClient(); | |
305 | ||
306 | // reset the token | |
307 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
308 | $user = $em | |
1210dae1 | 309 | ->getRepository('WallabagUserBundle:User') |
371ac69a J |
310 | ->findOneByUsername('admin'); |
311 | ||
312 | if (!$user) { | |
313 | $this->markTestSkipped('No user found in db.'); | |
314 | } | |
315 | ||
316 | $config = $user->getConfig(); | |
531c8d0a | 317 | $config->setFeedToken(null); |
371ac69a J |
318 | $em->persist($config); |
319 | $em->flush(); | |
320 | ||
321 | $crawler = $client->request('GET', '/config'); | |
322 | ||
f808b016 | 323 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
371ac69a | 324 | |
4094ea47 | 325 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
531c8d0a | 326 | $this->assertContains('config.form_feed.no_token', $body[0]); |
371ac69a J |
327 | |
328 | $client->request('GET', '/generate-token'); | |
f808b016 | 329 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
371ac69a J |
330 | |
331 | $crawler = $client->followRedirect(); | |
332 | ||
4094ea47 | 333 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
c4bf12aa | 334 | $this->assertContains('config.form_feed.token_reset', $body[0]); |
371ac69a J |
335 | } |
336 | ||
337 | public function testGenerateTokenAjax() | |
338 | { | |
339 | $this->logInAs('admin'); | |
340 | $client = $this->getClient(); | |
341 | ||
342 | $client->request( | |
343 | 'GET', | |
344 | '/generate-token', | |
4094ea47 JB |
345 | [], |
346 | [], | |
347 | ['HTTP_X-Requested-With' => 'XMLHttpRequest'] | |
371ac69a J |
348 | ); |
349 | ||
f808b016 | 350 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
9744e971 | 351 | $content = json_decode($client->getResponse()->getContent(), true); |
371ac69a J |
352 | $this->assertArrayHasKey('token', $content); |
353 | } | |
354 | ||
c4bf12aa JB |
355 | public function testRevokeTokenAjax() |
356 | { | |
357 | $this->logInAs('admin'); | |
358 | $client = $this->getClient(); | |
359 | ||
360 | $client->request( | |
361 | 'GET', | |
362 | '/revoke-token', | |
363 | [], | |
364 | [], | |
365 | ['HTTP_X-Requested-With' => 'XMLHttpRequest'] | |
366 | ); | |
367 | ||
368 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
369 | } | |
370 | ||
531c8d0a | 371 | public function testFeedUpdate() |
371ac69a J |
372 | { |
373 | $this->logInAs('admin'); | |
374 | $client = $this->getClient(); | |
375 | ||
376 | $crawler = $client->request('GET', '/config'); | |
377 | ||
f808b016 | 378 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
371ac69a | 379 | |
531c8d0a | 380 | $form = $crawler->filter('button[id=feed_config_save]')->form(); |
371ac69a | 381 | |
4094ea47 | 382 | $data = [ |
531c8d0a | 383 | 'feed_config[feed_limit]' => 12, |
4094ea47 | 384 | ]; |
371ac69a J |
385 | |
386 | $client->submit($form, $data); | |
387 | ||
f808b016 | 388 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
371ac69a J |
389 | |
390 | $crawler = $client->followRedirect(); | |
391 | ||
531c8d0a | 392 | $this->assertContains('flashes.config.notice.feed_updated', $crawler->filter('body')->extract(['_text'])[0]); |
371ac69a J |
393 | } |
394 | ||
531c8d0a | 395 | public function dataForFeedFailed() |
371ac69a | 396 | { |
4094ea47 JB |
397 | return [ |
398 | [ | |
399 | [ | |
531c8d0a | 400 | 'feed_config[feed_limit]' => 0, |
4094ea47 | 401 | ], |
371ac69a | 402 | 'This value should be 1 or more.', |
4094ea47 JB |
403 | ], |
404 | [ | |
405 | [ | |
531c8d0a | 406 | 'feed_config[feed_limit]' => 1000000000000, |
4094ea47 | 407 | ], |
531c8d0a | 408 | 'validator.feed_limit_too_high', |
4094ea47 JB |
409 | ], |
410 | ]; | |
371ac69a J |
411 | } |
412 | ||
413 | /** | |
531c8d0a | 414 | * @dataProvider dataForFeedFailed |
371ac69a | 415 | */ |
531c8d0a | 416 | public function testFeedFailed($data, $expectedMessage) |
371ac69a J |
417 | { |
418 | $this->logInAs('admin'); | |
419 | $client = $this->getClient(); | |
420 | ||
421 | $crawler = $client->request('GET', '/config'); | |
422 | ||
f808b016 | 423 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
371ac69a | 424 | |
531c8d0a | 425 | $form = $crawler->filter('button[id=feed_config_save]')->form(); |
371ac69a J |
426 | |
427 | $crawler = $client->submit($form, $data); | |
428 | ||
f808b016 | 429 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
371ac69a | 430 | |
4094ea47 | 431 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); |
371ac69a J |
432 | $this->assertContains($expectedMessage, $alert[0]); |
433 | } | |
8a99c7a8 KG |
434 | |
435 | public function testTaggingRuleCreation() | |
436 | { | |
437 | $this->logInAs('admin'); | |
438 | $client = $this->getClient(); | |
439 | ||
440 | $crawler = $client->request('GET', '/config'); | |
441 | ||
f808b016 | 442 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
8a99c7a8 KG |
443 | |
444 | $form = $crawler->filter('button[id=tagging_rule_save]')->form(); | |
445 | ||
4094ea47 | 446 | $data = [ |
8a99c7a8 KG |
447 | 'tagging_rule[rule]' => 'readingTime <= 3', |
448 | 'tagging_rule[tags]' => 'short reading', | |
4094ea47 | 449 | ]; |
8a99c7a8 KG |
450 | |
451 | $client->submit($form, $data); | |
452 | ||
f808b016 | 453 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
8a99c7a8 KG |
454 | |
455 | $crawler = $client->followRedirect(); | |
456 | ||
bf3dc999 JB |
457 | $this->assertContains('flashes.config.notice.tagging_rules_updated', $crawler->filter('body')->extract(['_text'])[0]); |
458 | ||
24230a51 | 459 | $editLink = $crawler->filter('div[id=set5] a.mode_edit')->last()->link(); |
bf3dc999 JB |
460 | |
461 | $crawler = $client->click($editLink); | |
f808b016 | 462 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
bf3dc999 JB |
463 | $this->assertContains('?tagging-rule=', $client->getResponse()->headers->get('location')); |
464 | ||
465 | $crawler = $client->followRedirect(); | |
466 | ||
467 | $form = $crawler->filter('button[id=tagging_rule_save]')->form(); | |
468 | ||
469 | $data = [ | |
470 | 'tagging_rule[rule]' => 'readingTime <= 30', | |
471 | 'tagging_rule[tags]' => 'short reading', | |
472 | ]; | |
473 | ||
474 | $client->submit($form, $data); | |
475 | ||
f808b016 | 476 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
bf3dc999 JB |
477 | |
478 | $crawler = $client->followRedirect(); | |
479 | ||
480 | $this->assertContains('flashes.config.notice.tagging_rules_updated', $crawler->filter('body')->extract(['_text'])[0]); | |
481 | ||
482 | $this->assertContains('readingTime <= 30', $crawler->filter('body')->extract(['_text'])[0]); | |
8a99c7a8 | 483 | |
24230a51 | 484 | $deleteLink = $crawler->filter('div[id=set5] a.delete')->last()->link(); |
8a99c7a8 KG |
485 | |
486 | $crawler = $client->click($deleteLink); | |
f808b016 | 487 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
8a99c7a8 KG |
488 | |
489 | $crawler = $client->followRedirect(); | |
bf3dc999 | 490 | $this->assertContains('flashes.config.notice.tagging_rules_deleted', $crawler->filter('body')->extract(['_text'])[0]); |
8a99c7a8 KG |
491 | } |
492 | ||
493 | public function dataForTaggingRuleFailed() | |
494 | { | |
4094ea47 JB |
495 | return [ |
496 | [ | |
497 | [ | |
a3cac44c JB |
498 | 'tagging_rule[rule]' => 'unknownVar <= 3', |
499 | 'tagging_rule[tags]' => 'cool tag', | |
4094ea47 JB |
500 | ], |
501 | [ | |
a3cac44c JB |
502 | 'The variable', |
503 | 'does not exist.', | |
4094ea47 JB |
504 | ], |
505 | ], | |
506 | [ | |
507 | [ | |
a3cac44c JB |
508 | 'tagging_rule[rule]' => 'length(domainName) <= 42', |
509 | 'tagging_rule[tags]' => 'cool tag', | |
4094ea47 JB |
510 | ], |
511 | [ | |
a3cac44c JB |
512 | 'The operator', |
513 | 'does not exist.', | |
4094ea47 JB |
514 | ], |
515 | ], | |
516 | ]; | |
8a99c7a8 | 517 | } |
a3cac44c JB |
518 | |
519 | /** | |
520 | * @dataProvider dataForTaggingRuleFailed | |
521 | */ | |
522 | public function testTaggingRuleCreationFail($data, $messages) | |
523 | { | |
524 | $this->logInAs('admin'); | |
525 | $client = $this->getClient(); | |
526 | ||
527 | $crawler = $client->request('GET', '/config'); | |
528 | ||
f808b016 | 529 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
a3cac44c JB |
530 | |
531 | $form = $crawler->filter('button[id=tagging_rule_save]')->form(); | |
532 | ||
4f9cf232 | 533 | $crawler = $client->submit($form, $data); |
a3cac44c | 534 | |
f808b016 | 535 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
a3cac44c | 536 | |
4094ea47 | 537 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
4f9cf232 | 538 | |
a3cac44c | 539 | foreach ($messages as $message) { |
4f9cf232 | 540 | $this->assertContains($message, $body[0]); |
a3cac44c JB |
541 | } |
542 | } | |
543 | ||
5aa0294c JB |
544 | public function testTaggingRuleTooLong() |
545 | { | |
546 | $this->logInAs('admin'); | |
547 | $client = $this->getClient(); | |
548 | ||
549 | $crawler = $client->request('GET', '/config'); | |
550 | ||
f808b016 | 551 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
5aa0294c JB |
552 | |
553 | $form = $crawler->filter('button[id=tagging_rule_save]')->form(); | |
554 | ||
555 | $crawler = $client->submit($form, [ | |
556 | 'tagging_rule[rule]' => str_repeat('title', 60), | |
557 | 'tagging_rule[tags]' => 'cool tag', | |
558 | ]); | |
559 | ||
f808b016 | 560 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
5aa0294c JB |
561 | |
562 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | |
563 | ||
564 | $this->assertContains('255 characters', $body[0]); | |
565 | } | |
566 | ||
a3cac44c JB |
567 | public function testDeletingTaggingRuleFromAnOtherUser() |
568 | { | |
569 | $this->logInAs('bob'); | |
570 | $client = $this->getClient(); | |
571 | ||
572 | $rule = $client->getContainer()->get('doctrine.orm.entity_manager') | |
573 | ->getRepository('WallabagCoreBundle:TaggingRule') | |
574 | ->findAll()[0]; | |
575 | ||
24230a51 | 576 | $crawler = $client->request('GET', '/tagging-rule/delete/' . $rule->getId()); |
bf3dc999 | 577 | |
f808b016 | 578 | $this->assertSame(403, $client->getResponse()->getStatusCode()); |
bf3dc999 | 579 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
24230a51 | 580 | $this->assertContains('You can not access this rule', $body[0]); |
bf3dc999 JB |
581 | } |
582 | ||
583 | public function testEditingTaggingRuleFromAnOtherUser() | |
584 | { | |
585 | $this->logInAs('bob'); | |
586 | $client = $this->getClient(); | |
587 | ||
588 | $rule = $client->getContainer()->get('doctrine.orm.entity_manager') | |
589 | ->getRepository('WallabagCoreBundle:TaggingRule') | |
590 | ->findAll()[0]; | |
591 | ||
f808b016 | 592 | $crawler = $client->request('GET', '/tagging-rule/edit/' . $rule->getId()); |
4f9cf232 | 593 | |
f808b016 | 594 | $this->assertSame(403, $client->getResponse()->getStatusCode()); |
4094ea47 | 595 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
24230a51 KD |
596 | $this->assertContains('You can not access this rule', $body[0]); |
597 | } | |
598 | ||
599 | public function testIgnoreOriginRuleCreation() | |
600 | { | |
601 | $this->logInAs('admin'); | |
602 | $client = $this->getClient(); | |
603 | ||
604 | $crawler = $client->request('GET', '/config'); | |
605 | ||
606 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
607 | ||
608 | $form = $crawler->filter('button[id=ignore_origin_user_rule_save]')->form(); | |
609 | ||
610 | $data = [ | |
611 | 'ignore_origin_user_rule[rule]' => 'host = "example.com"', | |
612 | ]; | |
613 | ||
614 | $client->submit($form, $data); | |
615 | ||
616 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
617 | ||
618 | $crawler = $client->followRedirect(); | |
619 | ||
620 | $this->assertContains('flashes.config.notice.ignore_origin_rules_updated', $crawler->filter('body')->extract(['_text'])[0]); | |
621 | ||
622 | $editLink = $crawler->filter('div[id=set6] a.mode_edit')->last()->link(); | |
623 | ||
624 | $crawler = $client->click($editLink); | |
625 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
626 | $this->assertContains('?ignore-origin-user-rule=', $client->getResponse()->headers->get('location')); | |
627 | ||
628 | $crawler = $client->followRedirect(); | |
629 | ||
630 | $form = $crawler->filter('button[id=ignore_origin_user_rule_save]')->form(); | |
631 | ||
632 | $data = [ | |
633 | 'ignore_origin_user_rule[rule]' => 'host = "example.org"', | |
634 | ]; | |
635 | ||
636 | $client->submit($form, $data); | |
637 | ||
638 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
639 | ||
640 | $crawler = $client->followRedirect(); | |
641 | ||
642 | $this->assertContains('flashes.config.notice.ignore_origin_rules_updated', $crawler->filter('body')->extract(['_text'])[0]); | |
643 | ||
644 | $this->assertContains('host = "example.org"', $crawler->filter('body')->extract(['_text'])[0]); | |
645 | ||
646 | $deleteLink = $crawler->filter('div[id=set6] a.delete')->last()->link(); | |
647 | ||
648 | $crawler = $client->click($deleteLink); | |
649 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
650 | ||
651 | $crawler = $client->followRedirect(); | |
652 | $this->assertContains('flashes.config.notice.ignore_origin_rules_deleted', $crawler->filter('body')->extract(['_text'])[0]); | |
653 | } | |
654 | ||
655 | public function dataForIgnoreOriginRuleCreationFail() | |
656 | { | |
657 | return [ | |
658 | [ | |
659 | [ | |
660 | 'ignore_origin_user_rule[rule]' => 'foo = "bar"', | |
661 | ], | |
662 | [ | |
663 | 'The variable', | |
664 | 'does not exist.', | |
665 | ], | |
666 | ], | |
667 | [ | |
668 | [ | |
669 | 'ignore_origin_user_rule[rule]' => '_all != "none"', | |
670 | ], | |
671 | [ | |
672 | 'The operator', | |
673 | 'does not exist.', | |
674 | ], | |
675 | ], | |
676 | ]; | |
677 | } | |
678 | ||
679 | /** | |
680 | * @dataProvider dataForIgnoreOriginRuleCreationFail | |
681 | */ | |
682 | public function testIgnoreOriginRuleCreationFail($data, $messages) | |
683 | { | |
684 | $this->logInAs('admin'); | |
685 | $client = $this->getClient(); | |
686 | ||
687 | $crawler = $client->request('GET', '/config'); | |
688 | ||
689 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
690 | ||
691 | $form = $crawler->filter('button[id=ignore_origin_user_rule_save]')->form(); | |
692 | ||
693 | $crawler = $client->submit($form, $data); | |
694 | ||
695 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
696 | ||
697 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | |
698 | ||
699 | foreach ($messages as $message) { | |
700 | $this->assertContains($message, $body[0]); | |
701 | } | |
702 | } | |
703 | ||
704 | public function testDeletingIgnoreOriginRuleFromAnOtherUser() | |
705 | { | |
706 | $this->logInAs('bob'); | |
707 | $client = $this->getClient(); | |
708 | ||
709 | $rule = $client->getContainer()->get('doctrine.orm.entity_manager') | |
710 | ->getRepository('WallabagCoreBundle:IgnoreOriginUserRule') | |
711 | ->findAll()[0]; | |
712 | ||
713 | $crawler = $client->request('GET', '/ignore-origin-user-rule/edit/' . $rule->getId()); | |
714 | ||
715 | $this->assertSame(403, $client->getResponse()->getStatusCode()); | |
716 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | |
717 | $this->assertContains('You can not access this rule', $body[0]); | |
718 | } | |
719 | ||
720 | public function testEditingIgnoreOriginRuleFromAnOtherUser() | |
721 | { | |
722 | $this->logInAs('bob'); | |
723 | $client = $this->getClient(); | |
724 | ||
725 | $rule = $client->getContainer()->get('doctrine.orm.entity_manager') | |
726 | ->getRepository('WallabagCoreBundle:IgnoreOriginUserRule') | |
727 | ->findAll()[0]; | |
728 | ||
729 | $crawler = $client->request('GET', '/ignore-origin-user-rule/edit/' . $rule->getId()); | |
730 | ||
731 | $this->assertSame(403, $client->getResponse()->getStatusCode()); | |
732 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | |
733 | $this->assertContains('You can not access this rule', $body[0]); | |
a3cac44c | 734 | } |
b6c00b0b JB |
735 | |
736 | public function testDemoMode() | |
737 | { | |
738 | $this->logInAs('admin'); | |
739 | $client = $this->getClient(); | |
740 | ||
741 | $config = $client->getContainer()->get('craue_config'); | |
742 | $config->set('demo_mode_enabled', 1); | |
743 | $config->set('demo_mode_username', 'admin'); | |
744 | ||
745 | $crawler = $client->request('GET', '/config'); | |
746 | ||
f808b016 | 747 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
b6c00b0b JB |
748 | |
749 | $form = $crawler->filter('button[id=change_passwd_save]')->form(); | |
750 | ||
4094ea47 | 751 | $data = [ |
b6c00b0b JB |
752 | 'change_passwd[old_password]' => 'mypassword', |
753 | 'change_passwd[new_password][first]' => 'mypassword', | |
754 | 'change_passwd[new_password][second]' => 'mypassword', | |
4094ea47 | 755 | ]; |
b6c00b0b JB |
756 | |
757 | $client->submit($form, $data); | |
758 | ||
f808b016 | 759 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
4204a06b | 760 | $this->assertContains('flashes.config.notice.password_not_updated_demo', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); |
b6c00b0b JB |
761 | |
762 | $config->set('demo_mode_enabled', 0); | |
763 | $config->set('demo_mode_username', 'wallabag'); | |
764 | } | |
821bb876 NL |
765 | |
766 | public function testDeleteUserButtonVisibility() | |
767 | { | |
768 | $this->logInAs('admin'); | |
769 | $client = $this->getClient(); | |
770 | ||
771 | $crawler = $client->request('GET', '/config'); | |
772 | ||
773 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | |
876d77a6 | 774 | $this->assertContains('config.form_user.delete.button', $body[0]); |
821bb876 NL |
775 | |
776 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
777 | ||
821bb876 NL |
778 | $user = $em |
779 | ->getRepository('WallabagUserBundle:User') | |
780 | ->findOneByUsername('empty'); | |
5066c3e0 | 781 | $user->setEnabled(false); |
821bb876 NL |
782 | $em->persist($user); |
783 | ||
784 | $user = $em | |
785 | ->getRepository('WallabagUserBundle:User') | |
786 | ->findOneByUsername('bob'); | |
5066c3e0 | 787 | $user->setEnabled(false); |
821bb876 NL |
788 | $em->persist($user); |
789 | ||
790 | $em->flush(); | |
791 | ||
792 | $crawler = $client->request('GET', '/config'); | |
793 | ||
794 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | |
876d77a6 | 795 | $this->assertNotContains('config.form_user.delete.button', $body[0]); |
821bb876 NL |
796 | |
797 | $client->request('GET', '/account/delete'); | |
f808b016 | 798 | $this->assertSame(403, $client->getResponse()->getStatusCode()); |
821bb876 | 799 | |
821bb876 NL |
800 | $user = $em |
801 | ->getRepository('WallabagUserBundle:User') | |
802 | ->findOneByUsername('empty'); | |
5066c3e0 | 803 | $user->setEnabled(true); |
821bb876 NL |
804 | $em->persist($user); |
805 | ||
806 | $user = $em | |
807 | ->getRepository('WallabagUserBundle:User') | |
808 | ->findOneByUsername('bob'); | |
5066c3e0 | 809 | $user->setEnabled(true); |
821bb876 NL |
810 | $em->persist($user); |
811 | ||
812 | $em->flush(); | |
813 | } | |
814 | ||
71f7e58f KD |
815 | /** |
816 | * @group NetworkCalls | |
817 | */ | |
821bb876 NL |
818 | public function testDeleteAccount() |
819 | { | |
821bb876 | 820 | $client = $this->getClient(); |
c3396c65 JB |
821 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); |
822 | ||
823 | $user = new User(); | |
824 | $user->setName('Wallace'); | |
825 | $user->setEmail('wallace@wallabag.org'); | |
826 | $user->setUsername('wallace'); | |
827 | $user->setPlainPassword('wallace'); | |
828 | $user->setEnabled(true); | |
829 | $user->addRole('ROLE_SUPER_ADMIN'); | |
830 | ||
831 | $em->persist($user); | |
832 | ||
833 | $config = new Config($user); | |
834 | ||
835 | $config->setTheme('material'); | |
836 | $config->setItemsPerPage(30); | |
af7b22a3 | 837 | $config->setReadingSpeed(200); |
c3396c65 JB |
838 | $config->setLanguage('en'); |
839 | $config->setPocketConsumerKey('xxxxx'); | |
840 | ||
841 | $em->persist($config); | |
842 | $em->flush(); | |
843 | ||
844 | $this->logInAs('wallace'); | |
876d77a6 | 845 | $loggedInUserId = $this->getLoggedInUserId(); |
821bb876 | 846 | |
b8402687 NL |
847 | // create entry to check after user deletion |
848 | // that this entry is also deleted | |
849 | $crawler = $client->request('GET', '/new'); | |
850 | ||
f808b016 | 851 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
b8402687 NL |
852 | |
853 | $form = $crawler->filter('form[name=entry]')->form(); | |
854 | $data = [ | |
855 | 'entry[url]' => $url = 'https://github.com/wallabag/wallabag', | |
856 | ]; | |
857 | ||
858 | $client->submit($form, $data); | |
f808b016 | 859 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
b8402687 | 860 | |
821bb876 NL |
861 | $crawler = $client->request('GET', '/config'); |
862 | ||
71254701 | 863 | $deleteLink = $crawler->filter('.delete-account')->last()->link(); |
821bb876 NL |
864 | |
865 | $client->click($deleteLink); | |
f808b016 | 866 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
821bb876 NL |
867 | |
868 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
869 | $user = $em | |
870 | ->getRepository('WallabagUserBundle:User') | |
871 | ->createQueryBuilder('u') | |
872 | ->where('u.username = :username')->setParameter('username', 'wallace') | |
873 | ->getQuery() | |
874 | ->getOneOrNullResult() | |
875 | ; | |
876 | ||
71254701 | 877 | $this->assertNull($user); |
b8402687 NL |
878 | |
879 | $entries = $client->getContainer() | |
880 | ->get('doctrine.orm.entity_manager') | |
881 | ->getRepository('WallabagCoreBundle:Entry') | |
876d77a6 | 882 | ->findByUser($loggedInUserId); |
b8402687 NL |
883 | |
884 | $this->assertEmpty($entries); | |
821bb876 | 885 | } |
206bade5 JB |
886 | |
887 | public function testReset() | |
888 | { | |
889 | $this->logInAs('empty'); | |
890 | $client = $this->getClient(); | |
891 | ||
892 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
893 | ||
894 | $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser(); | |
895 | ||
896 | $tag = new Tag(); | |
897 | $tag->setLabel('super'); | |
898 | $em->persist($tag); | |
899 | ||
900 | $entry = new Entry($user); | |
77854331 | 901 | $entry->setUrl('https://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html'); |
206bade5 JB |
902 | $entry->setContent('Youhou'); |
903 | $entry->setTitle('Youhou'); | |
904 | $entry->addTag($tag); | |
905 | $em->persist($entry); | |
906 | ||
907 | $entry2 = new Entry($user); | |
908 | $entry2->setUrl('http://www.lemonde.de/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html'); | |
909 | $entry2->setContent('Youhou'); | |
910 | $entry2->setTitle('Youhou'); | |
911 | $entry2->addTag($tag); | |
912 | $em->persist($entry2); | |
913 | ||
914 | $annotation = new Annotation($user); | |
915 | $annotation->setText('annotated'); | |
916 | $annotation->setQuote('annotated'); | |
917 | $annotation->setRanges([]); | |
918 | $annotation->setEntry($entry); | |
919 | $em->persist($annotation); | |
920 | ||
921 | $em->flush(); | |
922 | ||
923 | // reset annotations | |
924 | $crawler = $client->request('GET', '/config#set3'); | |
925 | ||
f808b016 | 926 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
206bade5 JB |
927 | |
928 | $crawler = $client->click($crawler->selectLink('config.reset.annotations')->link()); | |
929 | ||
f808b016 | 930 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
206bade5 JB |
931 | $this->assertContains('flashes.config.notice.annotations_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); |
932 | ||
933 | $annotationsReset = $em | |
934 | ->getRepository('WallabagAnnotationBundle:Annotation') | |
935 | ->findAnnotationsByPageId($entry->getId(), $user->getId()); | |
936 | ||
937 | $this->assertEmpty($annotationsReset, 'Annotations were reset'); | |
938 | ||
939 | // reset tags | |
940 | $crawler = $client->request('GET', '/config#set3'); | |
941 | ||
f808b016 | 942 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
206bade5 JB |
943 | |
944 | $crawler = $client->click($crawler->selectLink('config.reset.tags')->link()); | |
945 | ||
f808b016 | 946 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
206bade5 JB |
947 | $this->assertContains('flashes.config.notice.tags_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); |
948 | ||
949 | $tagReset = $em | |
950 | ->getRepository('WallabagCoreBundle:Tag') | |
951 | ->countAllTags($user->getId()); | |
952 | ||
f808b016 | 953 | $this->assertSame(0, $tagReset, 'Tags were reset'); |
206bade5 JB |
954 | |
955 | // reset entries | |
956 | $crawler = $client->request('GET', '/config#set3'); | |
957 | ||
f808b016 | 958 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
206bade5 JB |
959 | |
960 | $crawler = $client->click($crawler->selectLink('config.reset.entries')->link()); | |
961 | ||
f808b016 | 962 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
206bade5 JB |
963 | $this->assertContains('flashes.config.notice.entries_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); |
964 | ||
965 | $entryReset = $em | |
966 | ->getRepository('WallabagCoreBundle:Entry') | |
273b6f06 | 967 | ->countAllEntriesByUser($user->getId()); |
206bade5 | 968 | |
f808b016 | 969 | $this->assertSame(0, $entryReset, 'Entries were reset'); |
206bade5 JB |
970 | } |
971 | ||
6da1aebc TC |
972 | public function testResetArchivedEntries() |
973 | { | |
974 | $this->logInAs('empty'); | |
975 | $client = $this->getClient(); | |
976 | ||
977 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
978 | ||
979 | $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser(); | |
980 | ||
981 | $tag = new Tag(); | |
982 | $tag->setLabel('super'); | |
983 | $em->persist($tag); | |
984 | ||
985 | $entry = new Entry($user); | |
77854331 | 986 | $entry->setUrl('https://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html'); |
6da1aebc TC |
987 | $entry->setContent('Youhou'); |
988 | $entry->setTitle('Youhou'); | |
989 | $entry->addTag($tag); | |
990 | $em->persist($entry); | |
991 | ||
992 | $annotation = new Annotation($user); | |
993 | $annotation->setText('annotated'); | |
994 | $annotation->setQuote('annotated'); | |
995 | $annotation->setRanges([]); | |
996 | $annotation->setEntry($entry); | |
997 | $em->persist($annotation); | |
998 | ||
999 | $tagArchived = new Tag(); | |
1000 | $tagArchived->setLabel('super'); | |
1001 | $em->persist($tagArchived); | |
1002 | ||
1003 | $entryArchived = new Entry($user); | |
77854331 | 1004 | $entryArchived->setUrl('https://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html'); |
6da1aebc TC |
1005 | $entryArchived->setContent('Youhou'); |
1006 | $entryArchived->setTitle('Youhou'); | |
1007 | $entryArchived->addTag($tagArchived); | |
7975395d | 1008 | $entryArchived->updateArchived(true); |
6da1aebc TC |
1009 | $em->persist($entryArchived); |
1010 | ||
1011 | $annotationArchived = new Annotation($user); | |
1012 | $annotationArchived->setText('annotated'); | |
1013 | $annotationArchived->setQuote('annotated'); | |
1014 | $annotationArchived->setRanges([]); | |
1015 | $annotationArchived->setEntry($entryArchived); | |
1016 | $em->persist($annotationArchived); | |
1017 | ||
1018 | $em->flush(); | |
1019 | ||
1020 | $crawler = $client->request('GET', '/config#set3'); | |
1021 | ||
f808b016 | 1022 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
6da1aebc TC |
1023 | |
1024 | $crawler = $client->click($crawler->selectLink('config.reset.archived')->link()); | |
1025 | ||
f808b016 | 1026 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
6da1aebc TC |
1027 | $this->assertContains('flashes.config.notice.archived_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); |
1028 | ||
1029 | $entryReset = $em | |
1030 | ->getRepository('WallabagCoreBundle:Entry') | |
73f28afb | 1031 | ->countAllEntriesByUser($user->getId()); |
6da1aebc | 1032 | |
f808b016 | 1033 | $this->assertSame(1, $entryReset, 'Entries were reset'); |
6da1aebc TC |
1034 | |
1035 | $tagReset = $em | |
1036 | ->getRepository('WallabagCoreBundle:Tag') | |
1037 | ->countAllTags($user->getId()); | |
1038 | ||
f808b016 | 1039 | $this->assertSame(1, $tagReset, 'Tags were reset'); |
6da1aebc TC |
1040 | |
1041 | $annotationsReset = $em | |
1042 | ->getRepository('WallabagAnnotationBundle:Annotation') | |
1043 | ->findAnnotationsByPageId($annotationArchived->getId(), $user->getId()); | |
1044 | ||
1045 | $this->assertEmpty($annotationsReset, 'Annotations were reset'); | |
1046 | } | |
1047 | ||
206bade5 JB |
1048 | public function testResetEntriesCascade() |
1049 | { | |
1050 | $this->logInAs('empty'); | |
1051 | $client = $this->getClient(); | |
1052 | ||
1053 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
1054 | ||
1055 | $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser(); | |
1056 | ||
1057 | $tag = new Tag(); | |
1058 | $tag->setLabel('super'); | |
1059 | $em->persist($tag); | |
1060 | ||
1061 | $entry = new Entry($user); | |
77854331 | 1062 | $entry->setUrl('https://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html'); |
206bade5 JB |
1063 | $entry->setContent('Youhou'); |
1064 | $entry->setTitle('Youhou'); | |
1065 | $entry->addTag($tag); | |
1066 | $em->persist($entry); | |
1067 | ||
1068 | $annotation = new Annotation($user); | |
1069 | $annotation->setText('annotated'); | |
1070 | $annotation->setQuote('annotated'); | |
1071 | $annotation->setRanges([]); | |
1072 | $annotation->setEntry($entry); | |
1073 | $em->persist($annotation); | |
1074 | ||
1075 | $em->flush(); | |
1076 | ||
1077 | $crawler = $client->request('GET', '/config#set3'); | |
1078 | ||
f808b016 | 1079 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
206bade5 JB |
1080 | |
1081 | $crawler = $client->click($crawler->selectLink('config.reset.entries')->link()); | |
1082 | ||
f808b016 | 1083 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
206bade5 JB |
1084 | $this->assertContains('flashes.config.notice.entries_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); |
1085 | ||
1086 | $entryReset = $em | |
1087 | ->getRepository('WallabagCoreBundle:Entry') | |
273b6f06 | 1088 | ->countAllEntriesByUser($user->getId()); |
206bade5 | 1089 | |
f808b016 | 1090 | $this->assertSame(0, $entryReset, 'Entries were reset'); |
206bade5 JB |
1091 | |
1092 | $tagReset = $em | |
1093 | ->getRepository('WallabagCoreBundle:Tag') | |
1094 | ->countAllTags($user->getId()); | |
1095 | ||
f808b016 | 1096 | $this->assertSame(0, $tagReset, 'Tags were reset'); |
206bade5 JB |
1097 | |
1098 | $annotationsReset = $em | |
1099 | ->getRepository('WallabagAnnotationBundle:Annotation') | |
1100 | ->findAnnotationsByPageId($entry->getId(), $user->getId()); | |
1101 | ||
1102 | $this->assertEmpty($annotationsReset, 'Annotations were reset'); | |
1103 | } | |
8f3ff39c NL |
1104 | |
1105 | public function testSwitchViewMode() | |
1106 | { | |
1107 | $this->logInAs('admin'); | |
7ab5eb95 | 1108 | $this->useTheme('baggy'); |
8f3ff39c NL |
1109 | $client = $this->getClient(); |
1110 | ||
1111 | $client->request('GET', '/unread/list'); | |
1112 | ||
1113 | $this->assertNotContains('listmode', $client->getResponse()->getContent()); | |
1114 | ||
1115 | $client->request('GET', '/config/view-mode'); | |
1116 | $crawler = $client->followRedirect(); | |
1117 | ||
1118 | $client->request('GET', '/unread/list'); | |
1119 | ||
1120 | $this->assertContains('listmode', $client->getResponse()->getContent()); | |
56a7ce17 NL |
1121 | |
1122 | $client->request('GET', '/config/view-mode'); | |
8f3ff39c | 1123 | } |
4d4147b2 JB |
1124 | |
1125 | public function testChangeLocaleWithoutReferer() | |
1126 | { | |
1127 | $client = $this->getClient(); | |
1128 | ||
1129 | $client->request('GET', '/locale/de'); | |
1130 | $client->followRedirect(); | |
1131 | ||
1132 | $this->assertSame('de', $client->getRequest()->getLocale()); | |
1133 | $this->assertSame('de', $client->getContainer()->get('session')->get('_locale')); | |
1134 | } | |
1135 | ||
1136 | public function testChangeLocaleWithReferer() | |
1137 | { | |
1138 | $client = $this->getClient(); | |
1139 | ||
1140 | $client->request('GET', '/login'); | |
1141 | $client->request('GET', '/locale/de'); | |
1142 | $client->followRedirect(); | |
1143 | ||
1144 | $this->assertSame('de', $client->getRequest()->getLocale()); | |
1145 | $this->assertSame('de', $client->getContainer()->get('session')->get('_locale')); | |
1146 | } | |
1147 | ||
1148 | public function testChangeLocaleToBadLocale() | |
1149 | { | |
1150 | $client = $this->getClient(); | |
1151 | ||
1152 | $client->request('GET', '/login'); | |
1153 | $client->request('GET', '/locale/yuyuyuyu'); | |
1154 | $client->followRedirect(); | |
1155 | ||
1156 | $this->assertNotSame('yuyuyuyu', $client->getRequest()->getLocale()); | |
1157 | $this->assertNotSame('yuyuyuyu', $client->getContainer()->get('session')->get('_locale')); | |
1158 | } | |
a0c5eb00 JB |
1159 | |
1160 | public function testUserEnable2faEmail() | |
1161 | { | |
1162 | $this->logInAs('admin'); | |
1163 | $client = $this->getClient(); | |
1164 | ||
1165 | $crawler = $client->request('GET', '/config/otp/email'); | |
1166 | ||
1167 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
1168 | ||
1169 | $crawler = $client->followRedirect(); | |
1170 | ||
1171 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); | |
1172 | $this->assertContains('flashes.config.notice.otp_enabled', $alert[0]); | |
1173 | ||
1174 | // restore user | |
1175 | $em = $this->getEntityManager(); | |
1176 | $user = $em | |
1177 | ->getRepository('WallabagUserBundle:User') | |
1178 | ->findOneByUsername('admin'); | |
1179 | ||
1180 | $this->assertTrue($user->isEmailTwoFactor()); | |
1181 | ||
1182 | $user->setEmailTwoFactor(false); | |
1183 | $em->persist($user); | |
1184 | $em->flush(); | |
1185 | } | |
1186 | ||
4ff1efa4 NL |
1187 | public function testUserDisable2faEmail() |
1188 | { | |
1189 | $this->logInAs('admin'); | |
1190 | $client = $this->getClient(); | |
1191 | ||
1192 | $crawler = $client->request('GET', '/config/otp/email/disable'); | |
1193 | ||
1194 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
1195 | ||
1196 | $crawler = $client->followRedirect(); | |
1197 | ||
1198 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); | |
1199 | $this->assertContains('flashes.config.notice.otp_disabled', $alert[0]); | |
1200 | ||
1201 | // restore user | |
1202 | $em = $this->getEntityManager(); | |
1203 | $user = $em | |
1204 | ->getRepository('WallabagUserBundle:User') | |
1205 | ->findOneByUsername('admin'); | |
1206 | ||
1207 | $this->assertFalse($user->isEmailTwoFactor()); | |
1208 | } | |
1209 | ||
a0c5eb00 JB |
1210 | public function testUserEnable2faGoogle() |
1211 | { | |
1212 | $this->logInAs('admin'); | |
1213 | $client = $this->getClient(); | |
1214 | ||
1215 | $crawler = $client->request('GET', '/config/otp/app'); | |
1216 | ||
1217 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
1218 | ||
1219 | // restore user | |
1220 | $em = $this->getEntityManager(); | |
1221 | $user = $em | |
1222 | ->getRepository('WallabagUserBundle:User') | |
1223 | ->findOneByUsername('admin'); | |
1224 | ||
1225 | $this->assertTrue($user->isGoogleTwoFactor()); | |
1226 | $this->assertGreaterThan(0, $user->getBackupCodes()); | |
1227 | ||
1228 | $user->setGoogleAuthenticatorSecret(false); | |
1229 | $user->setBackupCodes(null); | |
1230 | $em->persist($user); | |
1231 | $em->flush(); | |
1232 | } | |
1233 | ||
1234 | public function testUserEnable2faGoogleCancel() | |
1235 | { | |
1236 | $this->logInAs('admin'); | |
1237 | $client = $this->getClient(); | |
1238 | ||
1239 | $crawler = $client->request('GET', '/config/otp/app'); | |
1240 | ||
1241 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
1242 | ||
1243 | // restore user | |
1244 | $em = $this->getEntityManager(); | |
1245 | $user = $em | |
1246 | ->getRepository('WallabagUserBundle:User') | |
1247 | ->findOneByUsername('admin'); | |
1248 | ||
1249 | $this->assertTrue($user->isGoogleTwoFactor()); | |
1250 | $this->assertGreaterThan(0, $user->getBackupCodes()); | |
1251 | ||
1252 | $crawler = $client->request('GET', '/config/otp/app/cancel'); | |
1253 | ||
1254 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
1255 | ||
1256 | $user = $em | |
1257 | ->getRepository('WallabagUserBundle:User') | |
1258 | ->findOneByUsername('admin'); | |
1259 | ||
1260 | $this->assertFalse($user->isGoogleTwoFactor()); | |
1261 | $this->assertEmpty($user->getBackupCodes()); | |
1262 | } | |
34be2d5d | 1263 | |
4ff1efa4 NL |
1264 | public function testUserDisable2faGoogle() |
1265 | { | |
1266 | $this->logInAs('admin'); | |
1267 | $client = $this->getClient(); | |
1268 | ||
1269 | $crawler = $client->request('GET', '/config/otp/app/disable'); | |
1270 | ||
1271 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
1272 | ||
1273 | $crawler = $client->followRedirect(); | |
1274 | ||
1275 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); | |
1276 | $this->assertContains('flashes.config.notice.otp_disabled', $alert[0]); | |
1277 | ||
1278 | // restore user | |
1279 | $em = $this->getEntityManager(); | |
1280 | $user = $em | |
1281 | ->getRepository('WallabagUserBundle:User') | |
1282 | ->findOneByUsername('admin'); | |
1283 | ||
1284 | $this->assertEmpty($user->getGoogleAuthenticatorSecret()); | |
1285 | $this->assertEmpty($user->getBackupCodes()); | |
1286 | } | |
1287 | ||
34be2d5d JB |
1288 | public function testExportTaggingRule() |
1289 | { | |
1290 | $this->logInAs('admin'); | |
1291 | $client = $this->getClient(); | |
1292 | ||
1293 | ob_start(); | |
1294 | $crawler = $client->request('GET', '/tagging-rule/export'); | |
1295 | ob_end_clean(); | |
1296 | ||
1297 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
1298 | ||
1299 | $headers = $client->getResponse()->headers; | |
1300 | $this->assertSame('application/json', $headers->get('content-type')); | |
1301 | $this->assertSame('attachment; filename="tagging_rules_admin.json"', $headers->get('content-disposition')); | |
1302 | $this->assertSame('UTF-8', $headers->get('content-transfer-encoding')); | |
1303 | ||
1304 | $content = json_decode($client->getResponse()->getContent(), true); | |
1305 | ||
1306 | $this->assertCount(4, $content); | |
1307 | $this->assertSame('content matches "spurs"', $content[0]['rule']); | |
1308 | $this->assertSame('sport', $content[0]['tags'][0]); | |
1309 | } | |
1310 | ||
1311 | public function testImportTagginfRuleBadFile() | |
1312 | { | |
1313 | $this->logInAs('admin'); | |
1314 | $client = $this->getClient(); | |
1315 | ||
1316 | $crawler = $client->request('GET', '/config'); | |
1317 | $form = $crawler->filter('form[name=upload_tagging_rule_file] > button[type=submit]')->form(); | |
1318 | ||
1319 | $data = [ | |
1320 | 'upload_tagging_rule_file[file]' => '', | |
1321 | ]; | |
1322 | ||
1323 | $client->submit($form, $data); | |
1324 | ||
1325 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
1326 | } | |
1327 | ||
1328 | public function testImportTagginfRuleFile() | |
1329 | { | |
1330 | $this->logInAs('admin'); | |
1331 | $client = $this->getClient(); | |
1332 | ||
1333 | $crawler = $client->request('GET', '/config'); | |
1334 | $form = $crawler->filter('form[name=upload_tagging_rule_file] > button[type=submit]')->form(); | |
1335 | ||
1336 | $file = new UploadedFile(__DIR__ . '/../fixtures/tagging_rules_admin.json', 'tagging_rules_admin.json'); | |
1337 | ||
1338 | $data = [ | |
1339 | 'upload_tagging_rule_file[file]' => $file, | |
1340 | ]; | |
1341 | ||
1342 | $client->submit($form, $data); | |
1343 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
1344 | ||
1345 | $user = $client->getContainer()->get('fos_user.user_manager.test')->findUserBy(['username' => 'admin']); | |
1346 | $taggingRules = $user->getConfig()->getTaggingRules()->toArray(); | |
1347 | $this->assertCount(5, $taggingRules); | |
1348 | $this->assertSame('title matches "football"', $taggingRules[4]->getRule()); | |
1349 | } | |
4d85d7e9 | 1350 | } |