Skip to content

Commit

Permalink
[Form] fixed more cases where the delegating validator did not match …
Browse files Browse the repository at this point in the history
…the validator paths
  • Loading branch information
fabpot committed Jun 10, 2011
1 parent 1daca76 commit 03a0566
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
Expand Up @@ -183,9 +183,12 @@ private function buildDataPathMapping(FormInterface $form, array &$mapping, $dat
$nestedNamePath = $namePath . '.' . $child->getName();

if (strpos($path, '[') === 0) {
$nestedDataPath = $dataPath . $path;
$nestedDataPaths = array($dataPath . $path);
} else {
$nestedDataPath = $dataPath . '.' . $path;
$nestedDataPaths = array($dataPath . '.' . $path);
if ($child->hasChildren()) {
$nestedDataPaths[] = $dataPath . '[' . $path . ']';
}
}

if ($child->hasChildren()) {
Expand All @@ -195,10 +198,14 @@ private function buildDataPathMapping(FormInterface $form, array &$mapping, $dat
$this->buildDataPathMapping($child, $mapping, $dataPath, $nestedNamePath);
}

$this->buildDataPathMapping($child, $mapping, $nestedDataPath, $nestedNamePath);
foreach ($nestedDataPaths as $nestedDataPath) {
$this->buildDataPathMapping($child, $mapping, $nestedDataPath, $nestedNamePath);
}
}

$mapping['/^'.preg_quote($nestedDataPath, '/').'(?!\w)/'] = $child;
foreach ($nestedDataPaths as $nestedDataPath) {
$mapping['/^'.preg_quote($nestedDataPath, '/').'(?!\w)/'] = $child;
}
}
}

Expand Down
Expand Up @@ -369,6 +369,28 @@ public function testDataErrorsOnGrandChild2()
$this->assertEquals(array($this->getFormError()), $grandChild->getErrors());
}

public function testDataErrorsOnGrandChild3()
{
$parent = $this->getForm();
$child = $this->getForm('address');
$grandChild = $this->getForm('street');

$parent->add($child);
$child->add($grandChild);

$this->delegate->expects($this->once())
->method('validate')
->will($this->returnValue(array(
$this->getConstraintViolation('data[address].street.constrainedProp')
)));

$this->validator->validate($parent);

$this->assertFalse($parent->hasErrors());
$this->assertFalse($child->hasErrors());
$this->assertEquals(array($this->getFormError()), $grandChild->getErrors());
}

public function testDataErrorsOnParentIfNoChildFound()
{
$parent = $this->getForm();
Expand Down

0 comments on commit 03a0566

Please sign in to comment.