em = self::$kernel->getContainer() ->get('doctrine.orm.entity_manager'); $center = $this->em->getRepository('ChillMainBundle:Center') ->findOneBy(['name' => 'Center A']); $this->person = (new Person()) ->setLastName('Tested Person') ->setFirstName('Réginald') ->setCenter($center) ->setGender(Person::MALE_GENDER); $this->em->persist($this->person); $this->em->flush(); $this->viewUrl = '/en/person/' . $this->person->getId() . '/general'; } protected function tearDown(): void { $this->refreshPerson(); $this->em->remove($this->person); $this->em->flush(); } /** * Test if the view page is accessible. * * @group configurable_fields */ public function testViewPerson() { $client = self::createClient([], [ 'PHP_AUTH_USER' => 'center a_social', 'PHP_AUTH_PW' => 'password', ]); $crawler = $client->request('GET', $this->viewUrl); $response = $client->getResponse(); $this->assertTrue($response->isSuccessful()); $this->assertGreaterThan(0, $crawler->filter('html:contains("TESTED PERSON")')->count()); $this->assertGreaterThan(0, $crawler->filter('html:contains("Réginald")')->count()); $this->assertStringContainsString('Email addresses', $crawler->text()); $this->assertStringContainsString('Phonenumber', $crawler->text()); $this->assertStringContainsString('Langues parlées', $crawler->text()); $this->assertStringContainsString(/* Etat */ 'civil', $crawler->text()); } /** * Test if the view page of a given person is not accessible for a user * of another center of the person. */ public function testViewPersonAccessDeniedForUnauthorized() { $client = self::createClient([], [ 'PHP_AUTH_USER' => 'center b_social', 'PHP_AUTH_PW' => 'password', ]); $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' ); } /** * Reload the person from the db. */ protected function refreshPerson() { $this->person = $this->em->getRepository('ChillPersonBundle:Person') ->find($this->person->getId()); } }