diff options
author | Kevin Decherf <kevin@kdecherf.com> | 2019-06-23 22:13:44 +0200 |
---|---|---|
committer | Kevin Decherf <kevin@kdecherf.com> | 2020-04-25 15:59:23 +0200 |
commit | 24230a5130005e274e1d8d3fe8eaca13cb978b9c (patch) | |
tree | dd91e56d1f8ea2ad0302440206688d13f66d1bfc /tests/Wallabag | |
parent | c675bd11c66e60a1976dfd66484448dcc9d80f0f (diff) | |
download | wallabag-24230a5130005e274e1d8d3fe8eaca13cb978b9c.tar.gz wallabag-24230a5130005e274e1d8d3fe8eaca13cb978b9c.tar.zst wallabag-24230a5130005e274e1d8d3fe8eaca13cb978b9c.zip |
Add new Ignore Origin rules tab, update ConfigController
Signed-off-by: Kevin Decherf <kevin@kdecherf.com>
Diffstat (limited to 'tests/Wallabag')
-rw-r--r-- | tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php | 148 |
1 files changed, 142 insertions, 6 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php index b3b3a19a..40a1aa97 100644 --- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php | |||
@@ -435,7 +435,6 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
435 | public function testTaggingRuleCreation() | 435 | public function testTaggingRuleCreation() |
436 | { | 436 | { |
437 | $this->logInAs('admin'); | 437 | $this->logInAs('admin'); |
438 | $this->useTheme('baggy'); | ||
439 | $client = $this->getClient(); | 438 | $client = $this->getClient(); |
440 | 439 | ||
441 | $crawler = $client->request('GET', '/config'); | 440 | $crawler = $client->request('GET', '/config'); |
@@ -457,7 +456,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
457 | 456 | ||
458 | $this->assertContains('flashes.config.notice.tagging_rules_updated', $crawler->filter('body')->extract(['_text'])[0]); | 457 | $this->assertContains('flashes.config.notice.tagging_rules_updated', $crawler->filter('body')->extract(['_text'])[0]); |
459 | 458 | ||
460 | $editLink = $crawler->filter('.mode_edit')->last()->link(); | 459 | $editLink = $crawler->filter('div[id=set5] a.mode_edit')->last()->link(); |
461 | 460 | ||
462 | $crawler = $client->click($editLink); | 461 | $crawler = $client->click($editLink); |
463 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | 462 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
@@ -482,7 +481,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
482 | 481 | ||
483 | $this->assertContains('readingTime <= 30', $crawler->filter('body')->extract(['_text'])[0]); | 482 | $this->assertContains('readingTime <= 30', $crawler->filter('body')->extract(['_text'])[0]); |
484 | 483 | ||
485 | $deleteLink = $crawler->filter('.delete')->last()->link(); | 484 | $deleteLink = $crawler->filter('div[id=set5] a.delete')->last()->link(); |
486 | 485 | ||
487 | $crawler = $client->click($deleteLink); | 486 | $crawler = $client->click($deleteLink); |
488 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | 487 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
@@ -574,11 +573,11 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
574 | ->getRepository('WallabagCoreBundle:TaggingRule') | 573 | ->getRepository('WallabagCoreBundle:TaggingRule') |
575 | ->findAll()[0]; | 574 | ->findAll()[0]; |
576 | 575 | ||
577 | $crawler = $client->request('GET', '/tagging-rule/edit/' . $rule->getId()); | 576 | $crawler = $client->request('GET', '/tagging-rule/delete/' . $rule->getId()); |
578 | 577 | ||
579 | $this->assertSame(403, $client->getResponse()->getStatusCode()); | 578 | $this->assertSame(403, $client->getResponse()->getStatusCode()); |
580 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | 579 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
581 | $this->assertContains('You can not access this tagging rule', $body[0]); | 580 | $this->assertContains('You can not access this rule', $body[0]); |
582 | } | 581 | } |
583 | 582 | ||
584 | public function testEditingTaggingRuleFromAnOtherUser() | 583 | public function testEditingTaggingRuleFromAnOtherUser() |
@@ -594,7 +593,144 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
594 | 593 | ||
595 | $this->assertSame(403, $client->getResponse()->getStatusCode()); | 594 | $this->assertSame(403, $client->getResponse()->getStatusCode()); |
596 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | 595 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
597 | $this->assertContains('You can not access this tagging rule', $body[0]); | 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]); | ||
598 | } | 734 | } |
599 | 735 | ||
600 | public function testDemoMode() | 736 | public function testDemoMode() |