]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Added tests
authorNicolas LÅ“uillet <nicolas@loeuillet.org>
Thu, 8 Sep 2016 13:47:03 +0000 (15:47 +0200)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Sat, 8 Oct 2016 11:27:18 +0000 (13:27 +0200)
tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php

index 1954c654a53fba9f7882d62ad524907fcd6fa069..23e7e78601113b079d53f05b94ce21dc2f166d47 100644 (file)
@@ -570,4 +570,89 @@ class ConfigControllerTest extends WallabagCoreTestCase
         $config->set('demo_mode_enabled', 0);
         $config->set('demo_mode_username', 'wallabag');
     }
+
+    public function testDeleteUserButtonVisibility()
+    {
+        $this->logInAs('admin');
+        $client = $this->getClient();
+
+        $crawler = $client->request('GET', '/config');
+
+        $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
+        $this->assertContains('config.form_user.delete_account', $body[0]);
+
+        $em = $client->getContainer()->get('doctrine.orm.entity_manager');
+
+        $user = $em
+            ->getRepository('WallabagUserBundle:User')
+            ->findOneByUsername('wallace');
+        $user->setExpired(1);
+        $em->persist($user);
+
+        $user = $em
+            ->getRepository('WallabagUserBundle:User')
+            ->findOneByUsername('empty');
+        $user->setExpired(1);
+        $em->persist($user);
+
+        $user = $em
+            ->getRepository('WallabagUserBundle:User')
+            ->findOneByUsername('bob');
+        $user->setExpired(1);
+        $em->persist($user);
+
+        $em->flush();
+
+        $crawler = $client->request('GET', '/config');
+
+        $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
+        $this->assertNotContains('config.form_user.delete_account', $body[0]);
+
+        $client->request('GET', '/account/delete');
+        $this->assertEquals(403, $client->getResponse()->getStatusCode());
+
+        $user = $em
+            ->getRepository('WallabagUserBundle:User')
+            ->findOneByUsername('wallace');
+        $user->setExpired(0);
+        $em->persist($user);
+
+        $user = $em
+            ->getRepository('WallabagUserBundle:User')
+            ->findOneByUsername('empty');
+        $user->setExpired(0);
+        $em->persist($user);
+
+        $user = $em
+            ->getRepository('WallabagUserBundle:User')
+            ->findOneByUsername('bob');
+        $user->setExpired(0);
+        $em->persist($user);
+
+        $em->flush();
+    }
+
+    public function testDeleteAccount()
+    {
+        $this->logInAs('wallace');
+        $client = $this->getClient();
+
+        $crawler = $client->request('GET', '/config');
+
+        $deleteLink = $crawler->filter('.red')->last()->link();
+
+        $client->click($deleteLink);
+        $this->assertEquals(302, $client->getResponse()->getStatusCode());
+
+        $em = $client->getContainer()->get('doctrine.orm.entity_manager');
+        $user = $em
+            ->getRepository('WallabagUserBundle:User')
+            ->createQueryBuilder('u')
+            ->where('u.username = :username')->setParameter('username', 'wallace')
+            ->getQuery()
+            ->getOneOrNullResult()
+        ;
+
+        $this->assertTrue(false !== $user);
+    }
 }