diff options
Diffstat (limited to 'tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php')
-rw-r--r-- | tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php | 270 |
1 files changed, 268 insertions, 2 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php index d4fbe2d4..9bbc5960 100644 --- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php | |||
@@ -3,6 +3,11 @@ | |||
3 | namespace Tests\Wallabag\CoreBundle\Controller; | 3 | namespace Tests\Wallabag\CoreBundle\Controller; |
4 | 4 | ||
5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | 5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; |
6 | use Wallabag\CoreBundle\Entity\Config; | ||
7 | use Wallabag\UserBundle\Entity\User; | ||
8 | use Wallabag\CoreBundle\Entity\Entry; | ||
9 | use Wallabag\CoreBundle\Entity\Tag; | ||
10 | use Wallabag\AnnotationBundle\Entity\Annotation; | ||
6 | 11 | ||
7 | class ConfigControllerTest extends WallabagCoreTestCase | 12 | class ConfigControllerTest extends WallabagCoreTestCase |
8 | { | 13 | { |
@@ -46,6 +51,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
46 | 'config[theme]' => 'baggy', | 51 | 'config[theme]' => 'baggy', |
47 | 'config[items_per_page]' => '30', | 52 | 'config[items_per_page]' => '30', |
48 | 'config[reading_speed]' => '0.5', | 53 | 'config[reading_speed]' => '0.5', |
54 | 'config[action_mark_as_read]' => '0', | ||
49 | 'config[language]' => 'en', | 55 | 'config[language]' => 'en', |
50 | ]; | 56 | ]; |
51 | 57 | ||
@@ -407,7 +413,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
407 | 413 | ||
408 | $crawler = $client->request('GET', '/config'); | 414 | $crawler = $client->request('GET', '/config'); |
409 | 415 | ||
410 | $this->assertTrue($client->getResponse()->isSuccessful()); | 416 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); |
411 | 417 | ||
412 | $form = $crawler->filter('button[id=tagging_rule_save]')->form(); | 418 | $form = $crawler->filter('button[id=tagging_rule_save]')->form(); |
413 | 419 | ||
@@ -494,7 +500,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
494 | 500 | ||
495 | $crawler = $client->request('GET', '/config'); | 501 | $crawler = $client->request('GET', '/config'); |
496 | 502 | ||
497 | $this->assertTrue($client->getResponse()->isSuccessful()); | 503 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); |
498 | 504 | ||
499 | $form = $crawler->filter('button[id=tagging_rule_save]')->form(); | 505 | $form = $crawler->filter('button[id=tagging_rule_save]')->form(); |
500 | 506 | ||
@@ -570,4 +576,264 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
570 | $config->set('demo_mode_enabled', 0); | 576 | $config->set('demo_mode_enabled', 0); |
571 | $config->set('demo_mode_username', 'wallabag'); | 577 | $config->set('demo_mode_username', 'wallabag'); |
572 | } | 578 | } |
579 | |||
580 | public function testDeleteUserButtonVisibility() | ||
581 | { | ||
582 | $this->logInAs('admin'); | ||
583 | $client = $this->getClient(); | ||
584 | |||
585 | $crawler = $client->request('GET', '/config'); | ||
586 | |||
587 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | ||
588 | $this->assertContains('config.form_user.delete.button', $body[0]); | ||
589 | |||
590 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
591 | |||
592 | $user = $em | ||
593 | ->getRepository('WallabagUserBundle:User') | ||
594 | ->findOneByUsername('empty'); | ||
595 | $user->setExpired(1); | ||
596 | $em->persist($user); | ||
597 | |||
598 | $user = $em | ||
599 | ->getRepository('WallabagUserBundle:User') | ||
600 | ->findOneByUsername('bob'); | ||
601 | $user->setExpired(1); | ||
602 | $em->persist($user); | ||
603 | |||
604 | $em->flush(); | ||
605 | |||
606 | $crawler = $client->request('GET', '/config'); | ||
607 | |||
608 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | ||
609 | $this->assertNotContains('config.form_user.delete.button', $body[0]); | ||
610 | |||
611 | $client->request('GET', '/account/delete'); | ||
612 | $this->assertEquals(403, $client->getResponse()->getStatusCode()); | ||
613 | |||
614 | $user = $em | ||
615 | ->getRepository('WallabagUserBundle:User') | ||
616 | ->findOneByUsername('empty'); | ||
617 | $user->setExpired(0); | ||
618 | $em->persist($user); | ||
619 | |||
620 | $user = $em | ||
621 | ->getRepository('WallabagUserBundle:User') | ||
622 | ->findOneByUsername('bob'); | ||
623 | $user->setExpired(0); | ||
624 | $em->persist($user); | ||
625 | |||
626 | $em->flush(); | ||
627 | } | ||
628 | |||
629 | public function testDeleteAccount() | ||
630 | { | ||
631 | $client = $this->getClient(); | ||
632 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
633 | |||
634 | $user = new User(); | ||
635 | $user->setName('Wallace'); | ||
636 | $user->setEmail('wallace@wallabag.org'); | ||
637 | $user->setUsername('wallace'); | ||
638 | $user->setPlainPassword('wallace'); | ||
639 | $user->setEnabled(true); | ||
640 | $user->addRole('ROLE_SUPER_ADMIN'); | ||
641 | |||
642 | $em->persist($user); | ||
643 | |||
644 | $config = new Config($user); | ||
645 | |||
646 | $config->setTheme('material'); | ||
647 | $config->setItemsPerPage(30); | ||
648 | $config->setReadingSpeed(1); | ||
649 | $config->setLanguage('en'); | ||
650 | $config->setPocketConsumerKey('xxxxx'); | ||
651 | |||
652 | $em->persist($config); | ||
653 | $em->flush(); | ||
654 | |||
655 | $this->logInAs('wallace'); | ||
656 | $loggedInUserId = $this->getLoggedInUserId(); | ||
657 | |||
658 | // create entry to check after user deletion | ||
659 | // that this entry is also deleted | ||
660 | $crawler = $client->request('GET', '/new'); | ||
661 | |||
662 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
663 | |||
664 | $form = $crawler->filter('form[name=entry]')->form(); | ||
665 | $data = [ | ||
666 | 'entry[url]' => $url = 'https://github.com/wallabag/wallabag', | ||
667 | ]; | ||
668 | |||
669 | $client->submit($form, $data); | ||
670 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
671 | |||
672 | $crawler = $client->request('GET', '/config'); | ||
673 | |||
674 | $deleteLink = $crawler->filter('.delete-account')->last()->link(); | ||
675 | |||
676 | $client->click($deleteLink); | ||
677 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
678 | |||
679 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
680 | $user = $em | ||
681 | ->getRepository('WallabagUserBundle:User') | ||
682 | ->createQueryBuilder('u') | ||
683 | ->where('u.username = :username')->setParameter('username', 'wallace') | ||
684 | ->getQuery() | ||
685 | ->getOneOrNullResult() | ||
686 | ; | ||
687 | |||
688 | $this->assertNull($user); | ||
689 | |||
690 | $entries = $client->getContainer() | ||
691 | ->get('doctrine.orm.entity_manager') | ||
692 | ->getRepository('WallabagCoreBundle:Entry') | ||
693 | ->findByUser($loggedInUserId); | ||
694 | |||
695 | $this->assertEmpty($entries); | ||
696 | } | ||
697 | |||
698 | public function testReset() | ||
699 | { | ||
700 | $this->logInAs('empty'); | ||
701 | $client = $this->getClient(); | ||
702 | |||
703 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
704 | |||
705 | $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser(); | ||
706 | |||
707 | $tag = new Tag(); | ||
708 | $tag->setLabel('super'); | ||
709 | $em->persist($tag); | ||
710 | |||
711 | $entry = new Entry($user); | ||
712 | $entry->setUrl('http://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html'); | ||
713 | $entry->setContent('Youhou'); | ||
714 | $entry->setTitle('Youhou'); | ||
715 | $entry->addTag($tag); | ||
716 | $em->persist($entry); | ||
717 | |||
718 | $entry2 = new Entry($user); | ||
719 | $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'); | ||
720 | $entry2->setContent('Youhou'); | ||
721 | $entry2->setTitle('Youhou'); | ||
722 | $entry2->addTag($tag); | ||
723 | $em->persist($entry2); | ||
724 | |||
725 | $annotation = new Annotation($user); | ||
726 | $annotation->setText('annotated'); | ||
727 | $annotation->setQuote('annotated'); | ||
728 | $annotation->setRanges([]); | ||
729 | $annotation->setEntry($entry); | ||
730 | $em->persist($annotation); | ||
731 | |||
732 | $em->flush(); | ||
733 | |||
734 | // reset annotations | ||
735 | $crawler = $client->request('GET', '/config#set3'); | ||
736 | |||
737 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
738 | |||
739 | $crawler = $client->click($crawler->selectLink('config.reset.annotations')->link()); | ||
740 | |||
741 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
742 | $this->assertContains('flashes.config.notice.annotations_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); | ||
743 | |||
744 | $annotationsReset = $em | ||
745 | ->getRepository('WallabagAnnotationBundle:Annotation') | ||
746 | ->findAnnotationsByPageId($entry->getId(), $user->getId()); | ||
747 | |||
748 | $this->assertEmpty($annotationsReset, 'Annotations were reset'); | ||
749 | |||
750 | // reset tags | ||
751 | $crawler = $client->request('GET', '/config#set3'); | ||
752 | |||
753 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
754 | |||
755 | $crawler = $client->click($crawler->selectLink('config.reset.tags')->link()); | ||
756 | |||
757 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
758 | $this->assertContains('flashes.config.notice.tags_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); | ||
759 | |||
760 | $tagReset = $em | ||
761 | ->getRepository('WallabagCoreBundle:Tag') | ||
762 | ->countAllTags($user->getId()); | ||
763 | |||
764 | $this->assertEquals(0, $tagReset, 'Tags were reset'); | ||
765 | |||
766 | // reset entries | ||
767 | $crawler = $client->request('GET', '/config#set3'); | ||
768 | |||
769 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
770 | |||
771 | $crawler = $client->click($crawler->selectLink('config.reset.entries')->link()); | ||
772 | |||
773 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
774 | $this->assertContains('flashes.config.notice.entries_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); | ||
775 | |||
776 | $entryReset = $em | ||
777 | ->getRepository('WallabagCoreBundle:Entry') | ||
778 | ->countAllEntriesByUsername($user->getId()); | ||
779 | |||
780 | $this->assertEquals(0, $entryReset, 'Entries were reset'); | ||
781 | } | ||
782 | |||
783 | public function testResetEntriesCascade() | ||
784 | { | ||
785 | $this->logInAs('empty'); | ||
786 | $client = $this->getClient(); | ||
787 | |||
788 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
789 | |||
790 | $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser(); | ||
791 | |||
792 | $tag = new Tag(); | ||
793 | $tag->setLabel('super'); | ||
794 | $em->persist($tag); | ||
795 | |||
796 | $entry = new Entry($user); | ||
797 | $entry->setUrl('http://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html'); | ||
798 | $entry->setContent('Youhou'); | ||
799 | $entry->setTitle('Youhou'); | ||
800 | $entry->addTag($tag); | ||
801 | $em->persist($entry); | ||
802 | |||
803 | $annotation = new Annotation($user); | ||
804 | $annotation->setText('annotated'); | ||
805 | $annotation->setQuote('annotated'); | ||
806 | $annotation->setRanges([]); | ||
807 | $annotation->setEntry($entry); | ||
808 | $em->persist($annotation); | ||
809 | |||
810 | $em->flush(); | ||
811 | |||
812 | $crawler = $client->request('GET', '/config#set3'); | ||
813 | |||
814 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
815 | |||
816 | $crawler = $client->click($crawler->selectLink('config.reset.entries')->link()); | ||
817 | |||
818 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
819 | $this->assertContains('flashes.config.notice.entries_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); | ||
820 | |||
821 | $entryReset = $em | ||
822 | ->getRepository('WallabagCoreBundle:Entry') | ||
823 | ->countAllEntriesByUsername($user->getId()); | ||
824 | |||
825 | $this->assertEquals(0, $entryReset, 'Entries were reset'); | ||
826 | |||
827 | $tagReset = $em | ||
828 | ->getRepository('WallabagCoreBundle:Tag') | ||
829 | ->countAllTags($user->getId()); | ||
830 | |||
831 | $this->assertEquals(0, $tagReset, 'Tags were reset'); | ||
832 | |||
833 | $annotationsReset = $em | ||
834 | ->getRepository('WallabagAnnotationBundle:Annotation') | ||
835 | ->findAnnotationsByPageId($entry->getId(), $user->getId()); | ||
836 | |||
837 | $this->assertEmpty($annotationsReset, 'Annotations were reset'); | ||
838 | } | ||
573 | } | 839 | } |