action: confirm accompanying period + create workflow

This commit is contained in:
2021-05-19 13:20:59 +02:00
parent 04e9e30972
commit 22aa4afc02
6 changed files with 203 additions and 20 deletions

View File

@@ -43,6 +43,10 @@ class AccompanyingCourseApiControllerTest extends WebTestCase
{
protected static EntityManagerInterface $em;
protected ?int $personId = NULL;
protected ?AccompanyingPeriod $period = NULL;
/**
* Setup before the first test of this class (see phpunit doc)
*/
@@ -302,6 +306,22 @@ class AccompanyingCourseApiControllerTest extends WebTestCase
$this->assertNull($period->getRequestor());
}
/**
* @dataProvider dataGenerateNewAccompanyingCourse
*/
public function testConfirm(AccompanyingPeriod $period)
{
$this->client->request(
Request::METHOD_POST,
sprintf('/api/1.0/person/accompanying-course/%d/confirm.json', $period->getId())
);
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
// add period to remove it in tear down
$this->period = $period;
}
/**
*
* @dataProvider dataGenerateRandomAccompanyingCourse
@@ -439,25 +459,32 @@ class AccompanyingCourseApiControllerTest extends WebTestCase
protected function tearDown()
{
// remove participation created during test 'testAccompanyingCourseAddParticipation'
// and if the test could not remove it
$testAddParticipationName = 'testAccompanyingCourseAddParticipation';
if ($testAddParticipationName !== \substr($this->getName(), 0, \strlen($testAddParticipationName))) {
return;
}
$em = static::$container->get(EntityManagerInterface::class);
$participation = $em
->getRepository(AccompanyingPeriodParticipation::class)
->findOneBy(['person' => $this->personId, 'accompanyingPeriod' => $this->period])
;
// remove participation if set
if ($this->personId && $this->period) {
$participation = $em
->getRepository(AccompanyingPeriodParticipation::class)
->findOneBy(['person' => $this->personId, 'accompanyingPeriod' => $this->period])
;
if (NULL !== $participation) {
$em->remove($participation);
$em->flush();
if (NULL !== $participation) {
$em->remove($participation);
$em->flush();
}
$this->personId = NULL;
$this->period = NULL;
} elseif ($this->period) {
$period = $em
->getRepository(AccompanyingPeriod::class)
->find($this->period->getId()) ;
if ($period !== NULL) {
$em->remove($period);
$em->flush();
}
$this->period = null;
}
}
@@ -550,4 +577,38 @@ class AccompanyingCourseApiControllerTest extends WebTestCase
}
}
public function dataGenerateNewAccompanyingCourse()
{
self::bootKernel();
$em = self::$container->get(EntityManagerInterface::class);
$period = new AccompanyingPeriod(new \DateTime('1 week ago'));
$user = $em->getRepository(User::class)
->findOneByUsernameCanonical('center a_social');
$period->setCreatedBy($user);
//$period->setCreatedAt(new \DateTime('yesterday'));
$center = $em->getRepository(Center::class)
->findOneBy(array('name' => 'Center A'));
$personIds = $em->createQuery("SELECT p.id FROM ".
Person::class." p ".
" WHERE p.center = :center")
->setParameter('center', $center)
->setMaxResults(100)
->getScalarResult();
// create a random order
shuffle($personIds);
for ($i = 0; $i<2; $i++) {
$person = $em->getRepository(Person::class)->find(\array_pop($personIds));
$period->addPerson($person);
}
$em->persist($period);
$em->flush();
yield [ $period ];
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace Chill\PersonBundle\Tests\Workflows;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Workflow\Registry;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
class AccompanyingPeriodLifecycle extends KernelTestCase
{
protected function setUp()
{
self::bootKernel();
}
public function testConfirm()
{
$registry = self::$container->get(Registry::class);
$period = new AccompanyingPeriod(new \DateTime('now'));
$workflow = $registry->get($period);
$this->assertArrayHasKey('DRAFT', $workflow->getMarking($period)->getPlaces());
$this->assertTrue($workflow->can($period, 'confirm'));
}
}