Merge branch '2.8'

* 2.8:
  Fix BC for the default root form name

Conflicts:
	src/Symfony/Component/Form/FormFactory.php
	src/Symfony/Component/Form/Tests/FormFactoryTest.php
This commit is contained in:
Nicolas Grekas 2015-11-30 15:11:44 +01:00
commit fdb419e918
2 changed files with 49 additions and 6 deletions

View File

@ -65,7 +65,11 @@ class FormFactory implements FormFactoryInterface
throw new UnexpectedTypeException($type, 'string');
}
return $this->createNamedBuilder(StringUtil::fqcnToBlockPrefix($type), $type, $data, $options);
if (null === $name = $this->registry->getType($type)->getBlockPrefix()) {
$name = StringUtil::fqcnToBlockPrefix($type);
}
return $this->createNamedBuilder($name, $type, $data, $options);
}
/**

View File

@ -169,13 +169,52 @@ class FormFactoryTest extends \PHPUnit_Framework_TestCase
$this->factory->create(new \stdClass());
}
public function testCreateUsesBlockPrefixIfTypeGivenAsString()
{
$options = array('a' => '1', 'b' => '2');
$resolvedOptions = array('a' => '2', 'b' => '3');
// the interface does not have the method, so use the real class
$resolvedType = $this->getMockBuilder('Symfony\Component\Form\ResolvedFormType')
->disableOriginalConstructor()
->getMock();
$resolvedType->expects($this->any())
->method('getBlockPrefix')
->willReturn('TYPE_PREFIX');
$this->registry->expects($this->any())
->method('getType')
->with('TYPE')
->will($this->returnValue($resolvedType));
$resolvedType->expects($this->once())
->method('createBuilder')
->with($this->factory, 'TYPE_PREFIX', $options)
->will($this->returnValue($this->builder));
$this->builder->expects($this->any())
->method('getOptions')
->will($this->returnValue($resolvedOptions));
$resolvedType->expects($this->once())
->method('buildForm')
->with($this->builder, $resolvedOptions);
$this->builder->expects($this->once())
->method('getForm')
->will($this->returnValue('FORM'));
$this->assertSame('FORM', $this->factory->create('TYPE', null, $options));
}
public function testCreateUsesTypeNameIfTypeGivenAsString()
{
$options = array('a' => '1', 'b' => '2');
$resolvedOptions = array('a' => '2', 'b' => '3');
$resolvedType = $this->getMockResolvedType();
$this->registry->expects($this->once())
$this->registry->expects($this->any())
->method('getType')
->with('TYPE')
->will($this->returnValue($resolvedType));
@ -206,7 +245,7 @@ class FormFactoryTest extends \PHPUnit_Framework_TestCase
$resolvedOptions = array('a' => '2', 'b' => '3');
$resolvedType = $this->getMockResolvedType();
$this->registry->expects($this->once())
$this->registry->expects($this->any())
->method('getType')
->with('Vendor\Name\Space\UserForm')
->will($this->returnValue($resolvedType));
@ -237,7 +276,7 @@ class FormFactoryTest extends \PHPUnit_Framework_TestCase
$resolvedOptions = array('a' => '2', 'b' => '3');
$resolvedType = $this->getMockResolvedType();
$this->registry->expects($this->once())
$this->registry->expects($this->any())
->method('getType')
->with('Vendor\Name\Space\UserType')
->will($this->returnValue($resolvedType));
@ -268,7 +307,7 @@ class FormFactoryTest extends \PHPUnit_Framework_TestCase
$resolvedOptions = array('a' => '2', 'b' => '3');
$resolvedType = $this->getMockResolvedType();
$this->registry->expects($this->once())
$this->registry->expects($this->any())
->method('getType')
->with('Vendor\Name\Space\Type')
->will($this->returnValue($resolvedType));
@ -299,7 +338,7 @@ class FormFactoryTest extends \PHPUnit_Framework_TestCase
$resolvedOptions = array('a' => '2', 'b' => '3');
$resolvedType = $this->getMockResolvedType();
$this->registry->expects($this->once())
$this->registry->expects($this->any())
->method('getType')
->with('Vendor\Name\Space\MyProfileHTMLType')
->will($this->returnValue($resolvedType));