mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 05:44:24 +00:00
fix required fields in user controller test
This commit is contained in:
parent
c62254caec
commit
b06e726ad1
@ -7,11 +7,11 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
|||||||
class UserControllerTest extends WebTestCase
|
class UserControllerTest extends WebTestCase
|
||||||
{
|
{
|
||||||
private $client;
|
private $client;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
self::bootKernel();
|
self::bootKernel();
|
||||||
|
|
||||||
$this->client = static::createClient(array(), array(
|
$this->client = static::createClient(array(), array(
|
||||||
'PHP_AUTH_USER' => 'admin',
|
'PHP_AUTH_USER' => 'admin',
|
||||||
'PHP_AUTH_PW' => 'password',
|
'PHP_AUTH_PW' => 'password',
|
||||||
@ -23,62 +23,64 @@ class UserControllerTest extends WebTestCase
|
|||||||
{
|
{
|
||||||
// get the list
|
// get the list
|
||||||
$crawler = $this->client->request('GET', '/fr/admin/user/');
|
$crawler = $this->client->request('GET', '/fr/admin/user/');
|
||||||
$this->assertEquals(200, $this->client->getResponse()->getStatusCode(),
|
$this->assertEquals(200, $this->client->getResponse()->getStatusCode(),
|
||||||
"Unexpected HTTP status code for GET /admin/user/");
|
"Unexpected HTTP status code for GET /admin/user/");
|
||||||
|
|
||||||
$link = $crawler->selectLink('Ajouter un nouvel utilisateur')->link();
|
$link = $crawler->selectLink('Ajouter un nouvel utilisateur')->link();
|
||||||
$this->assertInstanceOf('Symfony\Component\DomCrawler\Link', $link);
|
$this->assertInstanceOf('Symfony\Component\DomCrawler\Link', $link);
|
||||||
$this->assertRegExp('|/fr/admin/user/new$|', $link->getUri());
|
$this->assertRegExp('|/fr/admin/user/new$|', $link->getUri());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNew()
|
public function testNew()
|
||||||
{
|
{
|
||||||
$crawler = $this->client->request('GET', '/fr/admin/user/new');
|
$crawler = $this->client->request('GET', '/fr/admin/user/new');
|
||||||
|
|
||||||
$username = 'Test_user'. uniqid();
|
$username = 'Test_user'. uniqid();
|
||||||
$password = 'Password1234!';
|
$password = 'Password1234!';
|
||||||
dump($crawler->text());
|
|
||||||
// Fill in the form and submit it
|
// Fill in the form and submit it
|
||||||
$form = $crawler->selectButton('Créer')->form(array(
|
$form = $crawler->selectButton('Créer')->form(array(
|
||||||
'chill_mainbundle_user[username]' => $username,
|
'chill_mainbundle_user[username]' => $username,
|
||||||
'chill_mainbundle_user[plainPassword][first]' => $password,
|
'chill_mainbundle_user[plainPassword][first]' => $password,
|
||||||
'chill_mainbundle_user[plainPassword][second]' => $password
|
'chill_mainbundle_user[plainPassword][second]' => $password,
|
||||||
|
'chill_mainbundle_user[email]' => $username.'@gmail.com',
|
||||||
|
'chill_mainbundle_user[label]' => $username,
|
||||||
|
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->client->submit($form);
|
$this->client->submit($form);
|
||||||
$crawler = $this->client->followRedirect();
|
$crawler = $this->client->followRedirect();
|
||||||
|
|
||||||
// Check data in the show view
|
// Check data in the show view
|
||||||
$this->assertGreaterThan(0, $crawler->filter('td:contains("Test_user")')->count(),
|
$this->assertGreaterThan(0, $crawler->filter('td:contains("Test_user")')->count(),
|
||||||
'Missing element td:contains("Test user")');
|
'Missing element td:contains("Test user")');
|
||||||
|
|
||||||
$update = $crawler->selectLink('Modifier')->link();
|
$update = $crawler->selectLink('Modifier')->link();
|
||||||
|
|
||||||
$this->assertInstanceOf('Symfony\Component\DomCrawler\Link', $update);
|
$this->assertInstanceOf('Symfony\Component\DomCrawler\Link', $update);
|
||||||
$this->assertRegExp('|/fr/admin/user/[0-9]{1,}/edit$|', $update->getUri());
|
$this->assertRegExp('|/fr/admin/user/[0-9]{1,}/edit$|', $update->getUri());
|
||||||
|
|
||||||
//test the auth of the new client
|
//test the auth of the new client
|
||||||
$this->isPasswordValid($username, $password);
|
$this->isPasswordValid($username, $password);
|
||||||
|
|
||||||
return $update;
|
return $update;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function isPasswordValid($username, $password)
|
protected function isPasswordValid($username, $password)
|
||||||
{
|
{
|
||||||
/* @var $passwordEncoder \Symfony\Component\Security\Core\Encoder\UserPasswordEncoder */
|
/* @var $passwordEncoder \Symfony\Component\Security\Core\Encoder\UserPasswordEncoder */
|
||||||
$passwordEncoder = self::$kernel->getContainer()
|
$passwordEncoder = self::$kernel->getContainer()
|
||||||
->get('security.password_encoder');
|
->get('security.password_encoder');
|
||||||
|
|
||||||
$user = self::$kernel->getContainer()
|
$user = self::$kernel->getContainer()
|
||||||
->get('doctrine.orm.entity_manager')
|
->get('doctrine.orm.entity_manager')
|
||||||
->getRepository('ChillMainBundle:User')
|
->getRepository('ChillMainBundle:User')
|
||||||
->findOneBy(array('username' => $username));
|
->findOneBy(array('username' => $username));
|
||||||
|
|
||||||
$this->assertTrue($passwordEncoder->isPasswordValid($user, $password));
|
$this->assertTrue($passwordEncoder->isPasswordValid($user, $password));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param \Symfony\Component\DomCrawler\Link $update
|
* @param \Symfony\Component\DomCrawler\Link $update
|
||||||
* @depends testNew
|
* @depends testNew
|
||||||
*/
|
*/
|
||||||
@ -90,24 +92,24 @@ class UserControllerTest extends WebTestCase
|
|||||||
$form = $crawler->selectButton('Mettre à jour')->form(array(
|
$form = $crawler->selectButton('Mettre à jour')->form(array(
|
||||||
'chill_mainbundle_user[username]' => $username,
|
'chill_mainbundle_user[username]' => $username,
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->client->submit($form);
|
$this->client->submit($form);
|
||||||
$crawler = $this->client->followRedirect();
|
$crawler = $this->client->followRedirect();
|
||||||
// Check the element contains an attribute with value equals "Foo"
|
// Check the element contains an attribute with value equals "Foo"
|
||||||
$this->assertGreaterThan(0, $crawler->filter('[value="'.$username.'"]')->count(),
|
$this->assertGreaterThan(0, $crawler->filter('[value="'.$username.'"]')->count(),
|
||||||
'Missing element [value="Foo bar"]');
|
'Missing element [value="Foo bar"]');
|
||||||
|
|
||||||
$updatePassword = $crawler->selectLink('Modifier le mot de passe')->link();
|
$updatePassword = $crawler->selectLink('Modifier le mot de passe')->link();
|
||||||
|
|
||||||
$this->assertInstanceOf('Symfony\Component\DomCrawler\Link', $updatePassword);
|
$this->assertInstanceOf('Symfony\Component\DomCrawler\Link', $updatePassword);
|
||||||
$this->assertRegExp('|/fr/admin/user/[0-9]{1,}/edit_password$|',
|
$this->assertRegExp('|/fr/admin/user/[0-9]{1,}/edit_password$|',
|
||||||
$updatePassword->getUri());
|
$updatePassword->getUri());
|
||||||
|
|
||||||
return array('link' => $updatePassword, 'username' => $username);
|
return array('link' => $updatePassword, 'username' => $username);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param \Symfony\Component\DomCrawler\Link $updatePassword
|
* @param \Symfony\Component\DomCrawler\Link $updatePassword
|
||||||
* @depends testUpdate
|
* @depends testUpdate
|
||||||
*/
|
*/
|
||||||
@ -116,22 +118,22 @@ class UserControllerTest extends WebTestCase
|
|||||||
$link = $params['link'];
|
$link = $params['link'];
|
||||||
$username = $params['username'];
|
$username = $params['username'];
|
||||||
$newPassword = '1234Password!';
|
$newPassword = '1234Password!';
|
||||||
|
|
||||||
$crawler = $this->client->click($link);
|
$crawler = $this->client->click($link);
|
||||||
|
|
||||||
$form = $crawler->selectButton('Changer le mot de passe')->form(array(
|
$form = $crawler->selectButton('Changer le mot de passe')->form(array(
|
||||||
'chill_mainbundle_user_password[new_password][first]' => $newPassword,
|
'chill_mainbundle_user_password[new_password][first]' => $newPassword,
|
||||||
'chill_mainbundle_user_password[new_password][second]' => $newPassword,
|
'chill_mainbundle_user_password[new_password][second]' => $newPassword,
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->client->submit($form);
|
$this->client->submit($form);
|
||||||
|
|
||||||
$this->assertTrue($this->client->getResponse()->isRedirect(),
|
$this->assertTrue($this->client->getResponse()->isRedirect(),
|
||||||
"the response is a redirection");
|
"the response is a redirection");
|
||||||
$this->client->followRedirect();
|
$this->client->followRedirect();
|
||||||
|
|
||||||
$this->isPasswordValid($username, $newPassword);
|
$this->isPasswordValid($username, $newPassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user