fix test for accompanying period

This commit is contained in:
Julien Fastré 2021-07-20 22:43:12 +02:00
parent 19bfeacc9a
commit 81a8a6ed03

View File

@ -20,9 +20,11 @@
namespace Chill\PersonBundle\Tests\Timeline; 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\Person;
use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Doctrine\ORM\EntityManagerInterface;
use Chill\MainBundle\Test\PrepareClientTrait;
/** /**
* This class tests entries are shown for closing and opening * This class tests entries are shown for closing and opening
@ -31,22 +33,20 @@ use Chill\PersonBundle\Entity\AccompanyingPeriod;
* @author Julien Fastré <julien.fastre@champs-libres.coop> * @author Julien Fastré <julien.fastre@champs-libres.coop>
* @author Champs Libres <info@champs-libres.coop> * @author Champs Libres <info@champs-libres.coop>
*/ */
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( $client = $this->getClientAuthenticated();
[
'openingDate' => '2014-01-01', $crawler = $client->request('GET', "/en/person/{$personId}/timeline");
'closingDate' => '2014-12-31',
'closingMotive' => $this->getRandomClosingMotive()
]
));
$crawler = $this->client->request('GET', '/en/person/' $this->assertTrue($client->getResponse()->isSuccessful(),
.$this->person->getId().'/timeline');
$this->assertTrue($this->client->getResponse()->isSuccessful(),
"the timeline page loads sucessfully"); "the timeline page loads sucessfully");
$this->assertGreaterThan(0, $crawler->filter('.timeline div')->count(), $this->assertGreaterThan(0, $crawler->filter('.timeline div')->count(),
"the timeline page contains multiple div inside a .timeline element"); "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(), $crawler->Filter('.timeline')->text(),
"the text 'Une période d'accompagnement a été fermée' is present"); "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'] ];
}
} }