diff --git a/src/Symfony/Component/Form/Tests/Fixtures/AuthorType.php b/src/Symfony/Component/Form/Tests/Fixtures/AuthorType.php new file mode 100644 index 0000000000..43569843f0 --- /dev/null +++ b/src/Symfony/Component/Form/Tests/Fixtures/AuthorType.php @@ -0,0 +1,31 @@ +add('firstName') + ->add('lastName') + ; + } + + public function getName() + { + return 'author'; + } + + public function getDefaultOptions() + { + return array( + 'data_class' => 'Symfony\Component\Form\Tests\Fixtures\Author', + ); + } +} diff --git a/src/Symfony/Component/Form/Tests/FormFactoryTest.php b/src/Symfony/Component/Form/Tests/FormFactoryTest.php index 9bd50a1cf6..18c70bc457 100644 --- a/src/Symfony/Component/Form/Tests/FormFactoryTest.php +++ b/src/Symfony/Component/Form/Tests/FormFactoryTest.php @@ -16,6 +16,8 @@ use Symfony\Component\Form\FormFactory; use Symfony\Component\Form\Guess\Guess; use Symfony\Component\Form\Guess\ValueGuess; use Symfony\Component\Form\Guess\TypeGuess; +use Symfony\Component\Form\Tests\Fixtures\Author; +use Symfony\Component\Form\Tests\Fixtures\AuthorType; use Symfony\Component\Form\Tests\Fixtures\TestExtension; use Symfony\Component\Form\Tests\Fixtures\FooType; use Symfony\Component\Form\Tests\Fixtures\FooTypeBarExtension; @@ -539,6 +541,20 @@ class FormFactoryTest extends \PHPUnit_Framework_TestCase $factory->createNamedBuilder($type, "text", "value", array("unknown" => "opt")); } + public function testFieldTypeCreatesDefaultValueForEmptyDataOption() + { + $factory = new FormFactory(array(new \Symfony\Component\Form\Extension\Core\CoreExtension())); + + $form = $factory->createNamedBuilder(new AuthorType(), 'author')->getForm(); + $form->bind(array('firstName' => 'John', 'lastName' => 'Smith')); + + $author = new Author(); + $author->firstName = 'John'; + $author->setLastName('Smith'); + + $this->assertEquals($author, $form->getData()); + } + private function createMockFactory(array $methods = array()) { return $this->getMockBuilder('Symfony\Component\Form\FormFactory')