X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FTests%2FController%2FSecurityControllerTest.php;h=7af9d5c45747e7f932c4c657f0406ad6abb8e566;hb=2c13918acc3c46120bbef5e6746f3c6dc27be5df;hp=a51e836d1586c74659a5145175f59b35dff1a38e;hpb=4ab58dcf6c833170c307de120698740fe0685efb;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php index a51e836d..7af9d5c4 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php @@ -8,6 +8,124 @@ use Wallabag\CoreBundle\Tests\WallabagCoreTestCase; class SecurityControllerTest extends WallabagCoreTestCase { + public function testRegister() + { + $client = $this->getClient(); + + $crawler = $client->request('GET', '/register/'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertContains('Register', $client->getResponse()->getContent()); + } + + public function dataForCreateAccountFailed() + { + return array( + array( + array( + 'fos_user_registration_form[email]' => '', + 'fos_user_registration_form[username]' => 'newuser', + 'fos_user_registration_form[plainPassword][first]' => 'mypassword', + 'fos_user_registration_form[plainPassword][second]' => 'mypassword', + ), + 'Please enter an email', + ), + array( + array( + 'fos_user_registration_form[email]' => 'newuser@wallabag.org', + 'fos_user_registration_form[username]' => 'admin', + 'fos_user_registration_form[plainPassword][first]' => 'mypassword', + 'fos_user_registration_form[plainPassword][second]' => 'mypassword', + ), + 'The username is already used', + ), + array( + array( + 'fos_user_registration_form[email]' => 'newuser@wallabag.org', + 'fos_user_registration_form[username]' => 'newuser', + 'fos_user_registration_form[plainPassword][first]' => 'mypassword1', + 'fos_user_registration_form[plainPassword][second]' => 'mypassword2', + ), + 'The entered passwords don't match', + ), + ); + } + + /** + * @dataProvider dataForCreateAccountFailed + */ + public function testCreateAccountFailed($data, $expectedMessage) + { + $client = $this->getClient(); + + $crawler = $client->request('GET', '/register/'); + + $form = $crawler->filter('input[type=submit]')->form(); + + $client->submit($form, $data); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertContains($expectedMessage, $client->getResponse()->getContent()); + } + + public function dataForCreateAccountSuccess() + { + return array( + array( + array( + 'fos_user_registration_form[email]' => 'newuser@wallabag.org', + 'fos_user_registration_form[username]' => 'newuser', + 'fos_user_registration_form[plainPassword][first]' => 'mypassword', + 'fos_user_registration_form[plainPassword][second]' => 'mypassword', + ), + ), + ); + } + + /** + * @dataProvider dataForCreateAccountSuccess + */ + public function testCreateAccountSuccess($data) + { + $client = $this->getClient(); + + $crawler = $client->request('GET', '/register/'); + + $form = $crawler->filter('input[type=submit]')->form(); + + $client->submit($form, $data); + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertContains('The user has been created successfully', $client->getResponse()->getContent()); + } + + public function testRegistrationConfirmation() + { + $client = $this->getClient(); + $client->followRedirects(); + + $user = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:User') + ->findOneByUsername('newuser'); + + $this->assertNull($user->getConfig()); + + $client->request('GET', '/register/confirm/b4dT0k3n'); + $this->assertEquals(404, $client->getResponse()->getStatusCode()); + + $crawler = $client->request('GET', '/register/confirm/'.$user->getConfirmationToken()); + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $user = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:User') + ->findOneByUsername('newuser'); + $this->assertNotNull($user->getConfig()); + } + public function testLogin() { $client = $this->getClient(); @@ -40,6 +158,25 @@ class SecurityControllerTest extends WallabagCoreTestCase $this->assertContains('Bad credentials', $client->getResponse()->getContent()); } + public function testRedirectionAfterLogin() + { + $client = $this->getClient(); + $client->followRedirects(); + + $crawler = $client->request('GET', '/config'); + + $form = $crawler->filter('button[type=submit]')->form(); + + $data = array( + '_username' => 'admin', + '_password' => 'mypassword', + ); + + $client->submit($form, $data); + + $this->assertContains('RSS', $client->getResponse()->getContent()); + } + public function testForgotPassword() { $client = $this->getClient();