[Form] Fixed: ChoiceFields never validated
This commit is contained in:
parent
6ed7dc1e5a
commit
2276b98fc1
@ -855,28 +855,29 @@ class Form extends Field implements \IteratorAggregate, FormInterface
|
|||||||
*/
|
*/
|
||||||
public function validateData(ExecutionContext $context)
|
public function validateData(ExecutionContext $context)
|
||||||
{
|
{
|
||||||
$groups = $this->getValidationGroups();
|
if (is_object($this->getData()) || is_array($this->getData())) {
|
||||||
$propertyPath = $context->getPropertyPath();
|
$groups = $this->getValidationGroups();
|
||||||
$graphWalker = $context->getGraphWalker();
|
$propertyPath = $context->getPropertyPath();
|
||||||
|
$graphWalker = $context->getGraphWalker();
|
||||||
|
|
||||||
if (null === $groups) {
|
if (null === $groups) {
|
||||||
$groups = array(null);
|
$groups = array(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The Execute constraint is called on class level, so we need to
|
// The Execute constraint is called on class level, so we need to
|
||||||
// set the property manually
|
// set the property manually
|
||||||
$context->setCurrentProperty('data');
|
$context->setCurrentProperty('data');
|
||||||
|
|
||||||
// Adjust the property path accordingly
|
// Adjust the property path accordingly
|
||||||
if (!empty($propertyPath)) {
|
if (!empty($propertyPath)) {
|
||||||
$propertyPath .= '.';
|
$propertyPath .= '.';
|
||||||
}
|
}
|
||||||
|
|
||||||
$propertyPath .= 'data';
|
$propertyPath .= 'data';
|
||||||
|
|
||||||
foreach ($groups as $group) {
|
foreach ($groups as $group) {
|
||||||
// Don't use potential overridden versions of getData()!
|
$graphWalker->walkReference($this->getData(), $group, $propertyPath, true);
|
||||||
$graphWalker->walkReference(Form::getData(), $group, $propertyPath, true);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1111,6 +1111,25 @@ class FormTest extends \PHPUnit_Framework_TestCase
|
|||||||
$form->validateData($context);
|
$form->validateData($context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testValidateDataDoesNotWalkScalars()
|
||||||
|
{
|
||||||
|
$graphWalker = $this->createMockGraphWalker();
|
||||||
|
$metadataFactory = $this->createMockMetadataFactory();
|
||||||
|
$context = new ExecutionContext('Root', $graphWalker, $metadataFactory);
|
||||||
|
$valueTransformer = $this->createMockTransformer();
|
||||||
|
$form = new Form('author', array('value_transformer' => $valueTransformer));
|
||||||
|
|
||||||
|
$graphWalker->expects($this->never())
|
||||||
|
->method('walkReference');
|
||||||
|
|
||||||
|
$valueTransformer->expects($this->atLeastOnce())
|
||||||
|
->method('reverseTransform')
|
||||||
|
->will($this->returnValue('foobar'));
|
||||||
|
|
||||||
|
$form->submit(array('foo' => 'bar')); // reverse transformed to "foobar"
|
||||||
|
$form->validateData($context);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a group containing two fields, "visibleField" and "hiddenField"
|
* Create a group containing two fields, "visibleField" and "hiddenField"
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user