Skip to content

Commit

Permalink
merged branch bschussek/issue6134 (PR #6319)
Browse files Browse the repository at this point in the history
This PR was merged into the 2.1 branch.

Commits
-------

21a59ca [Form] Fixed FileType not to throw an exception when bound empty

Discussion
----------

[Form] Fixed FileType not to throw an exception when bound empty

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: #6134
Todo: -
License of the code: MIT
Documentation PR: -
  • Loading branch information
fabpot committed Dec 13, 2012
2 parents e0cefd7 + 21a59ca commit a6930a3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/Symfony/Component/Form/Extension/Core/Type/FileType.php
Expand Up @@ -46,7 +46,8 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'compound' => false,
'data_class' => 'Symfony\Component\HttpFoundation\File\File'
'data_class' => 'Symfony\Component\HttpFoundation\File\File',
'empty_data' => null,
));
}

Expand Down
Expand Up @@ -11,16 +11,37 @@

namespace Symfony\Component\Form\Tests\Extension\Core\Type;

use Symfony\Component\HttpFoundation\File\UploadedFile;

class FileTypeTest extends TypeTestCase
{
public function testFormBuilderIfEntityHasFile()
// https://github.com/symfony/symfony/pull/5028
public function testSetData()
{
$this->factory->createBuilder('file')
->getForm()
->setData($this->createUploadedFileMock('abcdef', 'original.jpg', true))
;
$form = $this->factory->createBuilder('file')->getForm();
$data = $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()
Expand Down

0 comments on commit a6930a3

Please sign in to comment.