]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
* rename AuthenticationListener
authorNicolas LÅ“uillet <nicolas@loeuillet.org>
Tue, 29 Sep 2015 15:05:17 +0000 (17:05 +0200)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Sat, 3 Oct 2015 11:30:43 +0000 (13:30 +0200)
* add tests

src/Wallabag/CoreBundle/EventListener/RegistrationConfirmedListener.php [moved from src/Wallabag/CoreBundle/EventListener/AuthenticationListener.php with 94% similarity]
src/Wallabag/CoreBundle/Resources/config/services.yml
src/Wallabag/CoreBundle/Resources/views/themes/baggy/Security/login.html.twig
src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php

similarity index 94%
rename from src/Wallabag/CoreBundle/EventListener/AuthenticationListener.php
rename to src/Wallabag/CoreBundle/EventListener/RegistrationConfirmedListener.php
index 7c2826ecd7137e752a8accd036ef4e7d811b399b..bcc84923b9ca464c7b858b74ba68328a3f670581 100644 (file)
@@ -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;
index 96ea482ae73e0f5329544f8ed1563726a81db059..f2247260714c4b443c9253bd31326a0cc84955cc 100644 (file)
@@ -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 }
index 5437d20c4aca12f2769ef0f8aa78fcec29152184..9a59dfc60651c7a22e9a2d7455d9188a98cd3ad4 100644 (file)
@@ -32,6 +32,7 @@
                 <div class="row mts txtcenter">
                     <input type="hidden" name="_csrf_token" value="{{ csrf_token('authenticate') }}" />
                     <button type="submit">Login</button>
+                    <a href="{{ path('fos_user_registration_register') }}" class="button">{% trans %}Register{% endtrans %}</a>
                     <a href="{{ path('forgot_password') }}" class="small">Forgot your password?</a>
                 </div>
             </fieldset>
index 759ef01b0417b2e63f88d984b95f2737e6ec749f..78b4952e4583f72638a0aecc0ea5af44f799aaf0 100644 (file)
@@ -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&#039;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();