diff --git a/src/Symfony/Component/Form/NativeRequestHandler.php b/src/Symfony/Component/Form/NativeRequestHandler.php index ea748d6161..a888967bb3 100644 --- a/src/Symfony/Component/Form/NativeRequestHandler.php +++ b/src/Symfony/Component/Form/NativeRequestHandler.php @@ -98,8 +98,8 @@ class NativeRequestHandler implements RequestHandlerInterface } $fixedFiles = array(); - foreach ($_FILES as $name => $file) { - $fixedFiles[$name] = self::stripEmptyFiles(self::fixPhpFilesArray($file)); + foreach ($_FILES as $fileKey => $file) { + $fixedFiles[$fileKey] = self::stripEmptyFiles(self::fixPhpFilesArray($file)); } if ('' === $name) { diff --git a/src/Symfony/Component/Form/Tests/AbstractRequestHandlerTest.php b/src/Symfony/Component/Form/Tests/AbstractRequestHandlerTest.php index b017db90d0..e4d63c2a94 100644 --- a/src/Symfony/Component/Form/Tests/AbstractRequestHandlerTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractRequestHandlerTest.php @@ -266,6 +266,50 @@ abstract class AbstractRequestHandlerTest extends \PHPUnit_Framework_TestCase $this->requestHandler->handleRequest($form, $this->request); } + /** + * @dataProvider methodExceptGetProvider + */ + public function testSubmitMultipleFiles($method) + { + $form = $this->getMockForm('param1', $method); + $file = $this->getMockFile(); + + $this->setRequestData($method, array( + 'param1' => null, + ), array( + 'param2' => $this->getMockFile('2'), + 'param1' => $file, + 'param3' => $this->getMockFile('3'), + )); + + $form->expects($this->once()) + ->method('submit') + ->with($file, 'PATCH' !== $method); + + $this->requestHandler->handleRequest($form, $this->request); + } + + /** + * @dataProvider methodExceptGetProvider + */ + public function testSubmitFileWithNamelessForm($method) + { + $form = $this->getMockForm(null, $method); + $file = $this->getMockFile(); + + $this->setRequestData($method, array( + '' => null, + ), array( + '' => $file, + )); + + $form->expects($this->once()) + ->method('submit') + ->with($file, 'PATCH' !== $method); + + $this->requestHandler->handleRequest($form, $this->request); + } + /** * @dataProvider getPostMaxSizeFixtures */ @@ -314,7 +358,7 @@ abstract class AbstractRequestHandlerTest extends \PHPUnit_Framework_TestCase abstract protected function getRequestHandler(); - abstract protected function getMockFile(); + abstract protected function getMockFile($suffix = ''); protected function getMockForm($name, $method = null, $compound = true) { diff --git a/src/Symfony/Component/Form/Tests/Extension/HttpFoundation/HttpFoundationRequestHandlerTest.php b/src/Symfony/Component/Form/Tests/Extension/HttpFoundation/HttpFoundationRequestHandlerTest.php index dcd26891c1..4d4ac86fe7 100644 --- a/src/Symfony/Component/Form/Tests/Extension/HttpFoundation/HttpFoundationRequestHandlerTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/HttpFoundation/HttpFoundationRequestHandlerTest.php @@ -46,8 +46,8 @@ class HttpFoundationRequestHandlerTest extends AbstractRequestHandlerTest return new HttpFoundationRequestHandler($this->serverParams); } - protected function getMockFile() + protected function getMockFile($suffix = '') { - return new UploadedFile(__DIR__.'/../../Fixtures/foo', 'foo'); + return new UploadedFile(__DIR__.'/../../Fixtures/foo'.$suffix, 'foo'.$suffix); } } diff --git a/src/Symfony/Component/Form/Tests/Fixtures/foo2 b/src/Symfony/Component/Form/Tests/Fixtures/foo2 new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/Symfony/Component/Form/Tests/Fixtures/foo3 b/src/Symfony/Component/Form/Tests/Fixtures/foo3 new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/Symfony/Component/Form/Tests/NativeRequestHandlerTest.php b/src/Symfony/Component/Form/Tests/NativeRequestHandlerTest.php index eac767f8c8..38580063e7 100644 --- a/src/Symfony/Component/Form/Tests/NativeRequestHandlerTest.php +++ b/src/Symfony/Component/Form/Tests/NativeRequestHandlerTest.php @@ -206,12 +206,12 @@ class NativeRequestHandlerTest extends AbstractRequestHandlerTest return new NativeRequestHandler($this->serverParams); } - protected function getMockFile() + protected function getMockFile($suffix = '') { return array( - 'name' => 'upload.txt', + 'name' => 'upload'.$suffix.'.txt', 'type' => 'text/plain', - 'tmp_name' => 'owfdskjasdfsa', + 'tmp_name' => 'owfdskjasdfsa'.$suffix, 'error' => UPLOAD_ERR_OK, 'size' => 100, );