[Form] Fixed FileType not to throw an exception when bound empty
This commit is contained in:
parent
e0cefd7f7e
commit
21a59ca04c
@ -46,7 +46,8 @@ class FileType extends AbstractType
|
|||||||
{
|
{
|
||||||
$resolver->setDefaults(array(
|
$resolver->setDefaults(array(
|
||||||
'compound' => false,
|
'compound' => false,
|
||||||
'data_class' => 'Symfony\Component\HttpFoundation\File\File'
|
'data_class' => 'Symfony\Component\HttpFoundation\File\File',
|
||||||
|
'empty_data' => null,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,16 +11,37 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||||
|
|
||||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
|
||||||
|
|
||||||
class FileTypeTest extends TypeTestCase
|
class FileTypeTest extends TypeTestCase
|
||||||
{
|
{
|
||||||
public function testFormBuilderIfEntityHasFile()
|
// https://github.com/symfony/symfony/pull/5028
|
||||||
|
public function testSetData()
|
||||||
{
|
{
|
||||||
$this->factory->createBuilder('file')
|
$form = $this->factory->createBuilder('file')->getForm();
|
||||||
->getForm()
|
$data = $this->createUploadedFileMock('abcdef', 'original.jpg', true);
|
||||||
->setData($this->createUploadedFileMock('abcdef', 'original.jpg', true))
|
|
||||||
;
|
$form->setData($data);
|
||||||
|
|
||||||
|
$this->assertSame($data, $form->getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testBind()
|
||||||
|
{
|
||||||
|
$form = $this->factory->createBuilder('file')->getForm();
|
||||||
|
$data = $this->createUploadedFileMock('abcdef', 'original.jpg', true);
|
||||||
|
|
||||||
|
$form->bind($data);
|
||||||
|
|
||||||
|
$this->assertSame($data, $form->getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://github.com/symfony/symfony/issues/6134
|
||||||
|
public function testBindEmpty()
|
||||||
|
{
|
||||||
|
$form = $this->factory->createBuilder('file')->getForm();
|
||||||
|
|
||||||
|
$form->bind(null);
|
||||||
|
|
||||||
|
$this->assertNull($form->getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDontPassValueToView()
|
public function testDontPassValueToView()
|
||||||
|
Reference in New Issue
Block a user