mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
create first round of tests for login
This commit is contained in:
parent
27a2cf5dc1
commit
143835b6b2
@ -3,6 +3,7 @@
|
|||||||
namespace Chill\MainBundle\Tests\Controller;
|
namespace Chill\MainBundle\Tests\Controller;
|
||||||
|
|
||||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
class LoginControllerTest extends WebTestCase
|
class LoginControllerTest extends WebTestCase
|
||||||
{
|
{
|
||||||
@ -10,7 +11,50 @@ class LoginControllerTest extends WebTestCase
|
|||||||
{
|
{
|
||||||
$client = static::createClient();
|
$client = static::createClient();
|
||||||
|
|
||||||
|
//load login page and submit form
|
||||||
$crawler = $client->request('GET', '/login');
|
$crawler = $client->request('GET', '/login');
|
||||||
|
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||||
|
|
||||||
|
$buttonCrawlerNode = $crawler->selectButton('Login');
|
||||||
|
$form = $buttonCrawlerNode->form();
|
||||||
|
|
||||||
|
$client->submit($form, array(
|
||||||
|
'_username' => 'center a_social',
|
||||||
|
'_password' => 'password'
|
||||||
|
));
|
||||||
|
|
||||||
|
//the response is a redirection
|
||||||
|
$this->assertTrue($client->getResponse()->isRedirect());
|
||||||
|
|
||||||
|
//the response is not a login page, but on a new page
|
||||||
|
$this->assertNotRegExp('/\/login$/', $client->getResponse()
|
||||||
|
->headers
|
||||||
|
->get('location'));
|
||||||
|
|
||||||
|
//on the home page, there must be a logout link
|
||||||
|
$client->followRedirects(true);
|
||||||
|
$crawler = $client->request('GET', '/');
|
||||||
|
|
||||||
|
$this->assertRegExp('/center a_social/', $client->getResponse()
|
||||||
|
->getContent());
|
||||||
|
$logoutLinkFilter = $crawler->filter('a:contains("Logout")');
|
||||||
|
|
||||||
|
//check there is > 0 logout link
|
||||||
|
$this->assertGreaterThan(0, $logoutLinkFilter->count());
|
||||||
|
|
||||||
|
//click on logout link
|
||||||
|
$client->followRedirects(false);
|
||||||
|
$client->click($crawler->selectLink('Logout')->link());
|
||||||
|
|
||||||
|
$this->assertTrue($client->getResponse()->isRedirect());
|
||||||
|
$client->followRedirect(); #redirect to login page
|
||||||
|
|
||||||
|
//check we are back on login page
|
||||||
|
$this->assertRegExp('/\/login$/', $client->getResponse()
|
||||||
|
->headers
|
||||||
|
->get('location'));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
13
Tests/Fixtures/App/Resources/views/base.html.twig
Normal file
13
Tests/Fixtures/App/Resources/views/base.html.twig
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<title>{% block title %}Welcome!{% endblock %}</title>
|
||||||
|
{% block stylesheets %}{% endblock %}
|
||||||
|
<link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
{% block body %}{% endblock %}
|
||||||
|
{% block javascripts %}{% endblock %}
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
x
Reference in New Issue
Block a user