4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Form\Tests\Extension\Core\Type
;
14 class FileTypeTest
extends \Symfony\Component\Form\Test\TypeTestCase
16 // https://github.com/symfony/symfony/pull/5028
17 public function testSetData()
19 $form = $this->factory
->createBuilder('file')->getForm();
20 $data = $this->createUploadedFileMock('abcdef', 'original.jpg', true);
22 $form->setData($data);
24 $this->assertSame($data, $form->getData());
27 public function testSubmit()
29 $form = $this->factory
->createBuilder('file')->getForm();
30 $data = $this->createUploadedFileMock('abcdef', 'original.jpg', true);
34 $this->assertSame($data, $form->getData());
37 // https://github.com/symfony/symfony/issues/6134
38 public function testSubmitEmpty()
40 $form = $this->factory
->createBuilder('file')->getForm();
44 $this->assertNull($form->getData());
47 public function testDontPassValueToView()
49 $form = $this->factory
->create('file');
51 'file' => $this->createUploadedFileMock('abcdef', 'original.jpg', true),
53 $view = $form->createView();
55 $this->assertEquals('', $view->vars
['value']);
58 private function createUploadedFileMock($name, $originalName, $valid)
61 ->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile')
62 ->disableOriginalConstructor()
66 ->expects($this->any())
67 ->method('getBasename')
68 ->will($this->returnValue($name))
71 ->expects($this->any())
72 ->method('getClientOriginalName')
73 ->will($this->returnValue($originalName))
76 ->expects($this->any())
78 ->will($this->returnValue($valid))