Revert "bug #18935 [Form] Consider a violation even if the form is not submitted (egeloen)"

This reverts commit f28eb9a617, reversing
changes made to bbb75faa15.
This commit is contained in:
Fabien Potencier 2016-08-29 09:54:06 -07:00
parent e4b48bbc88
commit bcb1d8fd0c
2 changed files with 12 additions and 9 deletions

View File

@ -275,6 +275,9 @@ class ViolationMapper implements ViolationMapperInterface
*/ */
private function acceptsErrors(FormInterface $form) private function acceptsErrors(FormInterface $form)
{ {
return $this->allowNonSynchronized || $form->isSynchronized(); // Ignore non-submitted forms. This happens, for example, in PATCH
// requests.
// https://github.com/symfony/symfony/pull/10567
return $form->isSubmitted() && ($this->allowNonSynchronized || $form->isSynchronized());
} }
} }

View File

@ -212,7 +212,7 @@ class ViolationMapperTest extends \PHPUnit_Framework_TestCase
$this->assertCount(0, $grandChild->getErrors(), $grandChild->getName().' should not have an error, but has one'); $this->assertCount(0, $grandChild->getErrors(), $grandChild->getName().' should not have an error, but has one');
} }
public function testMappingIfNotSubmitted() public function testAbortMappingIfNotSubmitted()
{ {
$violation = $this->getConstraintViolation('children[address].data.street'); $violation = $this->getConstraintViolation('children[address].data.street');
$parent = $this->getForm('parent'); $parent = $this->getForm('parent');
@ -230,12 +230,12 @@ class ViolationMapperTest extends \PHPUnit_Framework_TestCase
$this->mapper->mapViolation($violation, $parent); $this->mapper->mapViolation($violation, $parent);
$this->assertCount(0, $parent->getErrors(), $parent->getName().' should not have an error'); $this->assertCount(0, $parent->getErrors(), $parent->getName().' should not have an error, but has one');
$this->assertCount(0, $child->getErrors(), $child->getName().' should not have an error'); $this->assertCount(0, $child->getErrors(), $child->getName().' should not have an error, but has one');
$this->assertCount(1, $grandChild->getErrors(), $grandChild->getName().' should have one error'); $this->assertCount(0, $grandChild->getErrors(), $grandChild->getName().' should not have an error, but has one');
} }
public function testDotRuleMappingIfNotSubmitted() public function testAbortDotRuleMappingIfNotSubmitted()
{ {
$violation = $this->getConstraintViolation('data.address'); $violation = $this->getConstraintViolation('data.address');
$parent = $this->getForm('parent'); $parent = $this->getForm('parent');
@ -255,9 +255,9 @@ class ViolationMapperTest extends \PHPUnit_Framework_TestCase
$this->mapper->mapViolation($violation, $parent); $this->mapper->mapViolation($violation, $parent);
$this->assertCount(0, $parent->getErrors(), $parent->getName().' should not have an error'); $this->assertCount(0, $parent->getErrors(), $parent->getName().' should not have an error, but has one');
$this->assertCount(0, $child->getErrors(), $child->getName().' should not have an error'); $this->assertCount(0, $child->getErrors(), $child->getName().' should not have an error, but has one');
$this->assertCount(1, $grandChild->getErrors(), $grandChild->getName().' should have an error'); $this->assertCount(0, $grandChild->getErrors(), $grandChild->getName().' should not have an error, but has one');
} }
public function provideDefaultTests() public function provideDefaultTests()