aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php145
1 files changed, 145 insertions, 0 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
index 5faa0130..8d0644d1 100644
--- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
@@ -5,6 +5,9 @@ namespace Tests\Wallabag\CoreBundle\Controller;
5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; 5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
6use Wallabag\CoreBundle\Entity\Config; 6use Wallabag\CoreBundle\Entity\Config;
7use Wallabag\UserBundle\Entity\User; 7use Wallabag\UserBundle\Entity\User;
8use Wallabag\CoreBundle\Entity\Entry;
9use Wallabag\CoreBundle\Entity\Tag;
10use Wallabag\AnnotationBundle\Entity\Annotation;
8 11
9class ConfigControllerTest extends WallabagCoreTestCase 12class ConfigControllerTest extends WallabagCoreTestCase
10{ 13{
@@ -690,4 +693,146 @@ class ConfigControllerTest extends WallabagCoreTestCase
690 693
691 $this->assertEmpty($entries); 694 $this->assertEmpty($entries);
692 } 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 }
693} 838}