[Form] NativeRequestHandler file handling fix
This commit is contained in:
parent
c0dcbed7a5
commit
9b3421f18a
@ -98,8 +98,8 @@ class NativeRequestHandler implements RequestHandlerInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
$fixedFiles = array();
|
$fixedFiles = array();
|
||||||
foreach ($_FILES as $name => $file) {
|
foreach ($_FILES as $fileKey => $file) {
|
||||||
$fixedFiles[$name] = self::stripEmptyFiles(self::fixPhpFilesArray($file));
|
$fixedFiles[$fileKey] = self::stripEmptyFiles(self::fixPhpFilesArray($file));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('' === $name) {
|
if ('' === $name) {
|
||||||
|
@ -266,6 +266,50 @@ abstract class AbstractRequestHandlerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->requestHandler->handleRequest($form, $this->request);
|
$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
|
* @dataProvider getPostMaxSizeFixtures
|
||||||
*/
|
*/
|
||||||
@ -314,7 +358,7 @@ abstract class AbstractRequestHandlerTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
abstract protected function getRequestHandler();
|
abstract protected function getRequestHandler();
|
||||||
|
|
||||||
abstract protected function getMockFile();
|
abstract protected function getMockFile($suffix = '');
|
||||||
|
|
||||||
protected function getMockForm($name, $method = null, $compound = true)
|
protected function getMockForm($name, $method = null, $compound = true)
|
||||||
{
|
{
|
||||||
|
@ -46,8 +46,8 @@ class HttpFoundationRequestHandlerTest extends AbstractRequestHandlerTest
|
|||||||
return new HttpFoundationRequestHandler($this->serverParams);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
0
src/Symfony/Component/Form/Tests/Fixtures/foo2
Normal file
0
src/Symfony/Component/Form/Tests/Fixtures/foo2
Normal file
0
src/Symfony/Component/Form/Tests/Fixtures/foo3
Normal file
0
src/Symfony/Component/Form/Tests/Fixtures/foo3
Normal file
@ -206,12 +206,12 @@ class NativeRequestHandlerTest extends AbstractRequestHandlerTest
|
|||||||
return new NativeRequestHandler($this->serverParams);
|
return new NativeRequestHandler($this->serverParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getMockFile()
|
protected function getMockFile($suffix = '')
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
'name' => 'upload.txt',
|
'name' => 'upload'.$suffix.'.txt',
|
||||||
'type' => 'text/plain',
|
'type' => 'text/plain',
|
||||||
'tmp_name' => 'owfdskjasdfsa',
|
'tmp_name' => 'owfdskjasdfsa'.$suffix,
|
||||||
'error' => UPLOAD_ERR_OK,
|
'error' => UPLOAD_ERR_OK,
|
||||||
'size' => 100,
|
'size' => 100,
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user