[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:
parent
b7330456b6
commit
cb87ccb284
31
src/Symfony/Component/Form/Tests/Fixtures/AuthorType.php
Normal file
31
src/Symfony/Component/Form/Tests/Fixtures/AuthorType.php
Normal 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',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -16,6 +16,8 @@ use Symfony\Component\Form\FormFactory;
|
|||||||
use Symfony\Component\Form\Guess\Guess;
|
use Symfony\Component\Form\Guess\Guess;
|
||||||
use Symfony\Component\Form\Guess\ValueGuess;
|
use Symfony\Component\Form\Guess\ValueGuess;
|
||||||
use Symfony\Component\Form\Guess\TypeGuess;
|
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\TestExtension;
|
||||||
use Symfony\Component\Form\Tests\Fixtures\FooType;
|
use Symfony\Component\Form\Tests\Fixtures\FooType;
|
||||||
use Symfony\Component\Form\Tests\Fixtures\FooTypeBarExtension;
|
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"));
|
$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())
|
private function createMockFactory(array $methods = array())
|
||||||
{
|
{
|
||||||
return $this->getMockBuilder('Symfony\Component\Form\FormFactory')
|
return $this->getMockBuilder('Symfony\Component\Form\FormFactory')
|
||||||
|
Reference in New Issue
Block a user