[Form] NativeRequestHandler file handling fix

This commit is contained in:
Mikael Pajunen 2015-02-24 00:10:57 +02:00 committed by Fabien Potencier
parent c0dcbed7a5
commit 9b3421f18a
6 changed files with 52 additions and 8 deletions

View File

@ -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) {

View File

@ -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)
{

View File

@ -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);
}
}

View File

@ -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,
);