X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=src%2FWallabag%2FCoreBundle%2FTests%2FController%2FSecurityControllerTest.php;h=78b4952e4583f72638a0aecc0ea5af44f799aaf0;hb=359b3f43cc42aa593cdba7dc8e1d6fa121cc3f6a;hp=759ef01b0417b2e63f88d984b95f2737e6ec749f;hpb=772732531ea1d0f9831cc5f29e11b6b11fd088f3;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php index 759ef01b..78b4952e 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php @@ -8,6 +8,99 @@ 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 testLogin() { $client = $this->getClient();