]> git.immae.eu Git - github/wallabag/wallabag.git/blob - vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/FileTypeTest.php
twig implementation
[github/wallabag/wallabag.git] / vendor / symfony / form / Symfony / Component / Form / Tests / Extension / Core / Type / FileTypeTest.php
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Component\Form\Tests\Extension\Core\Type;
13
14 class FileTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
15 {
16 // https://github.com/symfony/symfony/pull/5028
17 public function testSetData()
18 {
19 $form = $this->factory->createBuilder('file')->getForm();
20 $data = $this->createUploadedFileMock('abcdef', 'original.jpg', true);
21
22 $form->setData($data);
23
24 $this->assertSame($data, $form->getData());
25 }
26
27 public function testSubmit()
28 {
29 $form = $this->factory->createBuilder('file')->getForm();
30 $data = $this->createUploadedFileMock('abcdef', 'original.jpg', true);
31
32 $form->submit($data);
33
34 $this->assertSame($data, $form->getData());
35 }
36
37 // https://github.com/symfony/symfony/issues/6134
38 public function testSubmitEmpty()
39 {
40 $form = $this->factory->createBuilder('file')->getForm();
41
42 $form->submit(null);
43
44 $this->assertNull($form->getData());
45 }
46
47 public function testDontPassValueToView()
48 {
49 $form = $this->factory->create('file');
50 $form->submit(array(
51 'file' => $this->createUploadedFileMock('abcdef', 'original.jpg', true),
52 ));
53 $view = $form->createView();
54
55 $this->assertEquals('', $view->vars['value']);
56 }
57
58 private function createUploadedFileMock($name, $originalName, $valid)
59 {
60 $file = $this
61 ->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile')
62 ->disableOriginalConstructor()
63 ->getMock()
64 ;
65 $file
66 ->expects($this->any())
67 ->method('getBasename')
68 ->will($this->returnValue($name))
69 ;
70 $file
71 ->expects($this->any())
72 ->method('getClientOriginalName')
73 ->will($this->returnValue($originalName))
74 ;
75 $file
76 ->expects($this->any())
77 ->method('isValid')
78 ->will($this->returnValue($valid))
79 ;
80
81 return $file;
82 }
83 }