aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php')
-rw-r--r--tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php173
1 files changed, 47 insertions, 126 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
index 7193f9b0..1954c654 100644
--- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
@@ -28,7 +28,6 @@ class ConfigControllerTest extends WallabagCoreTestCase
28 $this->assertCount(1, $crawler->filter('button[id=config_save]')); 28 $this->assertCount(1, $crawler->filter('button[id=config_save]'));
29 $this->assertCount(1, $crawler->filter('button[id=change_passwd_save]')); 29 $this->assertCount(1, $crawler->filter('button[id=change_passwd_save]'));
30 $this->assertCount(1, $crawler->filter('button[id=update_user_save]')); 30 $this->assertCount(1, $crawler->filter('button[id=update_user_save]'));
31 $this->assertCount(1, $crawler->filter('button[id=new_user_save]'));
32 $this->assertCount(1, $crawler->filter('button[id=rss_config_save]')); 31 $this->assertCount(1, $crawler->filter('button[id=rss_config_save]'));
33 } 32 }
34 33
@@ -56,8 +55,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
56 55
57 $crawler = $client->followRedirect(); 56 $crawler = $client->followRedirect();
58 57
59 $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(['_text'])); 58 $this->assertContains('flashes.config.notice.config_saved', $crawler->filter('body')->extract(['_text'])[0]);
60 $this->assertContains('flashes.config.notice.config_saved', $alert[0]);
61 } 59 }
62 60
63 public function testChangeReadingSpeed() 61 public function testChangeReadingSpeed()
@@ -213,8 +211,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
213 211
214 $crawler = $client->followRedirect(); 212 $crawler = $client->followRedirect();
215 213
216 $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(['_text'])); 214 $this->assertContains('flashes.config.notice.password_updated', $crawler->filter('body')->extract(['_text'])[0]);
217 $this->assertContains('flashes.config.notice.password_updated', $alert[0]);
218 } 215 }
219 216
220 public function dataForUserFailed() 217 public function dataForUserFailed()
@@ -285,120 +282,6 @@ class ConfigControllerTest extends WallabagCoreTestCase
285 $this->assertContains('flashes.config.notice.user_updated', $alert[0]); 282 $this->assertContains('flashes.config.notice.user_updated', $alert[0]);
286 } 283 }
287 284
288 public function dataForNewUserFailed()
289 {
290 return [
291 [
292 [
293 'new_user[username]' => '',
294 'new_user[plainPassword][first]' => '',
295 'new_user[plainPassword][second]' => '',
296 'new_user[email]' => '',
297 ],
298 'fos_user.username.blank',
299 ],
300 [
301 [
302 'new_user[username]' => 'a',
303 'new_user[plainPassword][first]' => 'mypassword',
304 'new_user[plainPassword][second]' => 'mypassword',
305 'new_user[email]' => '',
306 ],
307 'fos_user.username.short',
308 ],
309 [
310 [
311 'new_user[username]' => 'wallace',
312 'new_user[plainPassword][first]' => 'mypassword',
313 'new_user[plainPassword][second]' => 'mypassword',
314 'new_user[email]' => 'test',
315 ],
316 'fos_user.email.invalid',
317 ],
318 [
319 [
320 'new_user[username]' => 'admin',
321 'new_user[plainPassword][first]' => 'wallacewallace',
322 'new_user[plainPassword][second]' => 'wallacewallace',
323 'new_user[email]' => 'wallace@wallace.me',
324 ],
325 'fos_user.username.already_used',
326 ],
327 [
328 [
329 'new_user[username]' => 'wallace',
330 'new_user[plainPassword][first]' => 'mypassword1',
331 'new_user[plainPassword][second]' => 'mypassword2',
332 'new_user[email]' => 'wallace@wallace.me',
333 ],
334 'validator.password_must_match',
335 ],
336 ];
337 }
338
339 /**
340 * @dataProvider dataForNewUserFailed
341 */
342 public function testNewUserFailed($data, $expectedMessage)
343 {
344 $this->logInAs('admin');
345 $client = $this->getClient();
346
347 $crawler = $client->request('GET', '/config');
348
349 $this->assertEquals(200, $client->getResponse()->getStatusCode());
350
351 $form = $crawler->filter('button[id=new_user_save]')->form();
352
353 $crawler = $client->submit($form, $data);
354
355 $this->assertEquals(200, $client->getResponse()->getStatusCode());
356
357 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text']));
358 $this->assertContains($expectedMessage, $alert[0]);
359 }
360
361 public function testNewUserCreated()
362 {
363 $this->logInAs('admin');
364 $client = $this->getClient();
365
366 $crawler = $client->request('GET', '/config');
367
368 $this->assertEquals(200, $client->getResponse()->getStatusCode());
369
370 $form = $crawler->filter('button[id=new_user_save]')->form();
371
372 $data = [
373 'new_user[username]' => 'wallace',
374 'new_user[plainPassword][first]' => 'wallace1',
375 'new_user[plainPassword][second]' => 'wallace1',
376 'new_user[email]' => 'wallace@wallace.me',
377 ];
378
379 $client->submit($form, $data);
380
381 $this->assertEquals(302, $client->getResponse()->getStatusCode());
382
383 $crawler = $client->followRedirect();
384
385 $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(['_text']));
386 $this->assertContains('flashes.config.notice.user_added', $alert[0]);
387
388 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
389 $user = $em
390 ->getRepository('WallabagUserBundle:User')
391 ->findOneByUsername('wallace');
392
393 $this->assertTrue(false !== $user);
394 $this->assertTrue($user->isEnabled());
395 $this->assertEquals('material', $user->getConfig()->getTheme());
396 $this->assertEquals(12, $user->getConfig()->getItemsPerPage());
397 $this->assertEquals(50, $user->getConfig()->getRssLimit());
398 $this->assertEquals('en', $user->getConfig()->getLanguage());
399 $this->assertEquals(1, $user->getConfig()->getReadingSpeed());
400 }
401
402 public function testRssUpdateResetToken() 285 public function testRssUpdateResetToken()
403 { 286 {
404 $this->logInAs('admin'); 287 $this->logInAs('admin');
@@ -474,8 +357,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
474 357
475 $crawler = $client->followRedirect(); 358 $crawler = $client->followRedirect();
476 359
477 $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(['_text'])); 360 $this->assertContains('flashes.config.notice.rss_updated', $crawler->filter('body')->extract(['_text'])[0]);
478 $this->assertContains('flashes.config.notice.rss_updated', $alert[0]);
479 } 361 }
480 362
481 public function dataForRssFailed() 363 public function dataForRssFailed()
@@ -540,8 +422,32 @@ class ConfigControllerTest extends WallabagCoreTestCase
540 422
541 $crawler = $client->followRedirect(); 423 $crawler = $client->followRedirect();
542 424
543 $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(['_text'])); 425 $this->assertContains('flashes.config.notice.tagging_rules_updated', $crawler->filter('body')->extract(['_text'])[0]);
544 $this->assertContains('flashes.config.notice.tagging_rules_updated', $alert[0]); 426
427 $editLink = $crawler->filter('.mode_edit')->last()->link();
428
429 $crawler = $client->click($editLink);
430 $this->assertEquals(302, $client->getResponse()->getStatusCode());
431 $this->assertContains('?tagging-rule=', $client->getResponse()->headers->get('location'));
432
433 $crawler = $client->followRedirect();
434
435 $form = $crawler->filter('button[id=tagging_rule_save]')->form();
436
437 $data = [
438 'tagging_rule[rule]' => 'readingTime <= 30',
439 'tagging_rule[tags]' => 'short reading',
440 ];
441
442 $client->submit($form, $data);
443
444 $this->assertEquals(302, $client->getResponse()->getStatusCode());
445
446 $crawler = $client->followRedirect();
447
448 $this->assertContains('flashes.config.notice.tagging_rules_updated', $crawler->filter('body')->extract(['_text'])[0]);
449
450 $this->assertContains('readingTime <= 30', $crawler->filter('body')->extract(['_text'])[0]);
545 451
546 $deleteLink = $crawler->filter('.delete')->last()->link(); 452 $deleteLink = $crawler->filter('.delete')->last()->link();
547 453
@@ -549,8 +455,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
549 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 455 $this->assertEquals(302, $client->getResponse()->getStatusCode());
550 456
551 $crawler = $client->followRedirect(); 457 $crawler = $client->followRedirect();
552 $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(['_text'])); 458 $this->assertContains('flashes.config.notice.tagging_rules_deleted', $crawler->filter('body')->extract(['_text'])[0]);
553 $this->assertContains('flashes.config.notice.tagging_rules_deleted', $alert[0]);
554 } 459 }
555 460
556 public function dataForTaggingRuleFailed() 461 public function dataForTaggingRuleFailed()
@@ -613,7 +518,23 @@ class ConfigControllerTest extends WallabagCoreTestCase
613 ->getRepository('WallabagCoreBundle:TaggingRule') 518 ->getRepository('WallabagCoreBundle:TaggingRule')
614 ->findAll()[0]; 519 ->findAll()[0];
615 520
616 $crawler = $client->request('GET', '/tagging-rule/delete/'.$rule->getId()); 521 $crawler = $client->request('GET', '/tagging-rule/edit/'.$rule->getId());
522
523 $this->assertEquals(403, $client->getResponse()->getStatusCode());
524 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
525 $this->assertContains('You can not access this tagging rule', $body[0]);
526 }
527
528 public function testEditingTaggingRuleFromAnOtherUser()
529 {
530 $this->logInAs('bob');
531 $client = $this->getClient();
532
533 $rule = $client->getContainer()->get('doctrine.orm.entity_manager')
534 ->getRepository('WallabagCoreBundle:TaggingRule')
535 ->findAll()[0];
536
537 $crawler = $client->request('GET', '/tagging-rule/edit/'.$rule->getId());
617 538
618 $this->assertEquals(403, $client->getResponse()->getStatusCode()); 539 $this->assertEquals(403, $client->getResponse()->getStatusCode());
619 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); 540 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));