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'] ]; + + } }