Skip to content

Commit

Permalink
[Form] added missing DelegatingValidator registration in the Form Ext…
Browse files Browse the repository at this point in the history
…ension class (used when using the Form component outside a Symfony2 project where the validation.xml is used instead)
  • Loading branch information
fabpot committed Aug 22, 2011
1 parent 1fa6fa2 commit 2b1bb2c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Expand Up @@ -14,6 +14,8 @@
use Symfony\Component\Form\Extension\Validator\Type;
use Symfony\Component\Form\AbstractExtension;
use Symfony\Component\Validator\ValidatorInterface;
use Symfony\Component\Validator\Constraints\Callback;
use Symfony\Component\Validator\Constraints\Valid;

class ValidatorExtension extends AbstractExtension
{
Expand All @@ -22,6 +24,10 @@ class ValidatorExtension extends AbstractExtension
public function __construct(ValidatorInterface $validator)
{
$this->validator = $validator;

$metadata = $this->validator->getMetadataFactory()->getClassMetadata('Symfony\Component\Form\Form');
$metadata->addConstraint(new Callback(array(array('Symfony\Component\Form\Extension\Validator\Validator\DelegatingValidator', 'validateFormData'))));
$metadata->addPropertyConstraint('children', new Valid());
}

public function loadTypeGuesser()
Expand Down
Expand Up @@ -21,6 +21,10 @@ abstract class TypeTestCase extends BaseTestCase
protected function setUp()
{
$this->validator = $this->getMock('Symfony\Component\Validator\ValidatorInterface');
$metadataFactory = $this->getMock('Symfony\Component\Validator\Mapping\ClassMetadataFactoryInterface');
$this->validator->expects($this->once())->method('getMetadataFactory')->will($this->returnValue($metadataFactory));
$metadata = $this->getMockBuilder('Symfony\Component\Validator\Mapping\ClassMetadata')->disableOriginalConstructor()->getMock();
$metadataFactory->expects($this->once())->method('getClassMetadata')->will($this->returnValue($metadata));

parent::setUp();
}
Expand Down

0 comments on commit 2b1bb2c

Please sign in to comment.