bug #10953 [HttpKernel] fixed file uploads in functional tests without file selected (realmfoo)

This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes #10953).

Discussion
----------

[HttpKernel] fixed file uploads in functional tests without file selected

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

Commits
-------

6f56d87 [HttpKernel] fixed file uploads in functional tests when no file was selected
This commit is contained in:
Fabien Potencier 2014-05-21 14:41:36 +02:00
commit 125b9e7347
2 changed files with 18 additions and 3 deletions

View File

@ -143,7 +143,9 @@ EOF;
{
$httpRequest = Request::create($request->getUri(), $request->getMethod(), $request->getParameters(), $request->getCookies(), $request->getFiles(), $request->getServer(), $request->getContent());
$httpRequest->files->replace($this->filterFiles($httpRequest->files->all()));
foreach ($this->filterFiles($httpRequest->files->all()) as $key => $value) {
$httpRequest->files->set($key, $value);
}
return $httpRequest;
}
@ -189,8 +191,6 @@ EOF;
true
);
}
} else {
$filtered[$key] = $value;
}
}

View File

@ -143,6 +143,21 @@ class ClientTest extends \PHPUnit_Framework_TestCase
unlink($target);
}
public function testUploadedFileWhenNoFileSelected()
{
$kernel = new TestHttpKernel();
$client = new Client($kernel);
$file = array('tmp_name' => '', 'name' => '', 'type' => '', 'size' => 0, 'error' => UPLOAD_ERR_NO_FILE);
$client->request('POST', '/', array(), array('foo' => $file));
$files = $client->getRequest()->files->all();
$this->assertCount(1, $files);
$this->assertNull($files['foo']);
}
public function testUploadedFileWhenSizeExceedsUploadMaxFileSize()
{
$source = tempnam(sys_get_temp_dir(), 'source');