[Form] Failing test for empty_data option BC break

This demonstrates the issue described in symfony/symfony#3354. FieldType no longer has access to the child type's data_class option, which makes it unable to create the default closure for empty_data.
This commit is contained in:
Jeremy Mikola 2012-03-23 11:21:47 -04:00 committed by Bernhard Schussek
parent b7330456b6
commit cb87ccb284
2 changed files with 47 additions and 0 deletions

View File

@ -0,0 +1,31 @@
<?php
namespace Symfony\Component\Form\Tests\Fixtures;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;
class AuthorType extends AbstractType
{
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->add('firstName')
->add('lastName')
;
}
public function getName()
{
return 'author';
}
public function getDefaultOptions()
{
return array(
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\Author',
);
}
}

View File

@ -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')