X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=vendor%2Fsymfony%2Fvalidator%2FTests%2FValidator%2FRecursiveValidatorTest.php;fp=vendor%2Fsymfony%2Fvalidator%2FTests%2FValidator%2FRecursiveValidatorTest.php;h=9e0afe06390beb60127e28b43986e3bebb377f39;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hp=0000000000000000000000000000000000000000;hpb=aea91e65e895364e460983b890e295aa5d5540a5;p=yaffs-website diff --git a/vendor/symfony/validator/Tests/Validator/RecursiveValidatorTest.php b/vendor/symfony/validator/Tests/Validator/RecursiveValidatorTest.php new file mode 100644 index 000000000..9e0afe063 --- /dev/null +++ b/vendor/symfony/validator/Tests/Validator/RecursiveValidatorTest.php @@ -0,0 +1,98 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Validator\Tests\Validator; + +use Symfony\Component\Translation\IdentityTranslator; +use Symfony\Component\Validator\ConstraintValidatorFactory; +use Symfony\Component\Validator\Context\ExecutionContextFactory; +use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface; +use Symfony\Component\Validator\Tests\Constraints\Fixtures\ChildA; +use Symfony\Component\Validator\Tests\Constraints\Fixtures\ChildB; +use Symfony\Component\Validator\Tests\Fixtures\Entity; +use Symfony\Component\Validator\Validator\RecursiveValidator; + +class RecursiveValidatorTest extends AbstractTest +{ + protected function createValidator(MetadataFactoryInterface $metadataFactory, array $objectInitializers = array()) + { + $translator = new IdentityTranslator(); + $translator->setLocale('en'); + + $contextFactory = new ExecutionContextFactory($translator); + $validatorFactory = new ConstraintValidatorFactory(); + + return new RecursiveValidator($contextFactory, $metadataFactory, $validatorFactory, $objectInitializers); + } + + public function testEmptyGroupsArrayDoesNotTriggerDeprecation() + { + $entity = new Entity(); + $childA = new ChildA(); + $childB = new ChildB(); + $childA->name = false; + $childB->name = 'fake'; + $entity->childA = array($childA); + $entity->childB = array($childB); + $validatorContext = $this->getMockBuilder('Symfony\Component\Validator\Validator\ContextualValidatorInterface')->getMock(); + $validatorContext + ->expects($this->once()) + ->method('validate') + ->with($entity, null, array()) + ->willReturnSelf(); + + $validator = $this + ->getMockBuilder('Symfony\Component\Validator\Validator\RecursiveValidator') + ->disableOriginalConstructor() + ->setMethods(array('startContext')) + ->getMock(); + $validator + ->expects($this->once()) + ->method('startContext') + ->willReturn($validatorContext); + + $validator->validate($entity, null, array()); + } + + public function testRelationBetweenChildAAndChildB() + { + $entity = new Entity(); + $childA = new ChildA(); + $childB = new ChildB(); + + $childA->childB = $childB; + $childB->childA = $childA; + + $childA->name = false; + $childB->name = 'fake'; + $entity->childA = array($childA); + $entity->childB = array($childB); + + $validatorContext = $this->getMockBuilder('Symfony\Component\Validator\Validator\ContextualValidatorInterface')->getMock(); + $validatorContext + ->expects($this->once()) + ->method('validate') + ->with($entity, null, array()) + ->willReturnSelf(); + + $validator = $this + ->getMockBuilder('Symfony\Component\Validator\Validator\RecursiveValidator') + ->disableOriginalConstructor() + ->setMethods(array('startContext')) + ->getMock(); + $validator + ->expects($this->once()) + ->method('startContext') + ->willReturn($validatorContext); + + $validator->validate($entity, null, array()); + } +}