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