|
|
|
@ -15,6 +15,7 @@ use Symfony\Component\Form\Extension\Validator\ViolationMapper\ViolationMapper;
|
|
|
|
|
use Symfony\Component\Form\Exception\TransformationFailedException;
|
|
|
|
|
use Symfony\Component\Form\CallbackTransformer;
|
|
|
|
|
use Symfony\Component\Form\Form;
|
|
|
|
|
use Symfony\Component\Form\FormInterface;
|
|
|
|
|
use Symfony\Component\Form\FormConfigBuilder;
|
|
|
|
|
use Symfony\Component\Form\FormError;
|
|
|
|
|
use Symfony\Component\PropertyAccess\PropertyPath;
|
|
|
|
@ -110,9 +111,12 @@ class ViolationMapperTest extends \PHPUnit_Framework_TestCase
|
|
|
|
|
/**
|
|
|
|
|
* @return FormError
|
|
|
|
|
*/
|
|
|
|
|
protected function getFormError(ConstraintViolationInterface $violation)
|
|
|
|
|
protected function getFormError(ConstraintViolationInterface $violation, FormInterface $form)
|
|
|
|
|
{
|
|
|
|
|
return new FormError($this->message, $this->messageTemplate, $this->params, null, $violation);
|
|
|
|
|
$error = new FormError($this->message, $this->messageTemplate, $this->params, null, $violation);
|
|
|
|
|
$error->setOrigin($form);
|
|
|
|
|
|
|
|
|
|
return $error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testMapToFormInheritingParentDataIfDataDoesNotMatch()
|
|
|
|
@ -130,7 +134,7 @@ class ViolationMapperTest extends \PHPUnit_Framework_TestCase
|
|
|
|
|
$this->mapper->mapViolation($violation, $parent);
|
|
|
|
|
|
|
|
|
|
$this->assertCount(0, $parent->getErrors(), $parent->getName().' should not have an error, but has one');
|
|
|
|
|
$this->assertEquals(array($this->getFormError($violation)), iterator_to_array($child->getErrors()), $child->getName().' should have an error, but has none');
|
|
|
|
|
$this->assertEquals(array($this->getFormError($violation, $child)), iterator_to_array($child->getErrors()), $child->getName().' should have an error, but has none');
|
|
|
|
|
$this->assertCount(0, $grandChild->getErrors(), $grandChild->getName().' should not have an error, but has one');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -159,7 +163,7 @@ class ViolationMapperTest extends \PHPUnit_Framework_TestCase
|
|
|
|
|
$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->assertEquals(array($this->getFormError($violation)), iterator_to_array($grandGrandChild->getErrors()), $grandGrandChild->getName().' should have an error, but has none');
|
|
|
|
|
$this->assertEquals(array($this->getFormError($violation, $grandGrandChild)), iterator_to_array($grandGrandChild->getErrors()), $grandGrandChild->getName().' should have an error, but has none');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testAbortMappingIfNotSynchronized()
|
|
|
|
@ -800,17 +804,17 @@ class ViolationMapperTest extends \PHPUnit_Framework_TestCase
|
|
|
|
|
$this->mapper->mapViolation($violation, $parent);
|
|
|
|
|
|
|
|
|
|
if (self::LEVEL_0 === $target) {
|
|
|
|
|
$this->assertEquals(array($this->getFormError($violation)), iterator_to_array($parent->getErrors()), $parent->getName().' should have an error, but has none');
|
|
|
|
|
$this->assertEquals(array($this->getFormError($violation, $parent)), iterator_to_array($parent->getErrors()), $parent->getName().' should have an error, but has none');
|
|
|
|
|
$this->assertCount(0, $child->getErrors(), $childName.' should not have an error, but has one');
|
|
|
|
|
$this->assertCount(0, $grandChild->getErrors(), $grandChildName.' should not have an error, but has one');
|
|
|
|
|
} elseif (self::LEVEL_1 === $target) {
|
|
|
|
|
$this->assertCount(0, $parent->getErrors(), $parent->getName().' should not have an error, but has one');
|
|
|
|
|
$this->assertEquals(array($this->getFormError($violation)), iterator_to_array($child->getErrors()), $childName.' should have an error, but has none');
|
|
|
|
|
$this->assertEquals(array($this->getFormError($violation, $child)), iterator_to_array($child->getErrors()), $childName.' should have an error, but has none');
|
|
|
|
|
$this->assertCount(0, $grandChild->getErrors(), $grandChildName.' should not have an error, but has one');
|
|
|
|
|
} else {
|
|
|
|
|
$this->assertCount(0, $parent->getErrors(), $parent->getName().' should not have an error, but has one');
|
|
|
|
|
$this->assertCount(0, $child->getErrors(), $childName.' should not have an error, but has one');
|
|
|
|
|
$this->assertEquals(array($this->getFormError($violation)), iterator_to_array($grandChild->getErrors()), $grandChildName.' should have an error, but has none');
|
|
|
|
|
$this->assertEquals(array($this->getFormError($violation, $grandChild)), iterator_to_array($grandChild->getErrors()), $grandChildName.' should have an error, but has none');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1274,17 +1278,17 @@ class ViolationMapperTest extends \PHPUnit_Framework_TestCase
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (self::LEVEL_0 === $target) {
|
|
|
|
|
$this->assertEquals(array($this->getFormError($violation)), iterator_to_array($parent->getErrors()), $parent->getName().' should have an error, but has none');
|
|
|
|
|
$this->assertEquals(array($this->getFormError($violation, $parent)), iterator_to_array($parent->getErrors()), $parent->getName().' should have an error, but has none');
|
|
|
|
|
$this->assertCount(0, $child->getErrors(), $childName.' should not have an error, but has one');
|
|
|
|
|
$this->assertCount(0, $grandChild->getErrors(), $grandChildName.' should not have an error, but has one');
|
|
|
|
|
} elseif (self::LEVEL_1 === $target) {
|
|
|
|
|
$this->assertCount(0, $parent->getErrors(), $parent->getName().' should not have an error, but has one');
|
|
|
|
|
$this->assertEquals(array($this->getFormError($violation)), iterator_to_array($child->getErrors()), $childName.' should have an error, but has none');
|
|
|
|
|
$this->assertEquals(array($this->getFormError($violation, $child)), iterator_to_array($child->getErrors()), $childName.' should have an error, but has none');
|
|
|
|
|
$this->assertCount(0, $grandChild->getErrors(), $grandChildName.' should not have an error, but has one');
|
|
|
|
|
} else {
|
|
|
|
|
$this->assertCount(0, $parent->getErrors(), $parent->getName().' should not have an error, but has one');
|
|
|
|
|
$this->assertCount(0, $child->getErrors(), $childName.' should not have an error, but has one');
|
|
|
|
|
$this->assertEquals(array($this->getFormError($violation)), iterator_to_array($grandChild->getErrors()), $grandChildName.' should have an error, but has none');
|
|
|
|
|
$this->assertEquals(array($this->getFormError($violation, $grandChild)), iterator_to_array($grandChild->getErrors()), $grandChildName.' should have an error, but has none');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1458,16 +1462,16 @@ class ViolationMapperTest extends \PHPUnit_Framework_TestCase
|
|
|
|
|
|
|
|
|
|
if (self::LEVEL_0 === $target) {
|
|
|
|
|
$this->assertCount(0, $errorChild->getErrors(), $errorName.' should not have an error, but has one');
|
|
|
|
|
$this->assertEquals(array($this->getFormError($violation)), iterator_to_array($parent->getErrors()), $parent->getName().' should have an error, but has none');
|
|
|
|
|
$this->assertEquals(array($this->getFormError($violation, $parent)), iterator_to_array($parent->getErrors()), $parent->getName().' should have an error, but has none');
|
|
|
|
|
$this->assertCount(0, $child->getErrors(), $childName.' should not have an error, but has one');
|
|
|
|
|
$this->assertCount(0, $grandChild->getErrors(), $grandChildName.' should not have an error, but has one');
|
|
|
|
|
} elseif (self::LEVEL_1 === $target) {
|
|
|
|
|
$this->assertCount(0, $errorChild->getErrors(), $errorName.' should not have an error, but has one');
|
|
|
|
|
$this->assertCount(0, $parent->getErrors(), $parent->getName().' should not have an error, but has one');
|
|
|
|
|
$this->assertEquals(array($this->getFormError($violation)), iterator_to_array($child->getErrors()), $childName.' should have an error, but has none');
|
|
|
|
|
$this->assertEquals(array($this->getFormError($violation, $child)), iterator_to_array($child->getErrors()), $childName.' should have an error, but has none');
|
|
|
|
|
$this->assertCount(0, $grandChild->getErrors(), $grandChildName.' should not have an error, but has one');
|
|
|
|
|
} elseif (self::LEVEL_1B === $target) {
|
|
|
|
|
$this->assertEquals(array($this->getFormError($violation)), iterator_to_array($errorChild->getErrors()), $errorName.' should have an error, but has none');
|
|
|
|
|
$this->assertEquals(array($this->getFormError($violation, $errorChild)), iterator_to_array($errorChild->getErrors()), $errorName.' should have an error, but has none');
|
|
|
|
|
$this->assertCount(0, $parent->getErrors(), $parent->getName().' should not have an error, but has one');
|
|
|
|
|
$this->assertCount(0, $child->getErrors(), $childName.' should not have an error, but has one');
|
|
|
|
|
$this->assertCount(0, $grandChild->getErrors(), $grandChildName.' should not have an error, but has one');
|
|
|
|
@ -1475,7 +1479,7 @@ class ViolationMapperTest extends \PHPUnit_Framework_TestCase
|
|
|
|
|
$this->assertCount(0, $errorChild->getErrors(), $errorName.' should not have an error, but has one');
|
|
|
|
|
$this->assertCount(0, $parent->getErrors(), $parent->getName().' should not have an error, but has one');
|
|
|
|
|
$this->assertCount(0, $child->getErrors(), $childName.' should not have an error, but has one');
|
|
|
|
|
$this->assertEquals(array($this->getFormError($violation)), iterator_to_array($grandChild->getErrors()), $grandChildName.' should have an error, but has none');
|
|
|
|
|
$this->assertEquals(array($this->getFormError($violation, $grandChild)), iterator_to_array($grandChild->getErrors()), $grandChildName.' should have an error, but has none');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1522,17 +1526,17 @@ class ViolationMapperTest extends \PHPUnit_Framework_TestCase
|
|
|
|
|
$this->mapper->mapViolation($violation, $parent);
|
|
|
|
|
|
|
|
|
|
if (self::LEVEL_0 === $target) {
|
|
|
|
|
$this->assertEquals(array($this->getFormError($violation)), iterator_to_array($parent->getErrors()), $parent->getName().' should have an error, but has none');
|
|
|
|
|
$this->assertEquals(array($this->getFormError($violation, $parent)), iterator_to_array($parent->getErrors()), $parent->getName().' should have an error, but has none');
|
|
|
|
|
$this->assertCount(0, $child->getErrors(), $childName.' should not have an error, but has one');
|
|
|
|
|
$this->assertCount(0, $grandChild->getErrors(), $grandChildName.' should not have an error, but has one');
|
|
|
|
|
} elseif (self::LEVEL_1 === $target) {
|
|
|
|
|
$this->assertCount(0, $parent->getErrors(), $parent->getName().' should not have an error, but has one');
|
|
|
|
|
$this->assertEquals(array($this->getFormError($violation)), iterator_to_array($child->getErrors()), $childName.' should have an error, but has none');
|
|
|
|
|
$this->assertEquals(array($this->getFormError($violation, $child)), iterator_to_array($child->getErrors()), $childName.' should have an error, but has none');
|
|
|
|
|
$this->assertCount(0, $grandChild->getErrors(), $grandChildName.' should not have an error, but has one');
|
|
|
|
|
} else {
|
|
|
|
|
$this->assertCount(0, $parent->getErrors(), $parent->getName().' should not have an error, but has one');
|
|
|
|
|
$this->assertCount(0, $child->getErrors(), $childName.' should not have an error, but has one');
|
|
|
|
|
$this->assertEquals(array($this->getFormError($violation)), iterator_to_array($grandChild->getErrors()), $grandChildName.' should have an error, but has none');
|
|
|
|
|
$this->assertEquals(array($this->getFormError($violation, $grandChild)), iterator_to_array($grandChild->getErrors()), $grandChildName.' should have an error, but has none');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|