mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-14 14:24:24 +00:00
validation attempt with assert\callback: still doesn't work
This commit is contained in:
parent
acacef936c
commit
c527b1b3cf
@ -49,10 +49,6 @@ use UnexpectedValueException;
|
|||||||
* "accompanying_period": AccompanyingPeriod::class
|
* "accompanying_period": AccompanyingPeriod::class
|
||||||
* })
|
* })
|
||||||
* @Assert\GroupSequenceProvider
|
* @Assert\GroupSequenceProvider
|
||||||
* @Assert\Expression(
|
|
||||||
* "this.isConfidential && this.getUser && this.getStep === 'CONFIRMED'",
|
|
||||||
* message="If the accompanying course is confirmed and confidential, a referrer must remain assigned."
|
|
||||||
* )
|
|
||||||
*/
|
*/
|
||||||
class AccompanyingPeriod implements
|
class AccompanyingPeriod implements
|
||||||
TrackCreationInterface,
|
TrackCreationInterface,
|
||||||
@ -860,7 +856,7 @@ class AccompanyingPeriod implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validation function.
|
* Validation functions.
|
||||||
*/
|
*/
|
||||||
public function isDateConsistent(ExecutionContextInterface $context)
|
public function isDateConsistent(ExecutionContextInterface $context)
|
||||||
{
|
{
|
||||||
@ -875,6 +871,21 @@ class AccompanyingPeriod implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function isEmergency(): bool
|
public function isEmergency(): bool
|
||||||
{
|
{
|
||||||
return $this->emergency;
|
return $this->emergency;
|
||||||
|
@ -10,6 +10,8 @@
|
|||||||
namespace Chill\PersonBundle\Tests\AccompanyingPeriod;
|
namespace Chill\PersonBundle\Tests\AccompanyingPeriod;
|
||||||
|
|
||||||
use Chill\MainBundle\Entity\User;
|
use Chill\MainBundle\Entity\User;
|
||||||
|
use Chill\MainBundle\Entity\Scope;
|
||||||
|
use Chill\PersonBundle\Entity\AccompanyingPeriod\Origin;
|
||||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||||
@ -34,8 +36,13 @@ class AccompanyingPeriodConfidentialTest extends KernelTestCase
|
|||||||
$period = new AccompanyingPeriod();
|
$period = new AccompanyingPeriod();
|
||||||
$period->setConfidential(true);
|
$period->setConfidential(true);
|
||||||
$period->setStep('CONFIRMED');
|
$period->setStep('CONFIRMED');
|
||||||
|
$period->setIntensity('regular');
|
||||||
|
$period->setOrigin(new Origin());
|
||||||
|
$period->addScope(new Scope());
|
||||||
|
|
||||||
$violations = self::$validator->validate($period, []);
|
var_dump($period);
|
||||||
|
|
||||||
|
$violations = self::$validator->validate($period);
|
||||||
|
|
||||||
$this->assertCount(1, $violations);
|
$this->assertCount(1, $violations);
|
||||||
}
|
}
|
||||||
@ -45,9 +52,12 @@ class AccompanyingPeriodConfidentialTest extends KernelTestCase
|
|||||||
$period = new AccompanyingPeriod();
|
$period = new AccompanyingPeriod();
|
||||||
$period->setConfidential(true);
|
$period->setConfidential(true);
|
||||||
$period->setStep('CONFIRMED');
|
$period->setStep('CONFIRMED');
|
||||||
|
$period->setIntensity('regular');
|
||||||
|
$period->setOrigin(new Origin());
|
||||||
|
$period->addScope(new Scope());
|
||||||
$period->setUser(new User());
|
$period->setUser(new User());
|
||||||
|
|
||||||
$violations = self::$validator->validate($period, []);
|
$violations = self::$validator->validate($period);
|
||||||
|
|
||||||
$this->assertCount(0, $violations);
|
$this->assertCount(0, $violations);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user