From 5992977a3e53684e819bb56ce8cd71eabe7a4cff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 27 Jan 2015 22:17:39 +0100 Subject: [PATCH 01/12] test person's edit form update the controller to get the validation --- Controller/PersonController.php | 5 +- Resources/translations/messages.en.yml | 80 ++++++++++ Tests/Controller/PersonUpdateTest.php | 205 +++++++++++++++++++++++++ 3 files changed, 289 insertions(+), 1 deletion(-) create mode 100644 Resources/translations/messages.en.yml create mode 100644 Tests/Controller/PersonUpdateTest.php diff --git a/Controller/PersonController.php b/Controller/PersonController.php index a0c0152f2..e536119d0 100644 --- a/Controller/PersonController.php +++ b/Controller/PersonController.php @@ -92,7 +92,10 @@ class PersonController extends Controller if ($request->getMethod() === 'POST') { $form->handleRequest($request); - if ( ! $form->isValid() ) { + $errors = $this->get('validator') + ->validate($person, array('general')); + + if ( count($errors) > 0 ) { $errors = $form->getErrorsAsString(); diff --git a/Resources/translations/messages.en.yml b/Resources/translations/messages.en.yml new file mode 100644 index 000000000..2a13e4c4e --- /dev/null +++ b/Resources/translations/messages.en.yml @@ -0,0 +1,80 @@ +Edit: Edit +'First name': First name +'Last name': Last name +Name: Name +'Date of birth': Date of birth +'Unknown date of birth': 'Date de naissance inconnue' +Nationality: Nationality +'Without nationality': 'Sans nationalité' +Gender: Gender +'Creation date': 'Date d''ouverture' +'Not given': 'Non renseigné' +'Place of birth': 'Place of birth' +'Country of birth': 'Country of birth' +'Unknown country of birth': 'Pays inconnu' +'Marital status': 'État civil' +'Number of children': 'Nombre d''enfants' +'{0} No child|{1} One child | ]1,Inf] %nb% children': '{0} Aucun enfant|{1} Un enfant | ]1,Inf] %nb% enfants' +'National number': 'Numéro national' +Email: 'Email addresses' +Address: Adresse +Memo: Memo +Phonenumber: 'Phonenumber7' +'{0} Born the %date% | {1} Born the %date%': '{0} Né le %date% | {1} Née le %date%' +'Spoken languages': 'Langues parlées' +'Unknown spoken languages': 'Langues parlées inconnues' +Male: Homme +Female: Femme +man: Homme +woman: Femme +Divorced: Divorcé(e) +Separated: Séparé(e) +Widow: Veuf(ve) +'Unknow marital status': Indéterminé +'Legal cohabitant': 'Cohabitant légal' +Single: Célibataire +Married: Marié(e) +'General information': Généralités +'Birth information': Naissance +'Family information': Famille +'Contact information': 'Informations de contact' +'Administrative information': Administratif +'Alreay existing person': 'Dossiers déjà encodés' +'Add the person': 'Ajouter la personne' +'Confirm the creation': 'Confirmer la création' +'You will create this person': 'Vous allez créer le dossier suivant' +Return: Retour +Submit: Submit +Reset: 'Remise à zéro' +'The person data has been updated': 'Bravo ! Les données ont été mises à jour.' +'{1} The person field %field% is incorrect. Please check. | ]1, Inf] Several person fields are incorrect. Please check.': '{1} Le champs %field% est incorrect. Veuillez le corriger. | ]1, Inf] Plusieurs champs sont incorrects. Veuillez les vérifier.' +'Add a person': 'Ajout d''une personne' +'Person Menu': 'Menu personne' +'The person data are not valid': 'Les données de votre formulaire sont invalides.' +'%nb% person with similar name. Please verify that this is a new person': '%nb% personnes ont un nom similaire. Vérifiez qu''il ne s''agit pas de l''une d''elles.' +'The person has been created': 'Le dossier a été créé' +'Person search results': 'Recherche de personnes' +'Search within persons': 'Recherche parmi les personnes' +'%total% persons matching the search %pattern%': '{0} Aucune personne ne correspond aux termes de recherche "%pattern%" | {1} Une personne a été trouvée par la recherche "%pattern%" | ]1,Inf] %total% personnes correspondent aux termes de recherche "%pattern%".' +'Last opening since %last_opening%': 'Dernière ouverture le %last_opening%.' +'Close person history': Clotûrer +'Person history - %name%': 'Historique du dossier - %name%' +'Opening date': 'Date d''ouverture' +'Closing date': 'Date de fermeture' +'Still open': 'Toujours en cours' +'Close history': 'Clôre le dossier' +'Open history': 'Ouvrir le dossier' +'Create history': 'Nouvel ouverture-fermeture à une autre date' +'Closing motive': 'Motif de clôture' +'History created!': 'Bravo ! Le dossier est maintenant ouvert.' +'Error! History not created!': 'Erreur ! Le dossier n''a pas pu être ouvert.' +'Updating history done': 'Bravo ! La mise à jour de l''historique a réussi !' +'Error when updating history': 'Les données introduites ne sont pas valides. Veuillez vérifier les informations ci-dessous.' +'Beware history is closed': 'Attention le dossier est déjà fermé' +'History closed!': 'Bravo ! Le dossier de %name% a été clotûré.' +'Error! History not closed!': 'Les informations introduites ne sont pas valides. Le dossier n''a pu être clos.' +'History closing form is not valide': 'Le formulaire n''est pas valide.' +'Error! History %name% is not closed ; it can be open': 'Le dossier de %name% n''est pas fermé. Il ne peut donc être ouvert.' +'History %name% opened!': 'Bravo ! Le dossier de %name a été ouvert' +'History not opened': 'Les informations introduites ne sont pas valides. Le dossier n''a pu être ouvert.' +'Person details': 'Détails de la personne' diff --git a/Tests/Controller/PersonUpdateTest.php b/Tests/Controller/PersonUpdateTest.php new file mode 100644 index 000000000..ec0228a6d --- /dev/null +++ b/Tests/Controller/PersonUpdateTest.php @@ -0,0 +1,205 @@ + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Chill\PersonBundle\Tests\Controller; + +use Chill\PersonBundle\Entity\Person; +use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; + +/** + * Test the edition of persons + * + * As I am logged in as "center a_social" + * + * @author Julien Fastré + */ +class PersonUpdateTest extends WebTestCase +{ + /** + * + * @var \Doctrine\ORM\EntityManagerInterface + */ + private $em; + + /** + * + * @var Person + */ + private $person; + + /** + * + * @var string + */ + private $editUrl; + + /** + * prepare client and select a random person + */ + public function setUp() + { + static::bootKernel(); + + $this->person = (new Person()) + ->setLastName("My Beloved") + ->setFirstName("Jesus") + ->setGenre(Person::GENRE_MAN); + + $this->em = static::$kernel->getContainer()->get('doctrine.orm.entity_manager'); + + $this->em->persist($this->person); + $this->em->flush(); + + $this->editUrl = '/en/person/'.$this->person->getId().'/general/edit'; + $this->seeUrl = '/en/person/'.$this->person->getId().'/general'; + + $this->client = static::createClient(array(), array( + 'PHP_AUTH_USER' => 'center a_social', + 'PHP_AUTH_PW' => 'password', + )); + } + + /** + * Test the edit page exist and rendering is successful + */ + public function testEditPageIsSuccessful() + { + $this->client->request('GET', $this->editUrl); + + $this->assertTrue($this->client->getResponse()->isSuccessful(), + "The person edit form is accessible"); + } + + /** + * test the edition of a field + * + * Given I fill the field with $value + * And I submit the form + * Then I am redirected to the 'general' page + * And the person is updated in the db + * + * @dataProvider validTextFieldsProvider + * @param string $field + * @param string $value + * @param \Closure $callback + */ + public function testEditTextField($field, $value, \Closure $callback) + { + $crawler = $this->client->request('GET', $this->editUrl); + + $form = $crawler->selectButton('Submit') + ->form(); + //transform countries into value if needed + switch ($field) { + case 'nationality': + case 'countryOfBirth': + if ($value !== NULL) { + $country = $this->em->getRepository('ChillMainBundle:Country') + ->findOneByCountryCode($value); + $transformedValue = $country->getId(); + } else { + $transformedValue = NULL; + } + break; + default: + $transformedValue = $value; + } + + $form->get('chill_personbundle_person['.$field. ']') + ->setValue($transformedValue); + + $this->client->submit($form); + $this->em->refresh($this->person); + + $this->assertTrue($this->client->getResponse()->isRedirect($this->seeUrl)); + $this->assertEquals($value, $callback($this->person)); + } + + /** + * provide valid values to test, with field name and + * a function to find the value back from person entity + * + * @return mixed[] + */ + public function validTextFieldsProvider() + { + return array( + ['firstName', 'random Value', function(Person $person) { return $person->getFirstName(); } ], + ['lastName' , 'random Value', function(Person $person) { return $person->getLastName(); } ], + ['placeOfBirth', 'none place', function(Person $person) { return $person->getPlaceOfBirth(); }], + ['dateOfBirth', '15-12-1980', function(Person $person) { return $person->getDateOfBirth()->format('d-m-Y'); }], + ['phonenumber', '0123456789', function(Person $person) { return $person->getPhonenumber(); }], + ['memo', 'jfkdlmq jkfldmsq jkmfdsq', function(Person $person) { return $person->getMemo(); }], + ['countryOfBirth', 'BE', function(Person $person) { return $person->getCountryOfBirth()->getCountryCode(); }], + ['nationality', 'FR', function(Person $person) { return $person->getNationality()->getCountryCode(); }], + ['placeOfBirth', '', function(Person $person) { return $person->getPlaceOfBirth(); }], + ['dateOfBirth', '', function(Person $person) { return $person->getDateOfBirth(); }], + ['phonenumber', '', function(Person $person) { return $person->getPhonenumber(); }], + ['memo', '', function(Person $person) { return $person->getMemo(); }], + ['countryOfBirth', NULL, function(Person $person) { return $person->getCountryOfBirth(); }], + ['nationality', NULL, function(Person $person) { return $person->getNationality(); }], + ['genre', Person::GENRE_WOMAN, function(Person $person) { return $person->getGenre(); }] + ); + } + + /** + * + * @dataProvider providesInvalidFieldsValues + * @param string $field + * @param string $value + */ + public function testInvalidFields($field, $value) + { + $crawler = $this->client->request('GET', $this->editUrl); + + $form = $crawler->selectButton('Submit') + ->form(); + $form->get('chill_personbundle_person['.$field.']') + ->setValue($value); + + $crawler = $this->client->submit($form); + + $this->assertFalse($this->client->getResponse()->isRedirect()); + $this->assertGreaterThan(0, $crawler->filter('.error')->count()); + } + + public function providesInvalidFieldsValues() + { + return array( + ['firstName', $this->getVeryLongText()], + ['lastName', $this->getVeryLongText()], + ['firstName', ''], + ['lastName', ''] + ); + } + + public function tearDown() + { + $this->em->remove($this->person); + $this->em->flush(); + } + + private function getVeryLongText() + { + return << Date: Wed, 28 Jan 2015 20:52:56 +0100 Subject: [PATCH 02/12] fix config to test app --- Tests/Fixtures/App/app/config/config.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Tests/Fixtures/App/app/config/config.yml b/Tests/Fixtures/App/app/config/config.yml index 219c7e736..af235e684 100644 --- a/Tests/Fixtures/App/app/config/config.yml +++ b/Tests/Fixtures/App/app/config/config.yml @@ -35,6 +35,9 @@ doctrine: auto_generate_proxy_classes: "%kernel.debug%" auto_mapping: true +chill_main: + available_languages: [ fr, nl, en ] + security: providers: users: From 5bd4e9ff1a4b4f5a4ffd95627a0932b347037c1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 29 Jan 2015 16:41:23 +0100 Subject: [PATCH 03/12] add composer bundle migration --- composer.json | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2fb4fd28d..501fab8a0 100644 --- a/composer.json +++ b/composer.json @@ -29,10 +29,22 @@ "doctrine/doctrine-bundle": "~1.2", "chill-project/main": "*@dev", "chill-project/custom-fields": "*@dev", - "doctrine/doctrine-fixtures-bundle": "~2.2" + "doctrine/doctrine-fixtures-bundle": "~2.2", + "champs-libres/composer-bundle-migration": "~1.0" }, "require-dev": { "symfony/dom-crawler": "2.5", "symfony/security": "~2.5" + }, + "scripts": { + "post-install-cmd": [ + "ComposerBundleMigration\\Composer\\Migrations::synchronizeMigrations" + ], + "post-update-cmd": [ + "ComposerBundleMigration\\Composer\\Migrations::synchronizeMigrations" + ] + }, + "extra": { + "app-migrations-dir": "Tests/Fixtures/App/app/DoctrineMigrations" } } From d6822520d2e5b82c719974b82c3dda81750a1d8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 29 Jan 2015 16:54:25 +0100 Subject: [PATCH 04/12] add doctrine migration to CI from person bundle refs #402 --- .travis.yml | 4 ++-- Tests/Fixtures/App/app/AppKernel.php | 3 ++- Tests/Fixtures/App/app/DoctrineMigrations/.gitignore | 2 ++ composer.json | 4 +++- 4 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 Tests/Fixtures/App/app/DoctrineMigrations/.gitignore diff --git a/.travis.yml b/.travis.yml index 73ae082a7..0228fd3f7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,7 @@ addons: postgresql: "9.3" install: - - composer install --dev + - composer install --dev --no-interaction - cp Tests/Fixtures/App/app/config/parameters.travis.yml Tests/Fixtures/App/app/config/parameters.yml before_script: @@ -22,7 +22,7 @@ before_script: - psql -d test0 -c 'CREATE EXTENSION unaccent;' -U postgres - php Tests/Fixtures/App/app/console.php --env=test cache:warmup - php Tests/Fixtures/App/app/console.php assets:install Tests/Fixtures/App/web - - php Tests/Fixtures/App/app/console.php doctrine:schema:create --env=test --no-interaction + - php Tests/Fixtures/App/app/console.php doctrine:migrations:migrate --no-interaction - php Tests/Fixtures/App/app/console.php doctrine:fixtures:load --env=test --no-interaction script: phpunit --coverage-text diff --git a/Tests/Fixtures/App/app/AppKernel.php b/Tests/Fixtures/App/app/AppKernel.php index 9880d4828..23b95d3fa 100644 --- a/Tests/Fixtures/App/app/AppKernel.php +++ b/Tests/Fixtures/App/app/AppKernel.php @@ -16,7 +16,8 @@ class AppKernel extends Kernel new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), new Chill\PersonBundle\ChillPersonBundle(), new Chill\MainBundle\ChillMainBundle(), - new \Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle, + new \Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(), + new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle() #add here all the required bundle (some bundle are not required) ); } diff --git a/Tests/Fixtures/App/app/DoctrineMigrations/.gitignore b/Tests/Fixtures/App/app/DoctrineMigrations/.gitignore new file mode 100644 index 000000000..d6b7ef32c --- /dev/null +++ b/Tests/Fixtures/App/app/DoctrineMigrations/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/composer.json b/composer.json index 501fab8a0..8210fcd75 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,9 @@ "chill-project/main": "*@dev", "chill-project/custom-fields": "*@dev", "doctrine/doctrine-fixtures-bundle": "~2.2", - "champs-libres/composer-bundle-migration": "~1.0" + "champs-libres/composer-bundle-migration": "~1.0", + "doctrine/doctrine-migrations-bundle": "dev-master@dev", + "doctrine/migrations": "~1.0@dev" }, "require-dev": { "symfony/dom-crawler": "2.5", From bf1eb5187331dfdc268a2e22751ebd5f41110c39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 29 Jan 2015 18:35:57 +0100 Subject: [PATCH 05/12] add composer auth to travis this should remove 'could not download package from source' message --- .travis.yml | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0228fd3f7..06751b78a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,20 +3,16 @@ php: - 5.5 - 5.6 - hhvm-nightly - matrix: allow_failures: - - php: hhvm-nightly - + - php: hhvm-nightly sudo: false - addons: - postgresql: "9.3" - -install: - - composer install --dev --no-interaction - - cp Tests/Fixtures/App/app/config/parameters.travis.yml Tests/Fixtures/App/app/config/parameters.yml - + postgresql: '9.3' +install: + - composer config -g github-oauth.github.com $GITHUB_COMPOSER_AUTH + - composer install --dev --no-interaction + - cp Tests/Fixtures/App/app/config/parameters.travis.yml Tests/Fixtures/App/app/config/parameters.yml before_script: - psql -c 'create database test0;' -U postgres - psql -d test0 -c 'CREATE EXTENSION unaccent;' -U postgres @@ -24,9 +20,10 @@ before_script: - php Tests/Fixtures/App/app/console.php assets:install Tests/Fixtures/App/web - php Tests/Fixtures/App/app/console.php doctrine:migrations:migrate --no-interaction - php Tests/Fixtures/App/app/console.php doctrine:fixtures:load --env=test --no-interaction - script: phpunit --coverage-text - notifications: email: - - info@champs-libres.coop + - info@champs-libres.coop +env: + global: + secure: cTLFyo5WBqz9r+cfvYB9JozISdiXWBQ/feLmQQjOEjj+CiQteKYGh7oQkePyJJRdi95JO9jyXG8yiKGcEcVNLgwShLkwKno3iyiWOIDVl0mPmFUKbQPd9P3UVWpCiL3oH1JVTFd7uz6Mq+eUMrETeLa/3sxoxlnmre8ESqDIIEo= From 0a1ff9e1414c6141f0ce046b2ef39686ba017dc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 29 Jan 2015 18:42:42 +0100 Subject: [PATCH 06/12] complete tests for person edition close #405 add a test on false date, but this made the validation fail. --- ...rTest.php => PersonControllerCreateTest.php} | 2 +- ...eTest.php => PersonControllerUpdateTest.php} | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) rename Tests/Controller/{PersonControllerTest.php => PersonControllerCreateTest.php} (99%) rename Tests/Controller/{PersonUpdateTest.php => PersonControllerUpdateTest.php} (94%) diff --git a/Tests/Controller/PersonControllerTest.php b/Tests/Controller/PersonControllerCreateTest.php similarity index 99% rename from Tests/Controller/PersonControllerTest.php rename to Tests/Controller/PersonControllerCreateTest.php index 8c0f91072..cbc6444e6 100644 --- a/Tests/Controller/PersonControllerTest.php +++ b/Tests/Controller/PersonControllerCreateTest.php @@ -9,7 +9,7 @@ use Symfony\Component\HttpFoundation\RedirectResponse; /** * Test creation and deletion for persons */ -class PersonControllerTest extends WebTestCase +class PersonControllerCreateTest extends WebTestCase { const FIRSTNAME_INPUT = 'chill_personbundle_person_creation[firstName]'; diff --git a/Tests/Controller/PersonUpdateTest.php b/Tests/Controller/PersonControllerUpdateTest.php similarity index 94% rename from Tests/Controller/PersonUpdateTest.php rename to Tests/Controller/PersonControllerUpdateTest.php index ec0228a6d..20b423151 100644 --- a/Tests/Controller/PersonUpdateTest.php +++ b/Tests/Controller/PersonControllerUpdateTest.php @@ -30,7 +30,7 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; * * @author Julien Fastré */ -class PersonUpdateTest extends WebTestCase +class PersonControllerUpdateTest extends WebTestCase { /** * @@ -128,8 +128,10 @@ class PersonUpdateTest extends WebTestCase $this->client->submit($form); $this->em->refresh($this->person); - $this->assertTrue($this->client->getResponse()->isRedirect($this->seeUrl)); - $this->assertEquals($value, $callback($this->person)); + $this->assertTrue($this->client->getResponse()->isRedirect($this->seeUrl), + 'the page is redirected to general view'); + $this->assertEquals($value, $callback($this->person), + 'the value '.$field.' is updated in db'); } /** @@ -176,8 +178,10 @@ class PersonUpdateTest extends WebTestCase $crawler = $this->client->submit($form); - $this->assertFalse($this->client->getResponse()->isRedirect()); - $this->assertGreaterThan(0, $crawler->filter('.error')->count()); + $this->assertFalse($this->client->getResponse()->isRedirect(), + 'the page is not redirected to /general'); + $this->assertGreaterThan(0, $crawler->filter('.error')->count(), + 'a element .error is shown'); } public function providesInvalidFieldsValues() @@ -186,7 +190,8 @@ class PersonUpdateTest extends WebTestCase ['firstName', $this->getVeryLongText()], ['lastName', $this->getVeryLongText()], ['firstName', ''], - ['lastName', ''] + ['lastName', ''], + ['dateOfBirth', 'false date'] ); } From d554407dce8d49df2adf30c5f32bf16ba4d37065 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 29 Jan 2015 22:01:16 +0100 Subject: [PATCH 07/12] fix validation on person update close #408 --- Controller/PersonController.php | 15 +++++---------- Form/PersonType.php | 3 ++- Resources/translations/messages.fr.yml | 1 + 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/Controller/PersonController.php b/Controller/PersonController.php index e536119d0..e12290347 100644 --- a/Controller/PersonController.php +++ b/Controller/PersonController.php @@ -91,16 +91,11 @@ class PersonController extends Controller if ($request->getMethod() === 'POST') { $form->handleRequest($request); - - $errors = $this->get('validator') - ->validate($person, array('general')); - - if ( count($errors) > 0 ) { - - $errors = $form->getErrorsAsString(); - + + if ( ! $form->isValid() ) { $this->get('session') - ->getFlashBag()->add('danger', 'error' . $errors); + ->getFlashBag()->add('danger', 'Thp person data provided' + . ' are not valid'); return $this->render('ChillPersonBundle:Person:edit.html.twig', array('person' => $person, @@ -110,7 +105,7 @@ class PersonController extends Controller $this->get('session')->getFlashBag() ->add('success', $this->get('translator') - ->trans('The person has been created') + ->trans('The person data has been updated') ); $em = $this->getDoctrine()->getManager(); diff --git a/Form/PersonType.php b/Form/PersonType.php index 84b82cd23..6d90623ef 100644 --- a/Form/PersonType.php +++ b/Form/PersonType.php @@ -74,7 +74,8 @@ class PersonType extends AbstractType public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver->setDefaults(array( - 'data_class' => 'Chill\PersonBundle\Entity\Person' + 'data_class' => 'Chill\PersonBundle\Entity\Person', + 'validation_groups' => array('general', 'creation') )); $resolver->setRequired(array( diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml index 5b3145ef5..b3ef30387 100644 --- a/Resources/translations/messages.fr.yml +++ b/Resources/translations/messages.fr.yml @@ -47,6 +47,7 @@ Return: Retour Submit: Envoi Reset: 'Remise à zéro' 'The person data has been updated': 'Bravo ! Les données ont été mises à jour.' +'The person data provided are not valid': 'Les données introduites ne sont pas valides' '{1} The person field %field% is incorrect. Please check. | ]1, Inf] Several person fields are incorrect. Please check.': '{1} Le champs %field% est incorrect. Veuillez le corriger. | ]1, Inf] Plusieurs champs sont incorrects. Veuillez les vérifier.' 'Add a person': 'Ajout d''une personne' 'Person Menu': 'Menu personne' From 72182a8c77760c48b5a620b4b551df34135b79cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 30 Jan 2015 18:02:09 +0100 Subject: [PATCH 08/12] move utilities at the end of the file --- .../Controller/PersonControllerUpdateTest.php | 47 ++++++++++--------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/Tests/Controller/PersonControllerUpdateTest.php b/Tests/Controller/PersonControllerUpdateTest.php index 20b423151..1eba88e23 100644 --- a/Tests/Controller/PersonControllerUpdateTest.php +++ b/Tests/Controller/PersonControllerUpdateTest.php @@ -134,6 +134,30 @@ class PersonControllerUpdateTest extends WebTestCase 'the value '.$field.' is updated in db'); } + + /** + * + * @dataProvider providesInvalidFieldsValues + * @param string $field + * @param string $value + */ + public function testInvalidFields($field, $value) + { + $crawler = $this->client->request('GET', $this->editUrl); + + $form = $crawler->selectButton('Submit') + ->form(); + $form->get('chill_personbundle_person['.$field.']') + ->setValue($value); + + $crawler = $this->client->submit($form); + + $this->assertFalse($this->client->getResponse()->isRedirect(), + 'the page is not redirected to /general'); + $this->assertGreaterThan(0, $crawler->filter('.error')->count(), + 'a element .error is shown'); + } + /** * provide valid values to test, with field name and * a function to find the value back from person entity @@ -161,29 +185,6 @@ class PersonControllerUpdateTest extends WebTestCase ); } - /** - * - * @dataProvider providesInvalidFieldsValues - * @param string $field - * @param string $value - */ - public function testInvalidFields($field, $value) - { - $crawler = $this->client->request('GET', $this->editUrl); - - $form = $crawler->selectButton('Submit') - ->form(); - $form->get('chill_personbundle_person['.$field.']') - ->setValue($value); - - $crawler = $this->client->submit($form); - - $this->assertFalse($this->client->getResponse()->isRedirect(), - 'the page is not redirected to /general'); - $this->assertGreaterThan(0, $crawler->filter('.error')->count(), - 'a element .error is shown'); - } - public function providesInvalidFieldsValues() { return array( From aa8d211e55f1570fb08836b47d677b8e6570e1eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 30 Jan 2015 18:14:27 +0100 Subject: [PATCH 09/12] add test for choose languages fix #409 --- .../Controller/PersonControllerUpdateTest.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Tests/Controller/PersonControllerUpdateTest.php b/Tests/Controller/PersonControllerUpdateTest.php index 1eba88e23..6196bb166 100644 --- a/Tests/Controller/PersonControllerUpdateTest.php +++ b/Tests/Controller/PersonControllerUpdateTest.php @@ -134,6 +134,30 @@ class PersonControllerUpdateTest extends WebTestCase 'the value '.$field.' is updated in db'); } + public function testEditLanguages() + { + $crawler = $this->client->request('GET', $this->editUrl); + $selectedLanguages = array('en', 'an', 'bbj'); + + $form = $crawler->selectButton('Submit') + ->form(); + $form->get('chill_personbundle_person[spokenLanguages]') + ->setValue($selectedLanguages); + + $this->client->submit($form); + $this->em->refresh($this->person); + + $this->assertTrue($this->client->getResponse()->isRedirect($this->seeUrl), + 'the page is redirected to /general view'); + //retrieve languages codes present in person + foreach($this->person->getSpokenLanguages() as $lang){ + $languagesCodesPresents[] = $lang->getId(); + } + $this->assertEquals(asort($selectedLanguages), asort($languagesCodesPresents), + 'the person speaks the expected languages'); + + } + /** * From 7ebaafe768d533dd65487dfe7447a404b0ff1852 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 3 Feb 2015 10:03:36 +0100 Subject: [PATCH 10/12] create first tests for accompanying period manipulation [ci skip] --- Controller/HistoryController.php | 5 + Entity/Person.php | 4 + Form/PersonHistoryFileType.php | 9 +- Resources/views/History/form.html.twig | 2 +- .../AccompanyingPeriodControllerTest.php | 197 ++++++++++++++++++ 5 files changed, 213 insertions(+), 4 deletions(-) create mode 100644 Tests/Controller/AccompanyingPeriodControllerTest.php diff --git a/Controller/HistoryController.php b/Controller/HistoryController.php index d73076f95..29a858c05 100644 --- a/Controller/HistoryController.php +++ b/Controller/HistoryController.php @@ -208,6 +208,11 @@ class HistoryController extends Controller $this->get('session')->getFlashBag() ->add('danger', $this->get('translator') ->trans('History closing form is not valide')); + + foreach ($form->getErrors() as $error) { + $this->get('session')->getFlashBag() + ->add('info', $error->getMessage()); + } } } diff --git a/Entity/Person.php b/Entity/Person.php index ad7b6e6cd..470a293bc 100644 --- a/Entity/Person.php +++ b/Entity/Person.php @@ -133,6 +133,10 @@ class Person { $this->history->add($history); } + public function removeHistoryFile(PersonHistoryFile $history) { + $this->history->remove($history); + } + /** * set the Person file as open at the given date. * diff --git a/Form/PersonHistoryFileType.php b/Form/PersonHistoryFileType.php index 4274d4800..3f57e4b0d 100644 --- a/Form/PersonHistoryFileType.php +++ b/Form/PersonHistoryFileType.php @@ -22,8 +22,11 @@ class PersonHistoryFileType extends AbstractType //if the period_action is close, date opening should not be seen if ($options['period_action'] !== 'close') { $builder - ->add('date_opening', 'date', array("required" => true, - 'widget' => 'single_text')); + ->add('date_opening', 'date', array( + "required" => true, + 'widget' => 'single_text', + 'format' => 'dd-MM-yyyy' + )); } // the closingDate should be seen only if period_action = close @@ -41,7 +44,7 @@ class PersonHistoryFileType extends AbstractType ($options['period_action'] === 'update' AND !$accompanyingPeriod->isOpen()) ){ $form->add('date_closing', 'date', array('required' => true, - 'widget' => 'single_text')); + 'widget' => 'single_text', 'format' => 'dd-MM-yyyy')); $form->add('closingMotive', 'closing_motive'); } }); diff --git a/Resources/views/History/form.html.twig b/Resources/views/History/form.html.twig index 0fdaa7c9c..9b7dbb7fb 100644 --- a/Resources/views/History/form.html.twig +++ b/Resources/views/History/form.html.twig @@ -25,7 +25,7 @@ {{ form_rest(form) }}
- +
{{ form_end(form) }} diff --git a/Tests/Controller/AccompanyingPeriodControllerTest.php b/Tests/Controller/AccompanyingPeriodControllerTest.php new file mode 100644 index 000000000..07b489fd4 --- /dev/null +++ b/Tests/Controller/AccompanyingPeriodControllerTest.php @@ -0,0 +1,197 @@ + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Chill\PersonBundle\Tests\Controller; + +use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; +use Chill\PersonBundle\Entity\PersonHistoryFile as AccompanyingPeriod; +use Chill\PersonBundle\Entity\Person; +use Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive; + +/** + * Test the creation or deletion of accompanying periods + * + * @author Julien Fastré + */ +class AccompanyingPeriodControllerTest extends WebTestCase +{ + /** + * + * @var \Symfony\Component\BrowserKit\Client + */ + private $client; + + /** + * + * @var Person + */ + private $person; + + /** + * + * @var \Doctrine\ORM\EntityManagerInterface + */ + private static $em; + + const OPENING_INPUT = 'cl_chill_personbundle_personhistoryfile[date_opening]'; + const CLOSING_INPUT = 'cl_chill_personbundle_personhistoryfile[date_closing]'; + const CLOSING_MOTIVE_INPUT = 'cl_chill_personbundle_personhistoryfile[closingMotive]'; + + public static function setUpBeforeClass() + { + static::bootKernel(); + + static::$em = static::$kernel->getContainer() + ->get('doctrine.orm.entity_manager'); + } + + public function setUp() + { + $this->client = static::createClient(array(), array( + 'PHP_AUTH_USER' => 'center a_social', + 'PHP_AUTH_PW' => 'password', + )); + + $this->person = (new Person(new \DateTime('2015-01-05'))) + ->setFirstName('Roland') + ->setLastName('Gallorime') + ->setGenre(Person::GENRE_MAN) + ; + + //remove Accompanying periods + $this->person->close($this->person->getCurrentHistory() + ->setDateClosing(new \DateTime('2015-01-05'))); + foreach($this->person->getHistories() as $accompanyingPeriod) { + $this->person->removeHistoryFile($accompanyingPeriod); + } + static::$em->persist($this->person); + static::$em->flush(); + } + + public function tearDown() + { + //static::$em->refresh($this->person); + //static::$em->remove($this->person); + + //static::$em->flush(); + } + + private function generatePeriods(array $periods) + { + foreach ($periods as $periodDef) { + $period = new AccompanyingPeriod(new \DateTime($periodDef['openingDate'])); + var_dump((new \DateTime($periodDef['openingDate']))->format('d-m-Y')); + if (array_key_exists('closingDate', $periodDef)) { + if (!array_key_exists('closingMotive', $periodDef)) { + throw new \LogicalException('you must define a closing ' + . 'motive into your periods fixtures'); + } + + $period->setDateClosing(new \DateTime($periodDef['closingDate'])) + ->setClosingMotive($periodDef['closingMotive']); + } + + $this->person->addHistoryFile($period); + + static::$em->persist($period); + + } + + static::$em->flush(); + } + + private function getLastValueOnClosingMotive(\Symfony\Component\DomCrawler\Form $form) + { + return end($form->get(self::CLOSING_MOTIVE_INPUT) + ->availableOptionValues()); + } + + /** + * Test the closing of a periods + * + * Given that a person as an accompanying period opened since 2015-01-05 + * and we fill the close form (at /en/person/[id]/history/close + * with : dateClosing: 2015-02-01 + * with : the last closing motive in list + * Then the response should redirect to history view + * And the next page should have a `.error` element present in page + * + * @todo + */ + public function testClosingCurrentPeriod() + { + + $this->markTestSkipped('not implemented fully'); + + $this->generatePeriods(array( [ + 'openingDate' => '2015-01-05' + ] + )); + + $crawler = $this->client->request('GET', '/en/person/' + .$this->person->getId().'/history/close'); + + $form = $crawler->selectButton('Submit')->form(); + + $form->get(self::CLOSING_MOTIVE_INPUT) + ->setValue($this->getLastValueOnClosingMotive($form)); + $form->get(self::CLOSING_INPUT) + ->setValue((new \DateTime('2015-02-01'))->format('d-m-Y')); + var_dump((new \DateTime('2015-02-01'))->format('d-m-Y')); + $cr = $this->client->submit($form); + var_dump($cr->text()); + $this->assertTrue($this->client->getResponse()->isRedirect( + '/en/person/'.$this->person->getId().'/history'), + 'the server redirects to /history page'); + $this->assertGreaterThan(0, $this->client->followRedirect() + ->filter('.success')->count(), + "a 'success' message is shown"); + } + + + public function testAddNewPeriodBeforeActual() + { + $this->generatePeriods(array( + [ + 'openingDate' => '2015-01-25' + ] + )); + + $crawler = $this->client->request('GET', '/en/person/' + .$this->person->getId().'/history/create'); + + $form = $crawler->selectButton('Submit')->form();; + $form->get(self::CLOSING_MOTIVE_INPUT) + ->setValue($this->getLastValueOnClosingMotive($form)); + $form->get(self::CLOSING_INPUT) + ->setValue('31-12-2014'); + $form->get(self::OPENING_INPUT) + ->setValue('01-01-2014'); + + $this->client->submit($form); + + $this->assertTrue($this->client->getResponse()->isRedirect( + '/en/person/'.$this->person->getId().'/history'), + 'the server redirects to /history page'); + $this->assertGreaterThan(0, $this->client->followRedirect() + ->filter('.success')->count(), + "a 'success' message is shown"); + } +} From 69042c683f7ffe6f4cc51289769dc9385e15296e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 3 Feb 2015 15:02:43 +0100 Subject: [PATCH 11/12] add tests for closing/opening accompanying periods refs #274 check : - closing the current period works - closing a period with date closing AFTER the opening fails - creating a new period works - create a period with closing after current (opened) period fails => fails see refs #410 - create a period with opening and closing after current (opened) period fails => fails see refs #410 - create a period with end date between another fails - create a period with end date after opening date fails - create a period between another period (date closing and date opening) fails - create a period with date opening inside another period fails --- .../AccompanyingPeriodControllerTest.php | 320 ++++++++++++++++-- 1 file changed, 293 insertions(+), 27 deletions(-) diff --git a/Tests/Controller/AccompanyingPeriodControllerTest.php b/Tests/Controller/AccompanyingPeriodControllerTest.php index 07b489fd4..6cf2d8cb7 100644 --- a/Tests/Controller/AccompanyingPeriodControllerTest.php +++ b/Tests/Controller/AccompanyingPeriodControllerTest.php @@ -75,29 +75,23 @@ class AccompanyingPeriodControllerTest extends WebTestCase ->setGenre(Person::GENRE_MAN) ; - //remove Accompanying periods - $this->person->close($this->person->getCurrentHistory() - ->setDateClosing(new \DateTime('2015-01-05'))); - foreach($this->person->getHistories() as $accompanyingPeriod) { - $this->person->removeHistoryFile($accompanyingPeriod); - } static::$em->persist($this->person); static::$em->flush(); } public function tearDown() { - //static::$em->refresh($this->person); - //static::$em->remove($this->person); + static::$em->refresh($this->person); + static::$em->remove($this->person); - //static::$em->flush(); + static::$em->flush(); } private function generatePeriods(array $periods) { foreach ($periods as $periodDef) { $period = new AccompanyingPeriod(new \DateTime($periodDef['openingDate'])); - var_dump((new \DateTime($periodDef['openingDate']))->format('d-m-Y')); + if (array_key_exists('closingDate', $periodDef)) { if (!array_key_exists('closingMotive', $periodDef)) { throw new \LogicalException('you must define a closing ' @@ -123,6 +117,14 @@ class AccompanyingPeriodControllerTest extends WebTestCase ->availableOptionValues()); } + private function getRandomClosingMotive() + { + $motives = static::$em + ->getRepository('ChillPersonBundle:AccompanyingPeriod\ClosingMotive') + ->findAll(); + return end($motives); + } + /** * Test the closing of a periods * @@ -137,13 +139,6 @@ class AccompanyingPeriodControllerTest extends WebTestCase */ public function testClosingCurrentPeriod() { - - $this->markTestSkipped('not implemented fully'); - - $this->generatePeriods(array( [ - 'openingDate' => '2015-01-05' - ] - )); $crawler = $this->client->request('GET', '/en/person/' .$this->person->getId().'/history/close'); @@ -154,25 +149,63 @@ class AccompanyingPeriodControllerTest extends WebTestCase ->setValue($this->getLastValueOnClosingMotive($form)); $form->get(self::CLOSING_INPUT) ->setValue((new \DateTime('2015-02-01'))->format('d-m-Y')); - var_dump((new \DateTime('2015-02-01'))->format('d-m-Y')); + $cr = $this->client->submit($form); - var_dump($cr->text()); + $this->assertTrue($this->client->getResponse()->isRedirect( '/en/person/'.$this->person->getId().'/history'), 'the server redirects to /history page'); $this->assertGreaterThan(0, $this->client->followRedirect() - ->filter('.success')->count(), - "a 'success' message is shown"); + ->filter('.success')->count(), + "a 'success' element is shown"); } + /** + * Test the closing of a periods + * + * Given that a person as an accompanying period opened since 2015-01-05 + * and we fill the close form (at /en/person/[id]/history/close + * with : dateClosing: 2014-01-01 + * with : the last closing motive in list + * Then the response should redirect to history view + * And the next page should have a `.error` element present in page + * + * @todo + */ + public function testClosingCurrentPeriodWithDateClosingBeforeOpeningFails() + { + + $crawler = $this->client->request('GET', '/en/person/' + .$this->person->getId().'/history/close'); + + $form = $crawler->selectButton('Submit')->form(); + + $form->get(self::CLOSING_MOTIVE_INPUT) + ->setValue($this->getLastValueOnClosingMotive($form)); + $form->get(self::CLOSING_INPUT) + ->setValue((new \DateTime('2014-01-01'))->format('d-m-Y')); + + $crawlerResponse = $this->client->submit($form); + + $this->assertFalse($this->client->getResponse()->isRedirect(), + 'the server stays on the /close page'); + $this->assertGreaterThan(0, $crawlerResponse + ->filter('.error')->count(), + "an '.error' element is shown"); + } + /** + * Test the creation of a new period + * + * Given that a person as an accompanying period opened since 2015-01-05 + * and we create a new period + * with : dateClosing: 2014-12-31 + * with : dateOpening: 2014-01-01 + * with : the last closing motive in list + * Then the response should redirect to history view + */ public function testAddNewPeriodBeforeActual() { - $this->generatePeriods(array( - [ - 'openingDate' => '2015-01-25' - ] - )); $crawler = $this->client->request('GET', '/en/person/' .$this->person->getId().'/history/create'); @@ -192,6 +225,239 @@ class AccompanyingPeriodControllerTest extends WebTestCase 'the server redirects to /history page'); $this->assertGreaterThan(0, $this->client->followRedirect() ->filter('.success')->count(), - "a 'success' message is shown"); + "a 'success' element is shown"); } + + /** + * Create a period with closing after current fails + * + * Given that a person as an accompanying period opened since 2015-01-05 + * and we create a new period + * with : dateClosing: 2015-02-01 (after 2015-01-05) + * with : dateOpening: 2014-12-31 + * with : the last closing motive in list + * Then the response should not redirect to any page + * and an error element is shown + * + * @todo + */ + public function testCreatePeriodWithClosingAfterCurrentFails() + { + + $this->markTestSkipped('this feature is not yet implemented'); + + $crawler = $this->client->request('GET', '/en/person/' + .$this->person->getId().'/history/create'); + + $form = $crawler->selectButton('Submit')->form();; + $form->get(self::CLOSING_MOTIVE_INPUT) + ->setValue($this->getLastValueOnClosingMotive($form)); + $form->get(self::CLOSING_INPUT) + ->setValue('01-02-2015'); + $form->get(self::OPENING_INPUT) + ->setValue('31-12-2014'); + + $crawler = $this->client->submit($form); + + $this->assertFalse($this->client->getResponse()->isRedirect(), + 'the server stay on form page'); + $this->assertGreaterThan(0, $crawler->filter('.error')->count(), + "an 'error' element is shown"); + } + + /** + * Create a period after a current opened period fails + * + * Given that a person as an accompanying period opened since 2015-01-05 + * and we create a new period + * with : dateClosing: 2015-03-01 + * with : dateOpening: 2015-02-01 + * with : the last closing motive in list + * Then the response should not redirect to any page + * and an error element is shown + * + * @todo + */ + public function testCreatePeriodWithOpeningAndClosingAfterCurrentFails() + { + + $this->markTestSkipped('this feature is not yet implemented'); + + $crawler = $this->client->request('GET', '/en/person/' + .$this->person->getId().'/history/create'); + + $form = $crawler->selectButton('Submit')->form();; + $form->get(self::CLOSING_MOTIVE_INPUT) + ->setValue($this->getLastValueOnClosingMotive($form)); + $form->get(self::CLOSING_INPUT) + ->setValue('01-03-2015'); + $form->get(self::OPENING_INPUT) + ->setValue('01-02-2015'); + + $crawler = $this->client->submit($form); + + $this->assertFalse($this->client->getResponse()->isRedirect(), + 'the server stay on form page'); + $this->assertGreaterThan(0, $crawler->filter('.error')->count(), + "an 'error' element is shown"); + } + + /** + * create a period with date end between another period must fails + * + * Given that a person as an accompanying period opened since 2015-01-05 + * and that this person has another accompanying period between 2014-01-01 and 2014-12-31 + * and we create a new period + * with : dateClosing: 2014-16-01 + * with : dateOpening: 2013-01-01 + * with : the last closing motive in list + * Then the response should not redirect + * and a error element is shown on the response page + */ + public function testCreatePeriodWithDateEndBetweenAnotherPeriodFails() + { + + $this->generatePeriods(array( + [ + 'openingDate' => '2014-01-01', + 'closingDate' => '2014-12-31', + 'closingMotive' => $this->getRandomClosingMotive() + ] + )); + + $crawler = $this->client->request('GET', '/en/person/' + .$this->person->getId().'/history/create'); + + $form = $crawler->selectButton('Submit')->form();; + $form->get(self::CLOSING_MOTIVE_INPUT) + ->setValue($this->getLastValueOnClosingMotive($form)); + $form->get(self::CLOSING_INPUT) + ->setValue('31-12-2014'); + $form->get(self::OPENING_INPUT) + ->setValue('01-02-2015'); + + $crawlerResponse = $this->client->submit($form); + + $this->assertFalse($this->client->getResponse()->isRedirect(), + 'the server stay on form page'); + $this->assertGreaterThan(0, $crawlerResponse->filter('.error')->count(), + "an 'error' element is shown"); + } + + /** + * create a period with date closing after opening fails + * + * Given that a person as an accompanying period opened since 2015-01-05 + * and we create a new period + * with : dateClosing: 2014-01-01 (before opening) + * with : dateOpening: 2015-01-01 + * with : the last closing motive in list + * Then the response should redirect to history view + */ + public function testCreatePeriodWithClosingBeforeOpeningFails() + { + $crawler = $this->client->request('GET', '/en/person/' + .$this->person->getId().'/history/create'); + + $form = $crawler->selectButton('Submit')->form();; + $form->get(self::CLOSING_MOTIVE_INPUT) + ->setValue($this->getLastValueOnClosingMotive($form)); + $form->get(self::CLOSING_INPUT) + ->setValue('01-01-2014'); + $form->get(self::OPENING_INPUT) + ->setValue('01-01-2015'); + + $crawler = $this->client->submit($form); + + $this->assertFalse($this->client->getResponse()->isRedirect(), + 'the server stay on form page'); + $this->assertGreaterThan(0, $crawler->filter('.error')->count(), + "an 'error' element is shown"); + } + + /** + * create a period with date closing and date opening inside another period + * fails + * + * Given that a person as an accompanying period opened since 2015-01-05 + * and that this person has another accompanying period between 2014-01-01 and 2014-12-31 + * and we create a new period + * with : dateClosing: 2014-02-01 + * with : dateOpening: 2014-03-01 + * with : the last closing motive in list + * Then the response should not redirect + * and a error element is shown on the response page + */ + public function testCreatePeriodAfterOpeningFails() + { + $this->generatePeriods(array( + [ + 'openingDate' => '2014-01-01', + 'closingDate' => '2014-12-31', + 'closingMotive' => $this->getRandomClosingMotive() + ] + )); + + $crawler = $this->client->request('GET', '/en/person/' + .$this->person->getId().'/history/create'); + + $form = $crawler->selectButton('Submit')->form();; + $form->get(self::CLOSING_MOTIVE_INPUT) + ->setValue($this->getLastValueOnClosingMotive($form)); + $form->get(self::CLOSING_INPUT) + ->setValue('2014-02-01'); + $form->get(self::OPENING_INPUT) + ->setValue('01-03-2014'); + + $crawlerResponse = $this->client->submit($form); + + $this->assertFalse($this->client->getResponse()->isRedirect(), + 'the server stay on form page'); + $this->assertGreaterThan(0, $crawlerResponse->filter('.error')->count(), + "an 'error' element is shown"); + } + + /** + * Create a period with dateOpening between another period must fails + * + * Given that a person as an accompanying period opened since 2015-01-05 + * and that this person has another accompanying period between 2014-01-01 and 2014-12-31 + * and we create a new period + * with : dateClosing: 2015-01-01 + * with : dateOpening: 2014-06-01 + * with : the last closing motive in list + * Then the response should not redirect + * and a error element is shown on the response page + */ + public function testCreatePeriodWithDateOpeningBetweenAnotherPeriodFails() + { + + $this->generatePeriods(array( + [ + 'openingDate' => '2014-01-01', + 'closingDate' => '2014-12-31', + 'closingMotive' => $this->getRandomClosingMotive() + ] + )); + + $crawler = $this->client->request('GET', '/en/person/' + .$this->person->getId().'/history/create'); + + $form = $crawler->selectButton('Submit')->form();; + $form->get(self::CLOSING_MOTIVE_INPUT) + ->setValue($this->getLastValueOnClosingMotive($form)); + $form->get(self::CLOSING_INPUT) + ->setValue('2015-01-01'); + $form->get(self::OPENING_INPUT) + ->setValue('01-06-2014'); + + $crawlerResponse = $this->client->submit($form); + + $this->assertFalse($this->client->getResponse()->isRedirect(), + 'the server stay on form page'); + $this->assertGreaterThan(0, $crawlerResponse->filter('.error')->count(), + "an 'error' element is shown"); + } + + } From 9fadc5d9c5a1aa1c68e9e52517532d433f39dab8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 5 Feb 2015 14:35:22 +0100 Subject: [PATCH 12/12] passing last value on closing motive by reference refs #411 --- Tests/Controller/AccompanyingPeriodControllerTest.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Tests/Controller/AccompanyingPeriodControllerTest.php b/Tests/Controller/AccompanyingPeriodControllerTest.php index 6cf2d8cb7..1d2abd882 100644 --- a/Tests/Controller/AccompanyingPeriodControllerTest.php +++ b/Tests/Controller/AccompanyingPeriodControllerTest.php @@ -113,8 +113,9 @@ class AccompanyingPeriodControllerTest extends WebTestCase private function getLastValueOnClosingMotive(\Symfony\Component\DomCrawler\Form $form) { - return end($form->get(self::CLOSING_MOTIVE_INPUT) - ->availableOptionValues()); + $values = $form->get(self::CLOSING_MOTIVE_INPUT) + ->availableOptionValues(); + return end($values); } private function getRandomClosingMotive()