diff --git a/src/Bundle/ChillPersonBundle/Controller/PersonController.php b/src/Bundle/ChillPersonBundle/Controller/PersonController.php index 747299e59..f33e9cce8 100644 --- a/src/Bundle/ChillPersonBundle/Controller/PersonController.php +++ b/src/Bundle/ChillPersonBundle/Controller/PersonController.php @@ -252,18 +252,6 @@ final class PersonController extends AbstractController */ $person = $form->getData(); - $periods = $person->getAccompanyingPeriodsOrdered(); - $period = $periods[0]; - $period->setOpeningDate($form['creation_date']->getData()); -// $person = new Person($form['creation_date']->getData()); -// -// $person->setFirstName($form['firstName']->getData()) -// ->setLastName($form['lastName']->getData()) -// ->setGender($form['gender']->getData()) -// ->setBirthdate($form['birthdate']->getData()) -// ->setCenter($form['center']->getData()) -// ; - return $person; } @@ -364,7 +352,6 @@ final class PersonController extends AbstractController 'lastName' => $form['lastName']->getData(), 'birthdate' => $form['birthdate']->getData(), 'gender' => $form['gender']->getData(), - 'creation_date' => $form['creation_date']->getData(), 'form' => $form->createView())); } diff --git a/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadPeople.php b/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadPeople.php index e8697ff28..556d832c1 100644 --- a/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadPeople.php +++ b/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadPeople.php @@ -183,6 +183,14 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con private function addAPerson(array $person, ObjectManager $manager) { $p = new Person(); + $p->addAccompanyingPeriod( + new AccompanyingPeriod( + (new \DateTime()) + ->sub( + new \DateInterval('P'.\random_int(0, 180).'D') + ) + ) + ); foreach ($person as $key => $value) { switch ($key) { diff --git a/src/Bundle/ChillPersonBundle/Entity/Person.php b/src/Bundle/ChillPersonBundle/Entity/Person.php index 7f9805f52..695970bfa 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person.php @@ -379,12 +379,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI */ private Collection $householdAddresses; - /** - * Person constructor. - * - * @param \DateTime|null $opening - */ - public function __construct(\DateTime $opening = null) + public function __construct() { $this->accompanyingPeriodParticipations = new ArrayCollection(); $this->spokenLanguages = new ArrayCollection(); @@ -393,12 +388,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI $this->otherPhoneNumbers = new ArrayCollection(); $this->householdParticipations = new ArrayCollection(); $this->householdAddresses = new ArrayCollection(); - - if ($opening === null) { - $opening = new \DateTime(); - } - - $this->open(new AccompanyingPeriod($opening)); $this->genderComment = new CommentEmbeddable(); $this->maritalStatusComment = new CommentEmbeddable(); } diff --git a/src/Bundle/ChillPersonBundle/Form/CreationPersonType.php b/src/Bundle/ChillPersonBundle/Form/CreationPersonType.php index e3583071f..c001185ca 100644 --- a/src/Bundle/ChillPersonBundle/Form/CreationPersonType.php +++ b/src/Bundle/ChillPersonBundle/Form/CreationPersonType.php @@ -26,7 +26,7 @@ use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransformer; use Symfony\Component\Form\Extension\Core\Type\HiddenType; -use Symfony\Component\Form\Extension\Core\Type\DateType; +use Chill\MainBundle\Form\Type\ChillDateType; use Chill\MainBundle\Form\Type\CenterType; use Chill\PersonBundle\Form\Type\GenderType; use Chill\MainBundle\Form\Type\DataTransformer\CenterTransformer; @@ -80,9 +80,6 @@ final class CreationPersonType extends AbstractType 'property_path' => 'birthdate' )) ->add('gender', HiddenType::class) - ->add('creation_date', HiddenType::class, array( - 'mapped' => false - )) ->add('form_status', HiddenType::class, array( 'mapped' => false, 'data' => $options['form_status'] @@ -99,25 +96,18 @@ final class CreationPersonType extends AbstractType $builder->get('birthdate') ->addModelTransformer($dateToStringTransformer); - $builder->get('creation_date') - ->addModelTransformer($dateToStringTransformer); $builder->get('center') ->addModelTransformer($this->centerTransformer); } else { $builder ->add('firstName') ->add('lastName') - ->add('birthdate', DateType::class, array('required' => false, - 'widget' => 'single_text', 'format' => 'dd-MM-yyyy')) + ->add('birthdate', ChillDateType::class, [ + 'required' => false, + ]) ->add('gender', GenderType::class, array( 'required' => true, 'placeholder' => null )) - ->add('creation_date', DateType::class, array( - 'required' => true, - 'widget' => 'single_text', - 'format' => 'dd-MM-yyyy', - 'mapped' => false, - 'data' => new \DateTime())) ->add('form_status', HiddenType::class, array( 'data' => $options['form_status'], 'mapped' => false diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Person/create.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Person/create.html.twig index 9d17cba9d..e7a6fb4a6 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Person/create.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Person/create.html.twig @@ -1,7 +1,6 @@ {# * Copyright (C) 2014, Champs Libres Cooperative SCRLFS, - * - * 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 * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. @@ -38,8 +37,6 @@ {{ form_row(form.birthdate, { 'label' : 'Date of birth'|trans }) }} {{ form_row(form.gender, { 'label' : 'Gender'|trans }) }} - - {{ form_row(form.creation_date, { 'label' : 'Creation date'|trans }) }} {{ form_rest(form) }} diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Person/create_review.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Person/create_review.html.twig index 8c5b6eb35..cd32c180c 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Person/create_review.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Person/create_review.html.twig @@ -71,14 +71,15 @@
{{ person|chill_entity_render_string }}
{{ 'Date of birth'|trans }}
-
{{ birthdate|format_date('long')|default( 'Unknown date of birth'|trans ) }}
+ {% if birthdate is empty %} +
{{ 'Unknown date of birth'|trans }}
+ {% else %} +
{{ birthdate|format_date('long') }}
+ {% endif %}
{{ 'Gender'|trans }}
{{ gender|trans }}
-
{{ 'Creation date'|trans }}
-
{{ creation_date|format_date('long') }}
- {% if form.altNames is defined %} {# mark as rendered #} {{ form_widget(form.altNames) }} @@ -86,10 +87,13 @@ {{ form_rest(form) }} - + {{ form_end(form) }} - diff --git a/src/Bundle/ChillPersonBundle/Tests/Controller/PersonControllerCreateTest.php b/src/Bundle/ChillPersonBundle/Tests/Controller/PersonControllerCreateTest.php index 57444dfaa..f7dd055c6 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Controller/PersonControllerCreateTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Controller/PersonControllerCreateTest.php @@ -93,8 +93,6 @@ class PersonControllerCreateTest extends WebTestCase 'The page contains a "gender" input'); $this->assertTrue($form->has(self::BIRTHDATE_INPUT), 'The page has a "date of birth" input'); - $this->assertTrue($form->has(self::CREATEDATE_INPUT), - 'The page contains a "creation date" input'); $genderType = $form->get(self::GENDER_INPUT); $this->assertEquals('radio', $genderType->getType(), @@ -107,10 +105,6 @@ class PersonControllerCreateTest extends WebTestCase 'gender has "femme" option'); $this->assertFalse($genderType->hasValue(), 'The gender input is not checked'); - $today = new \DateTime(); - $this->assertEquals($today->format('d-m-Y'), $form->get(self::CREATEDATE_INPUT) - ->getValue(), 'The creation date input has the current date by default'); - return $form; } diff --git a/src/Bundle/ChillPersonBundle/Tests/Entity/PersonTest.php b/src/Bundle/ChillPersonBundle/Tests/Entity/PersonTest.php index 7e9337d14..dbef739d1 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Entity/PersonTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Entity/PersonTest.php @@ -45,11 +45,12 @@ class PersonTest extends \PHPUnit\Framework\TestCase public function testGetCurrentAccompanyingPeriod() { $d = new \DateTime('yesterday'); - $p = new Person($d); + $p = new Person(); + $p->addAccompanyingPeriod(new AccompanyingPeriod($d)); $period = $p->getCurrentAccompanyingPeriod(); - $this->assertInstanceOf('Chill\PersonBundle\Entity\AccompanyingPeriod', $period); + $this->assertInstanceOf(AccompanyingPeriod::class, $period); $this->assertTrue($period->isOpen()); $this->assertEquals($d, $period->getOpeningDate()); @@ -67,7 +68,8 @@ class PersonTest extends \PHPUnit\Framework\TestCase public function testAccompanyingPeriodOrderWithUnorderedAccompanyingPeriod() { $d = new \DateTime("2013/2/1"); - $p = new Person($d); + $p = new Person(); + $p->addAccompanyingPeriod(new AccompanyingPeriod($d)); $e = new \DateTime("2013/3/1"); $period = $p->getCurrentAccompanyingPeriod()->setClosingDate($e); @@ -93,7 +95,8 @@ class PersonTest extends \PHPUnit\Framework\TestCase */ public function testAccompanyingPeriodOrderSameDateOpening() { $d = new \DateTime("2013/2/1"); - $p = new Person($d); + $p = new Person(); + $p->addAccompanyingPeriod(new AccompanyingPeriod($d)); $g = new \DateTime("2013/4/1"); $period = $p->getCurrentAccompanyingPeriod()->setClosingDate($g); @@ -120,7 +123,8 @@ class PersonTest extends \PHPUnit\Framework\TestCase */ public function testDateCoveringWithCoveringAccompanyingPeriod() { $d = new \DateTime("2013/2/1"); - $p = new Person($d); + $p = new Person(); + $p->addAccompanyingPeriod(new AccompanyingPeriod($d)); $e = new \DateTime("2013/3/1"); $period = $p->getCurrentAccompanyingPeriod()->setClosingDate($e); @@ -145,7 +149,8 @@ class PersonTest extends \PHPUnit\Framework\TestCase */ public function testNotOpenAFileReOpenedLater() { $d = new \DateTime("2013/2/1"); - $p = new Person($d); + $p = new Person(); + $p->addAccompanyingPeriod(new AccompanyingPeriod($d)); $e = new \DateTime("2013/3/1"); $period = $p->getCurrentAccompanyingPeriod()->setClosingDate($e); diff --git a/src/Bundle/ChillPersonBundle/Tests/Timeline/TimelineAccompanyingPeriodTest.php b/src/Bundle/ChillPersonBundle/Tests/Timeline/TimelineAccompanyingPeriodTest.php index 4fb3c7f06..9b2a32c85 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Timeline/TimelineAccompanyingPeriodTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Timeline/TimelineAccompanyingPeriodTest.php @@ -20,9 +20,11 @@ namespace Chill\PersonBundle\Tests\Timeline; -use Symfony\Bundle\SecurityBundle\Tests\Functional\WebTestCase; +use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\AccompanyingPeriod; +use Doctrine\ORM\EntityManagerInterface; +use Chill\MainBundle\Test\PrepareClientTrait; /** * This class tests entries are shown for closing and opening @@ -31,22 +33,20 @@ use Chill\PersonBundle\Entity\AccompanyingPeriod; * @author Julien Fastré * @author Champs Libres */ -class TimelineAccompanyingPeriodTest extends \Chill\PersonBundle\Tests\Controller\AccompanyingPeriodControllerTest +class TimelineAccompanyingPeriodTest extends WebTestCase { - public function testEntriesAreShown() + use PrepareClientTrait; + + /** + * @dataProvider provideDataPersonWithAccompanyingPeriod + */ + public function testEntriesAreShown($personId) { - $this->generatePeriods(array( - [ - 'openingDate' => '2014-01-01', - 'closingDate' => '2014-12-31', - 'closingMotive' => $this->getRandomClosingMotive() - ] - )); + $client = $this->getClientAuthenticated(); + + $crawler = $client->request('GET', "/en/person/{$personId}/timeline"); - $crawler = $this->client->request('GET', '/en/person/' - .$this->person->getId().'/timeline'); - - $this->assertTrue($this->client->getResponse()->isSuccessful(), + $this->assertTrue($client->getResponse()->isSuccessful(), "the timeline page loads sucessfully"); $this->assertGreaterThan(0, $crawler->filter('.timeline div')->count(), "the timeline page contains multiple div inside a .timeline element"); @@ -57,5 +57,34 @@ class TimelineAccompanyingPeriodTest extends \Chill\PersonBundle\Tests\Controlle $crawler->Filter('.timeline')->text(), "the text 'Une période d'accompagnement a été fermée' is present"); } + + public function provideDataPersonWithAccompanyingPeriod() + { + self::bootKernel(); + + $qb = self::$container->get(EntityManagerInterface::class) + ->createQueryBuilder() + ; + $personIds = $qb + ->from(Person::class, 'p') + ->join('p.accompanyingPeriodParticipations', 'part') + ->join('part.accompanyingPeriod', 'period') + ->join('p.center', 'center') + ->select('p.id') + ->where($qb->expr()->isNotNull('period.closingDate')) + ->andWhere($qb->expr()->eq('center.name', ':center')) + ->setParameter('center', 'Center A') + ->setMaxResults(1000) + ->getQuery() + ->getResult() + ; + + \shuffle($personIds); + + yield [ \array_pop($personIds)['id'] ]; + yield [ \array_pop($personIds)['id'] ]; + yield [ \array_pop($personIds)['id'] ]; + + } }