create first round of tests for login

This commit is contained in:
Julien Fastré 2014-11-07 00:10:51 +01:00
parent 27a2cf5dc1
commit 143835b6b2
2 changed files with 57 additions and 0 deletions

View File

@ -3,6 +3,7 @@
namespace Chill\MainBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\Response;
class LoginControllerTest extends WebTestCase
{
@ -10,7 +11,50 @@ class LoginControllerTest extends WebTestCase
{
$client = static::createClient();
//load login page and submit form
$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'));
}
}

View 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>