From d0c2243b1099303be961c9d4b33eaaa95e663bef Mon Sep 17 00:00:00 2001 From: Jeremy Date: Sun, 8 Mar 2015 22:47:32 +0100 Subject: Add some tests --- .../CoreBundle/Controller/SecurityController.php | 2 +- .../Tests/Controller/SecurityControllerTest.php | 45 ++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) (limited to 'src') 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')); + } } -- cgit v1.2.3