diff --git a/CHANGELOG.md b/CHANGELOG.md index a0a6019f1..4155d66a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -259,6 +259,7 @@ and this project adheres to * add an endpoint for checking permissions. See https://gitlab.com/Chill-Projet/chill-bundles/-/merge_requests/232 * [activity] for a new activity: suggest and create on-the-fly locations based on the accompanying course location + location of the suggested parties * [calendar] for a new rdv: suggest and create on-the-fly locations based on the accompanying course location + location of the suggested parties +* [period] Validation added when period is confidential and confirmed -> user cannot be null. ## Test releases diff --git a/composer b/composer new file mode 100755 index 000000000..0e7ab8212 Binary files /dev/null and b/composer differ diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php index 2550483ef..b5df81ce3 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php @@ -500,6 +500,20 @@ class AccompanyingPeriod implements return end($periods) === $this; } + /** + * @Assert\Callback + */ + public function canUserBeNull(ExecutionContextInterface $context) + { + if ($this->getStep() === self::STEP_CONFIRMED && $this->isConfidential() === true) { + if (!$this->getUser()) { + $context->buildViolation('User cannot be null for an accompanying period that is confirmed and confidential') + ->atPath('user') + ->addViolation(); + } + } + } + /** * Close a participation for a person. * @@ -938,7 +952,7 @@ class AccompanyingPeriod implements } /** - * Validation function. + * Validation functions. */ public function isDateConsistent(ExecutionContextInterface $context) { diff --git a/src/Bundle/ChillPersonBundle/Tests/AccompanyingPeriod/AccompanyingPeriodConfidentialTest.php b/src/Bundle/ChillPersonBundle/Tests/AccompanyingPeriod/AccompanyingPeriodConfidentialTest.php index 2dc51335c..c6da43174 100644 --- a/src/Bundle/ChillPersonBundle/Tests/AccompanyingPeriod/AccompanyingPeriodConfidentialTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/AccompanyingPeriod/AccompanyingPeriodConfidentialTest.php @@ -11,11 +11,12 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\AccompanyingPeriod; +use Chill\MainBundle\Entity\Scope; use Chill\MainBundle\Entity\User; use Chill\PersonBundle\Entity\AccompanyingPeriod; -use Chill\PersonBundle\Entity\Person; -use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; -use Symfony\Component\HttpFoundation\Request; +use Chill\PersonBundle\Entity\AccompanyingPeriod\Origin; +use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; +use Symfony\Component\Validator\Validator\ValidatorInterface; /** * @internal @@ -42,7 +43,7 @@ final class AccompanyingPeriodConfidentialTest extends WebTestCase ]); } - public function dataGenerateRandomAccompanyingCourse() + public function testConfidentialInvalid() { // Disabling this dataprovider to avoid having errors while running the test. return yield from []; @@ -88,10 +89,7 @@ final class AccompanyingPeriodConfidentialTest extends WebTestCase } } - /** - * @dataProvider dataGenerateRandomAccompanyingCourse - */ - public function testRemoveUserWhenConfidential(int $periodId) + public function testConfidentialValid() { $this->markTestIncomplete( 'Marked as incomplete because of a problem in the dataprovider, at line 81.' @@ -101,8 +99,7 @@ final class AccompanyingPeriodConfidentialTest extends WebTestCase ->find($periodId); $em = self::$kernel->getContainer()->get('doctrine.orm.entity_manager'); - $isConfidential = $period->isConfidential(); - $step = $period->getStep(); + $violations = self::$validator->validate($period, null, ['confirmed']); $initialUser = $period->getUser();