aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Wallabag')
-rw-r--r--tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php120
1 files changed, 120 insertions, 0 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
index 1954c654..5faa0130 100644
--- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
@@ -3,6 +3,8 @@
3namespace Tests\Wallabag\CoreBundle\Controller; 3namespace Tests\Wallabag\CoreBundle\Controller;
4 4
5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; 5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
6use Wallabag\CoreBundle\Entity\Config;
7use Wallabag\UserBundle\Entity\User;
6 8
7class ConfigControllerTest extends WallabagCoreTestCase 9class ConfigControllerTest extends WallabagCoreTestCase
8{ 10{
@@ -570,4 +572,122 @@ class ConfigControllerTest extends WallabagCoreTestCase
570 $config->set('demo_mode_enabled', 0); 572 $config->set('demo_mode_enabled', 0);
571 $config->set('demo_mode_username', 'wallabag'); 573 $config->set('demo_mode_username', 'wallabag');
572 } 574 }
575
576 public function testDeleteUserButtonVisibility()
577 {
578 $this->logInAs('admin');
579 $client = $this->getClient();
580
581 $crawler = $client->request('GET', '/config');
582
583 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
584 $this->assertContains('config.form_user.delete.button', $body[0]);
585
586 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
587
588 $user = $em
589 ->getRepository('WallabagUserBundle:User')
590 ->findOneByUsername('empty');
591 $user->setExpired(1);
592 $em->persist($user);
593
594 $user = $em
595 ->getRepository('WallabagUserBundle:User')
596 ->findOneByUsername('bob');
597 $user->setExpired(1);
598 $em->persist($user);
599
600 $em->flush();
601
602 $crawler = $client->request('GET', '/config');
603
604 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
605 $this->assertNotContains('config.form_user.delete.button', $body[0]);
606
607 $client->request('GET', '/account/delete');
608 $this->assertEquals(403, $client->getResponse()->getStatusCode());
609
610 $user = $em
611 ->getRepository('WallabagUserBundle:User')
612 ->findOneByUsername('empty');
613 $user->setExpired(0);
614 $em->persist($user);
615
616 $user = $em
617 ->getRepository('WallabagUserBundle:User')
618 ->findOneByUsername('bob');
619 $user->setExpired(0);
620 $em->persist($user);
621
622 $em->flush();
623 }
624
625 public function testDeleteAccount()
626 {
627 $client = $this->getClient();
628 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
629
630 $user = new User();
631 $user->setName('Wallace');
632 $user->setEmail('wallace@wallabag.org');
633 $user->setUsername('wallace');
634 $user->setPlainPassword('wallace');
635 $user->setEnabled(true);
636 $user->addRole('ROLE_SUPER_ADMIN');
637
638 $em->persist($user);
639
640 $config = new Config($user);
641
642 $config->setTheme('material');
643 $config->setItemsPerPage(30);
644 $config->setReadingSpeed(1);
645 $config->setLanguage('en');
646 $config->setPocketConsumerKey('xxxxx');
647
648 $em->persist($config);
649 $em->flush();
650
651 $this->logInAs('wallace');
652 $loggedInUserId = $this->getLoggedInUserId();
653
654 // create entry to check after user deletion
655 // that this entry is also deleted
656 $crawler = $client->request('GET', '/new');
657
658 $this->assertEquals(200, $client->getResponse()->getStatusCode());
659
660 $form = $crawler->filter('form[name=entry]')->form();
661 $data = [
662 'entry[url]' => $url = 'https://github.com/wallabag/wallabag',
663 ];
664
665 $client->submit($form, $data);
666 $this->assertEquals(302, $client->getResponse()->getStatusCode());
667
668 $crawler = $client->request('GET', '/config');
669
670 $deleteLink = $crawler->filter('.delete-account')->last()->link();
671
672 $client->click($deleteLink);
673 $this->assertEquals(302, $client->getResponse()->getStatusCode());
674
675 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
676 $user = $em
677 ->getRepository('WallabagUserBundle:User')
678 ->createQueryBuilder('u')
679 ->where('u.username = :username')->setParameter('username', 'wallace')
680 ->getQuery()
681 ->getOneOrNullResult()
682 ;
683
684 $this->assertNull($user);
685
686 $entries = $client->getContainer()
687 ->get('doctrine.orm.entity_manager')
688 ->getRepository('WallabagCoreBundle:Entry')
689 ->findByUser($loggedInUserId);
690
691 $this->assertEmpty($entries);
692 }
573} 693}