PersonControllerViewTest : refactoring (doc, indentation)

This commit is contained in:
Marc Ducobu 2015-08-18 09:32:57 +02:00
parent 91e133aec6
commit fce3de4046

View File

@ -23,47 +23,45 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Person;
/** /**
*
*
* @author Julien Fastré <julien.fastre@champs-libres.coop> * @author Julien Fastré <julien.fastre@champs-libres.coop>
* @author Marc Ducobu <marc.ducobu@champs-libres.coop>
*/ */
class PersonControllerViewTest extends WebTestCase class PersonControllerViewTest extends WebTestCase
{ {
/** @var \Doctrine\ORM\EntityManagerInterface The entity manager */
/**
*
* @var \Doctrine\ORM\EntityManagerInterface
*/
private $em; private $em;
/** /** @var Person A person used on which to run the test */
*
* @var Person
*/
private $person; private $person;
/** @var String The url to view the person details */
private $viewUrl;
public function setUp() public function setUp()
{ {
static::bootKernel(); static::bootKernel();
$this->em = static::$kernel->getContainer() $this->em = static::$kernel->getContainer()
->get('doctrine.orm.entity_manager'); ->get('doctrine.orm.entity_manager');
$center = $this->em->getRepository('ChillMainBundle:Center') $center = $this->em->getRepository('ChillMainBundle:Center')
->findOneBy(array('name' => 'Center A')); ->findOneBy(array('name' => 'Center A'));
$this->person = (new Person()) $this->person = (new Person())
->setLastName("Tested Person") ->setLastName("Tested Person")
->setFirstName("Réginald") ->setFirstName("Réginald")
->setCenter($center) ->setCenter($center)
->setGender(Person::MALE_GENDER); ->setGender(Person::MALE_GENDER);
$this->em->persist($this->person); $this->em->persist($this->person);
$this->em->flush(); $this->em->flush();
$this->seeUrl = '/en/person/'.$this->person->getId().'/general'; $this->viewUrl = '/en/person/'.$this->person->getId().'/general';
} }
/**
* Test if the view page is accessible
*/
public function testViewPerson() public function testViewPerson()
{ {
$client = static::createClient(array(), array( $client = static::createClient(array(), array(
@ -71,11 +69,19 @@ class PersonControllerViewTest extends WebTestCase
'PHP_AUTH_PW' => 'password', 'PHP_AUTH_PW' => 'password',
)); ));
$client->request('GET', $this->seeUrl); $crawler = $client->request('GET', $this->viewUrl);
$response = $client->getResponse();
$this->assertTrue($client->getResponse()->isSuccessful());
$this->assertTrue($response->isSuccessful());
$this->assertGreaterThan(0, $crawler->filter('html:contains("Tested Person")')->count());
$this->assertGreaterThan(0, $crawler->filter('html:contains("Réginald")')->count());
} }
/**
* Test if the view page of a given person is not accessible for a user
* of another center of the person
*/
public function testViewPersonAccessDeniedForUnauthorized() public function testViewPersonAccessDeniedForUnauthorized()
{ {
$client = static::createClient(array(), array( $client = static::createClient(array(), array(
@ -83,15 +89,18 @@ class PersonControllerViewTest extends WebTestCase
'PHP_AUTH_PW' => 'password', 'PHP_AUTH_PW' => 'password',
)); ));
$client->request('GET', $this->seeUrl); $client->request('GET', $this->viewUrl);
$this->assertEquals(403, $client->getResponse()->getStatusCode(),
$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");
} }
/**
* 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')
->find($this->person->getId()); ->find($this->person->getId());
} }
public function tearDown() public function tearDown()