Add some tests

This commit is contained in:
Jeremy 2015-03-08 22:47:32 +01:00
parent 6894d48e03
commit d0c2243b10
2 changed files with 46 additions and 1 deletions

View File

@ -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());

View File

@ -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'));
}
}