/** * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException * @expectedExceptionMessage Unable to transform value for property path "name": No mapping for value "arg" */ public function testDataTransformationFailure() { $model = new FixedDataTransformer(array('default' => 'foo')); $view = new FixedDataTransformer(array('foo' => 'bar')); $config = new FormConfigBuilder('name', null, $this->dispatcher); $config->addViewTransformer($view); $config->addModelTransformer($model); $config->setData('arg'); $form = new Form($config); $form->getData(); }
public function testDataIsInitializedToConfiguredValue() { $model = new FixedDataTransformer(array('default' => 'foo')); $view = new FixedDataTransformer(array('foo' => 'bar')); $config = new FormConfigBuilder('name', null, $this->dispatcher); $config->addViewTransformer($view); $config->addModelTransformer($model); $config->setData('default'); $form = new Form($config); $this->assertSame('default', $form->getData()); $this->assertSame('foo', $form->getNormData()); $this->assertSame('bar', $form->getViewData()); }
public function testMapFormsToDataIgnoresDisabled() { $car = new \stdClass(); $engine = new \stdClass(); $propertyPath = $this->getPropertyPath('engine'); $this->propertyAccessor->expects($this->never())->method('setValue'); $config = new FormConfigBuilder('name', '\\stdClass', $this->dispatcher); $config->setByReference(true); $config->setPropertyPath($propertyPath); $config->setData($engine); $config->setDisabled(true); $form = $this->getForm($config); $this->mapper->mapFormsToData(array($form), $car); }
public function testMapFormsToDataSkipsVirtualForms() { $car = new \stdClass(); $engine = new \stdClass(); $parentPath = $this->getPropertyPath('name'); $childPath = $this->getPropertyPath('engine'); // getValue() and setValue() must never be invoked for $parentPath $this->propertyAccessor->expects($this->once())->method('getValue')->with($car, $childPath); $this->propertyAccessor->expects($this->once())->method('setValue')->with($car, $childPath, $engine); $config = new FormConfigBuilder('name', '\\stdClass', $this->dispatcher); $config->setPropertyPath($parentPath); $config->setVirtual(true); $config->setCompound(true); $config->setDataMapper($this->getDataMapper()); $form = $this->getForm($config); $config = new FormConfigBuilder('engine', '\\stdClass', $this->dispatcher); $config->setByReference(true); $config->setPropertyPath($childPath); $config->setData($engine); $child = $this->getForm($config); $form->add($child); $this->mapper->mapFormsToData(array($form), $car); }