mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 21:34:25 +00:00
add test for accompanying period location validity
This commit is contained in:
parent
a3a5d5cfd0
commit
8d2b1fbe13
@ -0,0 +1,122 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Chill\PersonBundle\Tests\Validator\AccompanyingPeriod;
|
||||||
|
|
||||||
|
use Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod\LocationValidityValidator;
|
||||||
|
use Chill\PersonBundle\Templating\Entity\PersonRender;
|
||||||
|
use Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod\LocationValidity;
|
||||||
|
use Chill\PersonBundle\Entity\Person;
|
||||||
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||||
|
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
|
||||||
|
|
||||||
|
class LocationValidityValidatorTest extends ConstraintValidatorTestCase
|
||||||
|
{
|
||||||
|
public function testValidAddress()
|
||||||
|
{
|
||||||
|
$constraint = $this->getConstraint();
|
||||||
|
|
||||||
|
$period = new AccompanyingPeriod();
|
||||||
|
$person = new Person();
|
||||||
|
$period->addPerson($person);
|
||||||
|
|
||||||
|
$period->setPersonLocation($person);
|
||||||
|
|
||||||
|
$this->validator->validate($period, $constraint);
|
||||||
|
|
||||||
|
$this->assertNoViolation();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPeriodDoesNotContainsPersonOnRemovedPerson()
|
||||||
|
{
|
||||||
|
$constraint = $this->getConstraint();
|
||||||
|
|
||||||
|
$period = new AccompanyingPeriod();
|
||||||
|
$person1 = new Person();
|
||||||
|
$period->addPerson($person1);
|
||||||
|
|
||||||
|
$period->setPersonLocation($person1);
|
||||||
|
|
||||||
|
$period->removePerson($person1);
|
||||||
|
|
||||||
|
$this->validator->validate($period, $constraint);
|
||||||
|
|
||||||
|
$this->buildViolation('messagePersonLocatedMustBeAssociated')
|
||||||
|
->setParameters([
|
||||||
|
'{{ person_name }}' => 'name'
|
||||||
|
])
|
||||||
|
->assertRaised()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPeriodDoesNotContainsPersonOnOtherPerson()
|
||||||
|
{
|
||||||
|
$constraint = $this->getConstraint();
|
||||||
|
|
||||||
|
$period = new AccompanyingPeriod();
|
||||||
|
$person1 = new Person();
|
||||||
|
$person2 = new Person();
|
||||||
|
$period->addPerson($person1);
|
||||||
|
|
||||||
|
$period->setPersonLocation($person2);
|
||||||
|
|
||||||
|
$this->validator->validate($period, $constraint);
|
||||||
|
|
||||||
|
$this->buildViolation('messagePersonLocatedMustBeAssociated')
|
||||||
|
->setParameters([
|
||||||
|
'{{ person_name }}' => 'name'
|
||||||
|
])
|
||||||
|
->assertRaised()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPeriodDoesNotContainsPersonOnAnyPerson()
|
||||||
|
{
|
||||||
|
$constraint = $this->getConstraint();
|
||||||
|
|
||||||
|
$period = new AccompanyingPeriod();
|
||||||
|
$person1 = new Person();
|
||||||
|
$period->setPersonLocation($person1);
|
||||||
|
|
||||||
|
$this->validator->validate($period, $constraint);
|
||||||
|
|
||||||
|
$this->buildViolation('messagePersonLocatedMustBeAssociated')
|
||||||
|
->setParameters([
|
||||||
|
'{{ person_name }}' => 'name'
|
||||||
|
])
|
||||||
|
->assertRaised()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testRemoveLocationOnPeriodValidated()
|
||||||
|
{
|
||||||
|
$constraint = $this->getConstraint();
|
||||||
|
|
||||||
|
$period = new AccompanyingPeriod();
|
||||||
|
$period->setStep('not draft');
|
||||||
|
|
||||||
|
$this->validator->validate($period, $constraint);
|
||||||
|
|
||||||
|
$this->buildViolation('messagePeriodMustRemainsLocated')
|
||||||
|
->assertRaised()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getConstraint()
|
||||||
|
{
|
||||||
|
return new LocationValidity([
|
||||||
|
'messagePersonLocatedMustBeAssociated' => 'messagePersonLocatedMustBeAssociated',
|
||||||
|
'messagePeriodMustRemainsLocated' => 'messagePeriodMustRemainsLocated'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function createValidator()
|
||||||
|
{
|
||||||
|
$render= $this->createMock(PersonRender::class);
|
||||||
|
$render->method('renderString')
|
||||||
|
->willReturn('name')
|
||||||
|
;
|
||||||
|
|
||||||
|
return new LocationValidityValidator($render);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -11,7 +11,7 @@ class LocationValidity extends Constraint
|
|||||||
{
|
{
|
||||||
public $messagePersonLocatedMustBeAssociated = "The person where the course is located must be associated to the course. Change course's location before removing the person.";
|
public $messagePersonLocatedMustBeAssociated = "The person where the course is located must be associated to the course. Change course's location before removing the person.";
|
||||||
|
|
||||||
public $messagPeriodMustRemainsLocated = "The period must remains located";
|
public $messagePeriodMustRemainsLocated = "The period must remains located";
|
||||||
|
|
||||||
public function getTargets()
|
public function getTargets()
|
||||||
{
|
{
|
||||||
|
@ -42,10 +42,12 @@ class LocationValidityValidator extends ConstraintValidator
|
|||||||
|
|
||||||
if ($period->getStep() !== AccompanyingPeriod::STEP_DRAFT
|
if ($period->getStep() !== AccompanyingPeriod::STEP_DRAFT
|
||||||
&& $period->getLocationStatus() === 'none') {
|
&& $period->getLocationStatus() === 'none') {
|
||||||
$this->context->buildViolation($constraint->messagePeriodMustRemainsLocated
|
$this->context
|
||||||
->addViolation()
|
->buildViolation(
|
||||||
;
|
$constraint->messagePeriodMustRemainsLocated
|
||||||
|
)
|
||||||
|
->addViolation()
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user