mirror of
https://github.com/wallabag/wallabag.git
synced 2025-01-24 23:58:13 +00:00
* rename AuthenticationListener
* add tests
This commit is contained in:
parent
772732531e
commit
359b3f43cc
4 changed files with 96 additions and 2 deletions
|
@ -9,7 +9,7 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||||
use FOS\UserBundle\Event\FilterUserResponseEvent;
|
use FOS\UserBundle\Event\FilterUserResponseEvent;
|
||||||
use Wallabag\CoreBundle\Entity\Config;
|
use Wallabag\CoreBundle\Entity\Config;
|
||||||
|
|
||||||
class AuthenticationListener implements EventSubscriberInterface
|
class RegistrationConfirmedListener implements EventSubscriberInterface
|
||||||
{
|
{
|
||||||
private $em;
|
private $em;
|
||||||
private $container;
|
private $container;
|
|
@ -47,7 +47,7 @@ services:
|
||||||
- @wallabag_core.graby
|
- @wallabag_core.graby
|
||||||
|
|
||||||
wallabag_core.registration_confirmed:
|
wallabag_core.registration_confirmed:
|
||||||
class: Wallabag\CoreBundle\EventListener\AuthenticationListener
|
class: Wallabag\CoreBundle\EventListener\RegistrationConfirmedListener
|
||||||
arguments: [@service_container, @doctrine.orm.entity_manager]
|
arguments: [@service_container, @doctrine.orm.entity_manager]
|
||||||
tags:
|
tags:
|
||||||
- { name: kernel.event_subscriber }
|
- { name: kernel.event_subscriber }
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
<div class="row mts txtcenter">
|
<div class="row mts txtcenter">
|
||||||
<input type="hidden" name="_csrf_token" value="{{ csrf_token('authenticate') }}" />
|
<input type="hidden" name="_csrf_token" value="{{ csrf_token('authenticate') }}" />
|
||||||
<button type="submit">Login</button>
|
<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>
|
<a href="{{ path('forgot_password') }}" class="small">Forgot your password?</a>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
|
@ -8,6 +8,99 @@ use Wallabag\CoreBundle\Tests\WallabagCoreTestCase;
|
||||||
|
|
||||||
class SecurityControllerTest extends 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()
|
public function testLogin()
|
||||||
{
|
{
|
||||||
$client = $this->getClient();
|
$client = $this->getClient();
|
||||||
|
|
Loading…
Reference in a new issue