From ea47138f8159fc58dd1af2b5b89a9dedff505979 Mon Sep 17 00:00:00 2001 From: Ghriim Date: Fri, 16 Dec 2016 15:54:49 +0100 Subject: [PATCH] [Form] Applying bug #18935 fix (done only on symfony/form, see https://github.com/symfony/form/commit/8502f30310c3bc0294d4c3e98f271c83bf89a210#diff-65e060c56a6fa2c4a1f057f79b70cbb4) --- .../ViolationMapper/ViolationMapper.php | 5 +--- .../ViolationMapper/ViolationMapperTest.php | 24 +++++++++---------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/Symfony/Component/Form/Extension/Validator/ViolationMapper/ViolationMapper.php b/src/Symfony/Component/Form/Extension/Validator/ViolationMapper/ViolationMapper.php index 14e7b521f17e..4b64386117f8 100644 --- a/src/Symfony/Component/Form/Extension/Validator/ViolationMapper/ViolationMapper.php +++ b/src/Symfony/Component/Form/Extension/Validator/ViolationMapper/ViolationMapper.php @@ -275,9 +275,6 @@ private function reconstructPath(ViolationPath $violationPath, FormInterface $or */ private function acceptsErrors(FormInterface $form) { - // 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()); + return $this->allowNonSynchronized || $form->isSynchronized(); } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Validator/ViolationMapper/ViolationMapperTest.php b/src/Symfony/Component/Form/Tests/Extension/Validator/ViolationMapper/ViolationMapperTest.php index 74da4aee1c28..5ba9222bdef1 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Validator/ViolationMapper/ViolationMapperTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Validator/ViolationMapper/ViolationMapperTest.php @@ -82,9 +82,9 @@ protected function getForm($name = 'name', $propertyPath = null, $dataClass = nu if (!$synchronized) { $config->addViewTransformer(new CallbackTransformer( - function ($normData) { return $normData; }, - function () { throw new TransformationFailedException(); } - )); + function ($normData) { return $normData; }, + function () { throw new TransformationFailedException(); } + )); } return new Form($config); @@ -212,7 +212,7 @@ public function testAbortDotRuleMappingIfNotSynchronized() $this->assertCount(0, $grandChild->getErrors(), $grandChild->getName().' should not have an error, but has one'); } - public function testAbortMappingIfNotSubmitted() + public function testMappingIfNotSubmitted() { $violation = $this->getConstraintViolation('children[address].data.street'); $parent = $this->getForm('parent'); @@ -230,12 +230,12 @@ public function testAbortMappingIfNotSubmitted() $this->mapper->mapViolation($violation, $parent); - $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, but has one'); - $this->assertCount(0, $grandChild->getErrors(), $grandChild->getName().' should not have an error, but has one'); + $this->assertCount(0, $parent->getErrors(), $parent->getName().' should not have an error'); + $this->assertCount(0, $child->getErrors(), $child->getName().' should not have an error'); + $this->assertCount(1, $grandChild->getErrors(), $grandChild->getName().' should have one error'); } - public function testAbortDotRuleMappingIfNotSubmitted() + public function testDotRuleMappingIfNotSubmitted() { $violation = $this->getConstraintViolation('data.address'); $parent = $this->getForm('parent'); @@ -255,9 +255,9 @@ public function testAbortDotRuleMappingIfNotSubmitted() $this->mapper->mapViolation($violation, $parent); - $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, but has one'); - $this->assertCount(0, $grandChild->getErrors(), $grandChild->getName().' should not have an error, but has one'); + $this->assertCount(0, $parent->getErrors(), $parent->getName().' should not have an error'); + $this->assertCount(0, $child->getErrors(), $child->getName().' should not have an error'); + $this->assertCount(1, $grandChild->getErrors(), $grandChild->getName().' should have an error'); } public function provideDefaultTests() @@ -1577,4 +1577,4 @@ public function testBacktrackIfSeveralSubFormsWithSamePropertyPath() $this->assertEquals(array($this->getFormError($violation2, $grandChild2)), iterator_to_array($grandChild2->getErrors()), $grandChild2->getName().' should have an error, but has none'); $this->assertEquals(array($this->getFormError($violation3, $grandChild3)), iterator_to_array($grandChild3->getErrors()), $grandChild3->getName().' should have an error, but has none'); } -} +} \ No newline at end of file