[Form] Fixed TransformationFailedExceptions to be caught in the model transformers
This commit is contained in:
parent
f06203a640
commit
c919b81ca9
@ -156,3 +156,4 @@ CHANGELOG
|
|||||||
consumed by HTML5 browsers, if the widget is "single_text"
|
consumed by HTML5 browsers, if the widget is "single_text"
|
||||||
* deprecated the options "data_timezone" and "user_timezone" in DateType, DateTimeType and TimeType
|
* deprecated the options "data_timezone" and "user_timezone" in DateType, DateTimeType and TimeType
|
||||||
and renamed them to "model_timezone" and "view_timezone"
|
and renamed them to "model_timezone" and "view_timezone"
|
||||||
|
* fixed: TransformationFailedExceptions thrown in the model transformer are now caught by the form
|
||||||
|
@ -544,11 +544,7 @@ class Form implements \IteratorAggregate, FormInterface
|
|||||||
try {
|
try {
|
||||||
// Normalize data to unified representation
|
// Normalize data to unified representation
|
||||||
$normData = $this->viewToNorm($viewData);
|
$normData = $this->viewToNorm($viewData);
|
||||||
$synchronized = true;
|
|
||||||
} catch (TransformationFailedException $e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($synchronized) {
|
|
||||||
// Hook to change content of the data into the normalized
|
// Hook to change content of the data into the normalized
|
||||||
// representation
|
// representation
|
||||||
$event = new FormEvent($this, $normData);
|
$event = new FormEvent($this, $normData);
|
||||||
@ -560,6 +556,9 @@ class Form implements \IteratorAggregate, FormInterface
|
|||||||
// Synchronize representations - must not change the content!
|
// Synchronize representations - must not change the content!
|
||||||
$modelData = $this->normToModel($normData);
|
$modelData = $this->normToModel($normData);
|
||||||
$viewData = $this->normToView($normData);
|
$viewData = $this->normToView($normData);
|
||||||
|
|
||||||
|
$synchronized = true;
|
||||||
|
} catch (TransformationFailedException $e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->bound = true;
|
$this->bound = true;
|
||||||
|
@ -480,7 +480,7 @@ class SimpleFormTest extends AbstractFormTest
|
|||||||
$this->assertTrue($this->form->isSynchronized());
|
$this->assertTrue($this->form->isSynchronized());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNotSynchronizedIfTransformationFailed()
|
public function testNotSynchronizedIfViewReverseTransformationFailed()
|
||||||
{
|
{
|
||||||
$transformer = $this->getDataTransformer();
|
$transformer = $this->getDataTransformer();
|
||||||
$transformer->expects($this->once())
|
$transformer->expects($this->once())
|
||||||
@ -496,6 +496,22 @@ class SimpleFormTest extends AbstractFormTest
|
|||||||
$this->assertFalse($form->isSynchronized());
|
$this->assertFalse($form->isSynchronized());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testNotSynchronizedIfModelReverseTransformationFailed()
|
||||||
|
{
|
||||||
|
$transformer = $this->getDataTransformer();
|
||||||
|
$transformer->expects($this->once())
|
||||||
|
->method('reverseTransform')
|
||||||
|
->will($this->throwException(new TransformationFailedException()));
|
||||||
|
|
||||||
|
$form = $this->getBuilder()
|
||||||
|
->addModelTransformer($transformer)
|
||||||
|
->getForm();
|
||||||
|
|
||||||
|
$form->bind('foobar');
|
||||||
|
|
||||||
|
$this->assertFalse($form->isSynchronized());
|
||||||
|
}
|
||||||
|
|
||||||
public function testEmptyDataCreatedBeforeTransforming()
|
public function testEmptyDataCreatedBeforeTransforming()
|
||||||
{
|
{
|
||||||
$form = $this->getBuilder()
|
$form = $this->getBuilder()
|
||||||
|
Reference in New Issue
Block a user