From: Nicolas LÅ“uillet Date: Tue, 29 Sep 2015 15:05:17 +0000 (+0200) Subject: * rename AuthenticationListener X-Git-Tag: 2.0.0-alpha.1~28^2~9 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=359b3f43cc42aa593cdba7dc8e1d6fa121cc3f6a;p=github%2Fwallabag%2Fwallabag.git * rename AuthenticationListener * add tests --- diff --git a/src/Wallabag/CoreBundle/EventListener/AuthenticationListener.php b/src/Wallabag/CoreBundle/EventListener/RegistrationConfirmedListener.php similarity index 94% rename from src/Wallabag/CoreBundle/EventListener/AuthenticationListener.php rename to src/Wallabag/CoreBundle/EventListener/RegistrationConfirmedListener.php index 7c2826ec..bcc84923 100644 --- a/src/Wallabag/CoreBundle/EventListener/AuthenticationListener.php +++ b/src/Wallabag/CoreBundle/EventListener/RegistrationConfirmedListener.php @@ -9,7 +9,7 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; use FOS\UserBundle\Event\FilterUserResponseEvent; use Wallabag\CoreBundle\Entity\Config; -class AuthenticationListener implements EventSubscriberInterface +class RegistrationConfirmedListener implements EventSubscriberInterface { private $em; private $container; diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml index 96ea482a..f2247260 100644 --- a/src/Wallabag/CoreBundle/Resources/config/services.yml +++ b/src/Wallabag/CoreBundle/Resources/config/services.yml @@ -47,7 +47,7 @@ services: - @wallabag_core.graby wallabag_core.registration_confirmed: - class: Wallabag\CoreBundle\EventListener\AuthenticationListener + class: Wallabag\CoreBundle\EventListener\RegistrationConfirmedListener arguments: [@service_container, @doctrine.orm.entity_manager] tags: - { name: kernel.event_subscriber } diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Security/login.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Security/login.html.twig index 5437d20c..9a59dfc6 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Security/login.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Security/login.html.twig @@ -32,6 +32,7 @@
+ {% trans %}Register{% endtrans %} Forgot your password?
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();