diff --git a/tests/Symfony/Tests/Component/Form/Fixtures/AuthorType.php b/tests/Symfony/Tests/Component/Form/Fixtures/AuthorType.php new file mode 100644 index 0000000000000..a3c9367d6d1ea --- /dev/null +++ b/tests/Symfony/Tests/Component/Form/Fixtures/AuthorType.php @@ -0,0 +1,31 @@ +add('firstName') + ->add('lastName') + ; + } + + public function getName() + { + return 'author'; + } + + public function getDefaultOptions(array $options) + { + return array( + 'data_class' => 'Symfony\Tests\Component\Form\Fixtures\Author', + ); + } +} diff --git a/tests/Symfony/Tests/Component/Form/FormFactoryTest.php b/tests/Symfony/Tests/Component/Form/FormFactoryTest.php index 932cf0b38f841..5fe5decc13c52 100644 --- a/tests/Symfony/Tests/Component/Form/FormFactoryTest.php +++ b/tests/Symfony/Tests/Component/Form/FormFactoryTest.php @@ -16,6 +16,8 @@ use Symfony\Component\Form\Guess\Guess; use Symfony\Component\Form\Guess\ValueGuess; use Symfony\Component\Form\Guess\TypeGuess; +use Symfony\Tests\Component\Form\Fixtures\Author; +use Symfony\Tests\Component\Form\Fixtures\AuthorType; use Symfony\Tests\Component\Form\Fixtures\TestExtension; use Symfony\Tests\Component\Form\Fixtures\FooType; use Symfony\Tests\Component\Form\Fixtures\FooTypeBarExtension; @@ -531,6 +533,20 @@ public function testUnknownOption() $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')