Merge branch 'features/date-type-use-html5' into features/activity-form

This commit is contained in:
Julien Fastré 2021-06-08 22:01:19 +02:00
commit 79ec182ca3

View File

@ -3,17 +3,17 @@
/* /*
* Chill is a suite of a modules, Chill is a software for social workers * Chill is a suite of a modules, Chill is a software for social workers
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop> * Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the * published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version. * License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@ -27,7 +27,7 @@ use Chill\MainBundle\Test\PrepareClientTrait;
/** /**
* Test the edition of persons * Test the edition of persons
* *
* As I am logged in as "center a_social" * As I am logged in as "center a_social"
* *
*/ */
@ -37,66 +37,66 @@ class PersonControllerUpdateTest extends WebTestCase
/** @var \Doctrine\ORM\EntityManagerInterface The entity manager */ /** @var \Doctrine\ORM\EntityManagerInterface The entity manager */
private $em; private $em;
/** @var Person The person on which the test is executed */ /** @var Person The person on which the test is executed */
private $person; private $person;
/** @var string The url using for editing the person's information */ /** @var string The url using for editing the person's information */
private $editUrl; private $editUrl;
/** @var string The url using for seeing the person's information */ /** @var string The url using for seeing the person's information */
private $viewUrl; private $viewUrl;
/** /**
* Prepare client and create a random person * Prepare client and create a random person
*/ */
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("My Beloved") ->setLastName("My Beloved")
->setFirstName("Jesus") ->setFirstName("Jesus")
->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->editUrl = '/fr/person/'.$this->person->getId().'/general/edit'; $this->editUrl = '/fr/person/'.$this->person->getId().'/general/edit';
$this->viewUrl = '/fr/person/'.$this->person->getId().'/general'; $this->viewUrl = '/fr/person/'.$this->person->getId().'/general';
$this->client = $this->getClientAuthenticated(); $this->client = $this->getClientAuthenticated();
} }
/** /**
* Reload the person from the db * 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());
} }
/** /**
* Test the edit page are accessible * Test the edit page are accessible
*/ */
public function testEditPageIsSuccessful() public function testEditPageIsSuccessful()
{ {
$this->client->request('GET', $this->editUrl); $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 configurable fields are present * Test the configurable fields are present
* *
* @group configurable_fields * @group configurable_fields
*/ */
public function testHiddenFielsArePresent() public function testHiddenFielsArePresent()
@ -106,12 +106,12 @@ class PersonControllerUpdateTest extends WebTestCase
$configurables = array('placeOfBirth', 'phonenumber', 'email', $configurables = array('placeOfBirth', 'phonenumber', 'email',
'countryOfBirth', 'nationality', 'spokenLanguages', 'maritalStatus'); 'countryOfBirth', 'nationality', 'spokenLanguages', 'maritalStatus');
$form = $crawler->selectButton('Enregistrer')->form(); //; $form = $crawler->selectButton('Enregistrer')->form(); //;
foreach($configurables as $key) { foreach($configurables as $key) {
$this->assertTrue($form->has('chill_personbundle_person['.$key.']')); $this->assertTrue($form->has('chill_personbundle_person['.$key.']'));
} }
} }
/** /**
* Test if the edit page of a given person is not accessible for a user * Test if the edit page of a given person is not accessible for a user
* of another center of the person * of another center of the person
@ -122,12 +122,12 @@ class PersonControllerUpdateTest extends WebTestCase
'PHP_AUTH_USER' => 'center b_social', 'PHP_AUTH_USER' => 'center b_social',
'PHP_AUTH_PW' => 'password', 'PHP_AUTH_PW' => 'password',
)); ));
$client->request('GET', $this->editUrl); $client->request('GET', $this->editUrl);
$this->assertEquals(403, $client->getResponse()->getStatusCode(), $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"); "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 * Test the edit page of a given person are not accessible for an
* administrative user * administrative user
@ -138,19 +138,19 @@ class PersonControllerUpdateTest extends WebTestCase
'PHP_AUTH_USER' => 'center a_administrative', 'PHP_AUTH_USER' => 'center a_administrative',
'PHP_AUTH_PW' => 'password', 'PHP_AUTH_PW' => 'password',
)); ));
$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
* Then I am redirected to the 'general' page * Then I am redirected to the 'general' page
* And the person is updated in the db * And the person is updated in the db
* *
* @dataProvider validTextFieldsProvider * @dataProvider validTextFieldsProvider
* @param string $field * @param string $field
* @param string $value * @param string $value
@ -159,7 +159,7 @@ class PersonControllerUpdateTest extends WebTestCase
public function testEditTextField($field, $value, \Closure $callback) public function testEditTextField($field, $value, \Closure $callback)
{ {
$crawler = $this->client->request('GET', $this->editUrl); $crawler = $this->client->request('GET', $this->editUrl);
$form = $crawler->selectButton('Enregistrer') $form = $crawler->selectButton('Enregistrer')
->form(); ->form();
//transform countries into value if needed //transform countries into value if needed
@ -177,13 +177,13 @@ class PersonControllerUpdateTest extends WebTestCase
default: default:
$transformedValue = $value; $transformedValue = $value;
} }
$form->get('chill_personbundle_person['.$field. ']') $form->get('chill_personbundle_person['.$field. ']')
->setValue($transformedValue); ->setValue($transformedValue);
$this->client->submit($form); $this->client->submit($form);
$this->refreshPerson(); $this->refreshPerson();
$this->assertTrue($this->client->getResponse()->isRedirect($this->viewUrl), $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),
@ -200,20 +200,20 @@ class PersonControllerUpdateTest extends WebTestCase
$this->assertGreaterThan(0, $crawler->filter('html:contains("'.$value.'")')->count()); $this->assertGreaterThan(0, $crawler->filter('html:contains("'.$value.'")')->count());
} }
} }
public function testEditLanguages() public function testEditLanguages()
{ {
$crawler = $this->client->request('GET', $this->editUrl); $crawler = $this->client->request('GET', $this->editUrl);
$selectedLanguages = array('en', 'an', 'bbj'); $selectedLanguages = array('en', 'an', 'bbj');
$form = $crawler->selectButton('Enregistrer') $form = $crawler->selectButton('Enregistrer')
->form(); ->form();
$form->get('chill_personbundle_person[spokenLanguages]') $form->get('chill_personbundle_person[spokenLanguages]')
->setValue($selectedLanguages); ->setValue($selectedLanguages);
$this->client->submit($form); $this->client->submit($form);
$this->refreshPerson(); $this->refreshPerson();
$this->assertTrue($this->client->getResponse()->isRedirect($this->viewUrl), $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
@ -223,10 +223,10 @@ 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 * Test tbe detection of invalid data during the update procedure
* *
* @dataProvider providesInvalidFieldsValues * @dataProvider providesInvalidFieldsValues
* @param string $field * @param string $field
@ -235,33 +235,33 @@ class PersonControllerUpdateTest extends WebTestCase
public function testInvalidFields($field, $value) public function testInvalidFields($field, $value)
{ {
$crawler = $this->client->request('GET', $this->editUrl); $crawler = $this->client->request('GET', $this->editUrl);
$form = $crawler->selectButton('Enregistrer') $form = $crawler->selectButton('Enregistrer')
->form(); ->form();
$form->get('chill_personbundle_person['.$field.']') $form->get('chill_personbundle_person['.$field.']')
->setValue($value); ->setValue($value);
$crawler = $this->client->submit($form); $crawler = $this->client->submit($form);
$this->assertFalse($this->client->getResponse()->isRedirect(), $this->assertFalse($this->client->getResponse()->isRedirect(),
'the page is not redirected to /general'); 'the page is not redirected to /general');
$this->assertGreaterThan(0, $crawler->filter('.error')->count(), $this->assertGreaterThan(0, $crawler->filter('.error')->count(),
'a element .error is shown'); 'a element .error is shown');
} }
/** /**
* provide valid values to test, with field name and * provide valid values to test, with field name and
* a function to find the value back from person entity * a function to find the value back from person entity
* *
* @return mixed[] * @return mixed[]
*/ */
public function validTextFieldsProvider() public function validTextFieldsProvider()
{ {
return array( return array(
['firstName', 'random Value', function(Person $person) { return $person->getFirstName(); } ], ['firstName', 'random Value', function(Person $person) { return $person->getFirstName(); } ],
['lastName' , 'random Value', function(Person $person) { return $person->getLastName(); } ], ['lastName' , 'random Value', function(Person $person) { return $person->getLastName(); } ],
['placeOfBirth', 'none place', function(Person $person) { return $person->getPlaceOfBirth(); }], ['placeOfBirth', 'none place', function(Person $person) { return $person->getPlaceOfBirth(); }],
['birthdate', '1980-12-15', function(Person $person) { return $person->getBirthdate()->format('d-m-Y'); }], ['birthdate', '1980-12-15', function(Person $person) { return $person->getBirthdate()->format('Y-m-d'); }],
['phonenumber', '+32123456789', function(Person $person) { return $person->getPhonenumber(); }], ['phonenumber', '+32123456789', function(Person $person) { return $person->getPhonenumber(); }],
['memo', 'jfkdlmq jkfldmsq jkmfdsq', function(Person $person) { return $person->getMemo(); }], ['memo', 'jfkdlmq jkfldmsq jkmfdsq', function(Person $person) { return $person->getMemo(); }],
['countryOfBirth', 'BE', function(Person $person) { return $person->getCountryOfBirth()->getCountryCode(); }], ['countryOfBirth', 'BE', function(Person $person) { return $person->getCountryOfBirth()->getCountryCode(); }],
@ -275,7 +275,7 @@ class PersonControllerUpdateTest extends WebTestCase
['gender', Person::FEMALE_GENDER, function(Person $person) { return $person->getGender(); }], ['gender', Person::FEMALE_GENDER, function(Person $person) { return $person->getGender(); }],
); );
} }
public function providesInvalidFieldsValues() public function providesInvalidFieldsValues()
{ {
return array( return array(
@ -286,18 +286,18 @@ class PersonControllerUpdateTest extends WebTestCase
['birthdate', 'false date'] ['birthdate', 'false date']
); );
} }
public function tearDown() public function tearDown()
{ {
$this->refreshPerson(); $this->refreshPerson();
$this->em->remove($this->person); $this->em->remove($this->person);
$this->em->flush(); $this->em->flush();
} }
private function getVeryLongText() private function getVeryLongText()
{ {
return <<<EOT return <<<EOT
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse molestie at enim id auctor. Vivamus malesuada elit ipsum, ac mollis ex facilisis sit amet. Phasellus accumsan, quam ut aliquet accumsan, augue ligula consequat erat, condimentum iaculis orci magna egestas eros. In vel blandit sapien. Duis ut dui vitae tortor iaculis malesuada vitae vitae lorem. Morbi efficitur dolor orci, a rhoncus urna blandit quis. Aenean at placerat dui, ut tincidunt nulla. In ultricies tempus ligula ac rutrum. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Fusce urna nibh, placerat vel auctor sed, maximus quis magna. Vivamus quam ante, consectetur vel feugiat quis, aliquet id ante. Integer gravida erat dignissim ante commodo mollis. Donec imperdiet mauris elit, nec blandit dolor feugiat ut. Proin iaculis enim ut tortor pretium commodo. Etiam aliquet hendrerit dolor sed fringilla. Vestibulum facilisis nibh tincidunt dui egestas, vitae congue mi imperdiet. Duis vulputate ultricies lectus id cursus. Fusce bibendum sem dignissim, bibendum purus quis, mollis ex. Cras ac est justo. Duis congue mattis ipsum, vitae sagittis justo dictum sit amet. Duis aliquam pharetra sem, non laoreet ante laoreet ac. Mauris ornare mi tempus rutrum consequat. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse molestie at enim id auctor. Vivamus malesuada elit ipsum, ac mollis ex facilisis sit amet. Phasellus accumsan, quam ut aliquet accumsan, augue ligula consequat erat, condimentum iaculis orci magna egestas eros. In vel blandit sapien. Duis ut dui vitae tortor iaculis malesuada vitae vitae lorem. Morbi efficitur dolor orci, a rhoncus urna blandit quis. Aenean at placerat dui, ut tincidunt nulla. In ultricies tempus ligula ac rutrum. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Fusce urna nibh, placerat vel auctor sed, maximus quis magna. Vivamus quam ante, consectetur vel feugiat quis, aliquet id ante. Integer gravida erat dignissim ante commodo mollis. Donec imperdiet mauris elit, nec blandit dolor feugiat ut. Proin iaculis enim ut tortor pretium commodo. Etiam aliquet hendrerit dolor sed fringilla. Vestibulum facilisis nibh tincidunt dui egestas, vitae congue mi imperdiet. Duis vulputate ultricies lectus id cursus. Fusce bibendum sem dignissim, bibendum purus quis, mollis ex. Cras ac est justo. Duis congue mattis ipsum, vitae sagittis justo dictum sit amet. Duis aliquam pharetra sem, non laoreet ante laoreet ac. Mauris ornare mi tempus rutrum consequat.
EOT; EOT;
} }
} }