From: Jeremy Date: Sun, 8 Mar 2015 21:47:32 +0000 (+0100) Subject: Add some tests X-Git-Tag: 2.0.0-alpha.0~71^2 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=d0c2243b1099303be961c9d4b33eaaa95e663bef;p=github%2Fwallabag%2Fwallabag.git Add some tests --- diff --git a/src/Wallabag/CoreBundle/Controller/SecurityController.php b/src/Wallabag/CoreBundle/Controller/SecurityController.php index 5007307a..fe511db5 100644 --- a/src/Wallabag/CoreBundle/Controller/SecurityController.php +++ b/src/Wallabag/CoreBundle/Controller/SecurityController.php @@ -103,7 +103,7 @@ class SecurityController extends Controller $user = $this->getDoctrine()->getRepository('WallabagCoreBundle:User')->findOneByConfirmationToken($token); if (null === $user) { - $this->createNotFoundException(sprintf('No user found with token "%s"', $token)); + throw $this->createNotFoundException(sprintf('No user found with token "%s"', $token)); } $form = $this->createForm(new ResetPasswordType()); diff --git a/src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php index e02c4d05..1dd05f89 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php @@ -134,4 +134,49 @@ class SecurityControllerTest extends WallabagTestCase ); } } + + public function testReset() + { + $client = $this->getClient(); + $user = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:User') + ->findOneByEmail('bobby@wallabag.org'); + + $crawler = $client->request('GET', '/forgot-password/'.$user->getConfirmationToken()); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertCount(2, $crawler->filter('input[type=password]')); + $this->assertCount(1, $form = $crawler->filter('button[type=submit]')); + $this->assertCount(1, $form); + + $data = array( + 'change_passwd[new_password][first]' => 'mypassword', + 'change_passwd[new_password][second]' => 'mypassword', + ); + + $client->submit($form->form(), $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertContains('login', $client->getResponse()->headers->get('location')); + } + + public function testResetBadToken() + { + $client = $this->getClient(); + + $client->request('GET', '/forgot-password/UIZOAU29UE902IEPZO'); + + $this->assertEquals(404, $client->getResponse()->getStatusCode()); + } + + public function testCheckEmailWithoutEmail() + { + $client = $this->getClient(); + + $client->request('GET', '/forgot-password/check-email'); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertContains('forgot-password', $client->getResponse()->headers->get('location')); + } }