Explorar o código

[Form] Added test for 6c337d1cc09c623c5fbb4ce261e1d41f2ebb9f6d

Bernhard Schussek %!s(int64=14) %!d(string=hai) anos
pai
achega
af66beed76

+ 1 - 1
src/Symfony/Component/Form/Extension/Core/Type/FileType.php

@@ -52,7 +52,7 @@ class FileType extends AbstractType
     {
         $view->set('multipart', true);
         $view['file']->set('type', 'file');
-        $view['file']->set('value', null);
+        $view['file']->set('value', '');
     }
 
     public function getDefaultOptions(array $options)

+ 48 - 0
tests/Symfony/Tests/Component/Form/Extension/Core/Type/FileTypeTest.php

@@ -0,0 +1,48 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Tests\Component\Form\Extension\Core\Type;
+
+require_once __DIR__ . '/TypeTestCase.php';
+
+use Symfony\Component\HttpFoundation\File\UploadedFile;
+
+class FileTypeTest extends TypeTestCase
+{
+    public function testDontPassValueToView()
+    {
+        $form = $this->factory->create('file');
+        $form->bind(array(
+            'file' => $this->createUploadedFileMock('abcdef', 'original.jpg', true),
+        ));
+        $view = $form->createView();
+
+        $this->assertEquals('', $view['file']->get('value'));
+    }
+
+    private function createUploadedFileMock($name, $originalName, $valid)
+    {
+        $file = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile')
+            ->disableOriginalConstructor()
+            ->getMock();
+        $file->expects($this->any())
+            ->method('getName')
+            ->will($this->returnValue($name));
+        $file->expects($this->any())
+            ->method('getOriginalName')
+            ->will($this->returnValue($originalName));
+        $file->expects($this->any())
+            ->method('isValid')
+            ->will($this->returnValue($valid));
+
+        return $file;
+    }
+}