chill-bundles/src/Bundle/ChillPersonBundle/Tests/Controller/PersonControllerViewWithHiddenFieldsTest.php
2021-11-30 11:37:57 +01:00

104 lines
2.9 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.
*/
namespace Chill\PersonBundle\Tests\Controller;
use Chill\PersonBundle\Entity\Person;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
/**
* @internal
* @coversNothing
*/
class PersonControllerViewWithHiddenFieldsTest 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;
public function setUp()
{
static::bootKernel(['environment' => 'test_with_hidden_fields']);
$this->em = static::$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';
}
public function tearDown()
{
$this->refreshPerson();
$this->em->remove($this->person);
$this->em->flush();
}
/**
* Test if the view page is accessible.
*
* @group configurable_fields
*/
public function testViewPerson()
{
$this->markTestSkipped('This configuration does not allow multiple environnements');
$client = static::createClient(
['environment' => 'test_with_hidden_fields'],
[
'PHP_AUTH_USER' => 'center a_social',
'PHP_AUTH_PW' => 'password',
'HTTP_ACCEPT_LANGUAGE' => 'fr',
]
);
$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->assertNotContains('Email addresses', $crawler->text());
$this->assertNotContains('Phonenumber', $crawler->text());
$this->assertNotContains('Langues parlées', $crawler->text());
$this->assertNotContains(/* Etat */ 'civil', $crawler->text());
}
/**
* Reload the person from the db.
*/
protected function refreshPerson()
{
$this->person = $this->em->getRepository('ChillPersonBundle:Person')
->find($this->person->getId());
}
}