mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-27 01:53:49 +00:00
create first round of tests for login
This commit is contained in:
@@ -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'));
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user