mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +00:00
PersonControllerUpdateTest : refactoring (doc + more tests + indentation)
This commit is contained in:
parent
8bc893fe90
commit
91bd7a4529
@ -20,8 +20,6 @@
|
|||||||
|
|
||||||
namespace Chill\PersonBundle\Tests\Controller;
|
namespace Chill\PersonBundle\Tests\Controller;
|
||||||
|
|
||||||
ini_set('memory_limit', '-1');
|
|
||||||
|
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||||
|
|
||||||
@ -34,26 +32,20 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
|||||||
*/
|
*/
|
||||||
class PersonControllerUpdateTest extends WebTestCase
|
class PersonControllerUpdateTest extends WebTestCase
|
||||||
{
|
{
|
||||||
/**
|
/** @var \Doctrine\ORM\EntityManagerInterface The entity manager */
|
||||||
*
|
|
||||||
* @var \Doctrine\ORM\EntityManagerInterface
|
|
||||||
*/
|
|
||||||
private $em;
|
private $em;
|
||||||
|
|
||||||
/**
|
/** @var Person The person on which the test is executed */
|
||||||
*
|
|
||||||
* @var Person
|
|
||||||
*/
|
|
||||||
private $person;
|
private $person;
|
||||||
|
|
||||||
/**
|
/** @var string The url using for editing the person's information */
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $editUrl;
|
private $editUrl;
|
||||||
|
|
||||||
|
/** @var string The url using for seeing the person's information */
|
||||||
|
private $viewUrl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* prepare client and select a random person
|
* Prepare client and create a random person
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
@ -75,7 +67,7 @@ class PersonControllerUpdateTest extends WebTestCase
|
|||||||
$this->em->flush();
|
$this->em->flush();
|
||||||
|
|
||||||
$this->editUrl = '/en/person/'.$this->person->getId().'/general/edit';
|
$this->editUrl = '/en/person/'.$this->person->getId().'/general/edit';
|
||||||
$this->seeUrl = '/en/person/'.$this->person->getId().'/general';
|
$this->viewUrl = '/en/person/'.$this->person->getId().'/general';
|
||||||
|
|
||||||
$this->client = static::createClient(array(), array(
|
$this->client = static::createClient(array(), array(
|
||||||
'PHP_AUTH_USER' => 'center a_social',
|
'PHP_AUTH_USER' => 'center a_social',
|
||||||
@ -83,6 +75,9 @@ class PersonControllerUpdateTest extends WebTestCase
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reload the person from the db
|
||||||
|
*/
|
||||||
protected function refreshPerson()
|
protected function refreshPerson()
|
||||||
{
|
{
|
||||||
$this->person = $this->em->getRepository('ChillPersonBundle:Person')
|
$this->person = $this->em->getRepository('ChillPersonBundle:Person')
|
||||||
@ -90,16 +85,24 @@ class PersonControllerUpdateTest extends WebTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the edit page exist and rendering is successful
|
* Test the view & edit page are accessible
|
||||||
*/
|
*/
|
||||||
public function testEditPageIsSuccessful()
|
public function testEditPageIsSuccessful()
|
||||||
{
|
{
|
||||||
$this->client->request('GET', $this->editUrl);
|
$this->client->request('GET', $this->viewUrl);
|
||||||
|
$this->assertTrue($this->client->getResponse()->isSuccessful(),
|
||||||
|
"The person view form is accessible");
|
||||||
|
|
||||||
|
|
||||||
|
$this->client->request('GET', $this->editUrl);
|
||||||
$this->assertTrue($this->client->getResponse()->isSuccessful(),
|
$this->assertTrue($this->client->getResponse()->isSuccessful(),
|
||||||
"The person edit form is accessible");
|
"The person edit form is accessible");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the view & edit page of a given person are not accessible for a user
|
||||||
|
* of another center of the person
|
||||||
|
*/
|
||||||
public function testEditPageDeniedForUnauthorized_OutsideCenter()
|
public function testEditPageDeniedForUnauthorized_OutsideCenter()
|
||||||
{
|
{
|
||||||
$client = static::createClient(array(), array(
|
$client = static::createClient(array(), array(
|
||||||
@ -107,11 +110,19 @@ class PersonControllerUpdateTest extends WebTestCase
|
|||||||
'PHP_AUTH_PW' => 'password',
|
'PHP_AUTH_PW' => 'password',
|
||||||
));
|
));
|
||||||
|
|
||||||
$client->request('GET', $this->editUrl);
|
$client->request('GET', $this->viewUrl);
|
||||||
|
$this->assertEquals(403, $client->getResponse()->getStatusCode(),
|
||||||
|
"The view page of a person of a center A must not be accessible for user of center B");
|
||||||
|
|
||||||
$this->assertEquals(403, $client->getResponse()->getStatusCode());
|
$client->request('GET', $this->editUrl);
|
||||||
|
$this->assertEquals(403, $client->getResponse()->getStatusCode(),
|
||||||
|
"The edit page of a person of a center A must not be accessible for user of center B");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the edit page of a given person are not accessible for an
|
||||||
|
* administrative user
|
||||||
|
*/
|
||||||
public function testEditPageDeniedForUnauthorized_InsideCenter()
|
public function testEditPageDeniedForUnauthorized_InsideCenter()
|
||||||
{
|
{
|
||||||
$client = static::createClient(array(), array(
|
$client = static::createClient(array(), array(
|
||||||
@ -120,12 +131,11 @@ class PersonControllerUpdateTest extends WebTestCase
|
|||||||
));
|
));
|
||||||
|
|
||||||
$client->request('GET', $this->editUrl);
|
$client->request('GET', $this->editUrl);
|
||||||
|
|
||||||
$this->assertEquals(403, $client->getResponse()->getStatusCode());
|
$this->assertEquals(403, $client->getResponse()->getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test the edition of a field
|
* Test the edition of a field
|
||||||
*
|
*
|
||||||
* Given I fill the field with $value
|
* Given I fill the field with $value
|
||||||
* And I submit the form
|
* And I submit the form
|
||||||
@ -165,10 +175,20 @@ class PersonControllerUpdateTest extends WebTestCase
|
|||||||
$this->client->submit($form);
|
$this->client->submit($form);
|
||||||
$this->refreshPerson();
|
$this->refreshPerson();
|
||||||
|
|
||||||
$this->assertTrue($this->client->getResponse()->isRedirect($this->seeUrl),
|
$this->assertTrue($this->client->getResponse()->isRedirect($this->viewUrl),
|
||||||
'the page is redirected to general view');
|
'the page is redirected to general view');
|
||||||
$this->assertEquals($value, $callback($this->person),
|
$this->assertEquals($value, $callback($this->person),
|
||||||
'the value '.$field.' is updated in db');
|
'the value '.$field.' is updated in db');
|
||||||
|
|
||||||
|
$crawler = $this->client->followRedirect();
|
||||||
|
$this->assertGreaterThan(0, $crawler->filter('.success')->count(),
|
||||||
|
'a element .success is shown');
|
||||||
|
|
||||||
|
if($field == 'birthdate' or $field == 'memo' or $field == 'countryOfBirth' or $field == 'nationality') {
|
||||||
|
$this->markTestIncomplete('Test html:contains("'.$value.'") was not performed');
|
||||||
|
} else {
|
||||||
|
$this->assertGreaterThan(0, $crawler->filter('html:contains("'.$value.'")')->count());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testEditLanguages()
|
public function testEditLanguages()
|
||||||
@ -184,7 +204,7 @@ class PersonControllerUpdateTest extends WebTestCase
|
|||||||
$this->client->submit($form);
|
$this->client->submit($form);
|
||||||
$this->refreshPerson();
|
$this->refreshPerson();
|
||||||
|
|
||||||
$this->assertTrue($this->client->getResponse()->isRedirect($this->seeUrl),
|
$this->assertTrue($this->client->getResponse()->isRedirect($this->viewUrl),
|
||||||
'the page is redirected to /general view');
|
'the page is redirected to /general view');
|
||||||
//retrieve languages codes present in person
|
//retrieve languages codes present in person
|
||||||
foreach($this->person->getSpokenLanguages() as $lang){
|
foreach($this->person->getSpokenLanguages() as $lang){
|
||||||
@ -192,11 +212,11 @@ class PersonControllerUpdateTest extends WebTestCase
|
|||||||
}
|
}
|
||||||
$this->assertEquals(asort($selectedLanguages), asort($languagesCodesPresents),
|
$this->assertEquals(asort($selectedLanguages), asort($languagesCodesPresents),
|
||||||
'the person speaks the expected languages');
|
'the person speaks the expected languages');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Test tbe detection of invalid data during the update procedure
|
||||||
*
|
*
|
||||||
* @dataProvider providesInvalidFieldsValues
|
* @dataProvider providesInvalidFieldsValues
|
||||||
* @param string $field
|
* @param string $field
|
||||||
|
Loading…
x
Reference in New Issue
Block a user