mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
120 lines
3.3 KiB
PHP
120 lines
3.3 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Chill is a software for social workers
|
|
*
|
|
* For the full copyright and license information, please view
|
|
* the LICENSE file that was distributed with this source code.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Chill\PersonBundle\Tests\Controller;
|
|
|
|
use Chill\PersonBundle\Entity\Person;
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
|
|
|
/**
|
|
* @internal
|
|
* @coversNothing
|
|
*/
|
|
final class PersonControllerViewTest extends WebTestCase
|
|
{
|
|
/**
|
|
* @var \Doctrine\ORM\EntityManagerInterface The entity manager
|
|
*/
|
|
private $em;
|
|
|
|
/**
|
|
* @var Person A person used on which to run the test
|
|
*/
|
|
private $person;
|
|
|
|
/**
|
|
* @var string The url to view the person details
|
|
*/
|
|
private $viewUrl;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
self::bootKernel();
|
|
|
|
$this->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());
|
|
}
|
|
}
|