mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
add test for accompanying period location validity
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user