|
|
|
@ -52,6 +52,45 @@ class MultipartFormDataParserTest extends TestCase
|
|
|
|
|
$this->assertStringEqualsFile($_FILES['Item']['tmp_name']['file'], 'item file content'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function testParseWithDoubleQuotes() |
|
|
|
|
{ |
|
|
|
|
if (defined('HHVM_VERSION')) { |
|
|
|
|
static::markTestSkipped('Can not test on HHVM because it does not support proper handling of the temporary files.'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$parser = new MultipartFormDataParser(); |
|
|
|
|
|
|
|
|
|
$boundary = '---------------------------22472926011618'; |
|
|
|
|
$contentType = 'multipart/form-data; boundary="' . $boundary . '"'; |
|
|
|
|
$rawBody = "--{$boundary}\nContent-Disposition: form-data; name=\"title\"\r\n\r\ntest-title"; |
|
|
|
|
$rawBody .= "\r\n--{$boundary}\nContent-Disposition: form-data; name=\"Item[name]\"\r\n\r\ntest-name"; |
|
|
|
|
$rawBody .= "\r\n--{$boundary}\nContent-Disposition: form-data; name=\"someFile\"; filename=\"some-file.txt\"\nContent-Type: text/plain\r\n\r\nsome file content"; |
|
|
|
|
$rawBody .= "\r\n--{$boundary}\nContent-Disposition: form-data; name=\"Item[file]\"; filename=\"item-file.txt\"\nContent-Type: text/plain\r\n\r\nitem file content"; |
|
|
|
|
$rawBody .= "\r\n--{$boundary}--"; |
|
|
|
|
|
|
|
|
|
$bodyParams = $parser->parse($rawBody, $contentType); |
|
|
|
|
|
|
|
|
|
$expectedBodyParams = [ |
|
|
|
|
'title' => 'test-title', |
|
|
|
|
'Item' => [ |
|
|
|
|
'name' => 'test-name', |
|
|
|
|
], |
|
|
|
|
]; |
|
|
|
|
$this->assertEquals($expectedBodyParams, $bodyParams); |
|
|
|
|
|
|
|
|
|
$this->assertNotEmpty($_FILES['someFile']); |
|
|
|
|
$this->assertEquals(UPLOAD_ERR_OK, $_FILES['someFile']['error']); |
|
|
|
|
$this->assertEquals('some-file.txt', $_FILES['someFile']['name']); |
|
|
|
|
$this->assertEquals('text/plain', $_FILES['someFile']['type']); |
|
|
|
|
$this->assertStringEqualsFile($_FILES['someFile']['tmp_name'], 'some file content'); |
|
|
|
|
|
|
|
|
|
$this->assertNotEmpty($_FILES['Item']); |
|
|
|
|
$this->assertNotEmpty($_FILES['Item']['name']['file']); |
|
|
|
|
$this->assertEquals(UPLOAD_ERR_OK, $_FILES['Item']['error']['file']); |
|
|
|
|
$this->assertEquals('item-file.txt', $_FILES['Item']['name']['file']); |
|
|
|
|
$this->assertEquals('text/plain', $_FILES['Item']['type']['file']); |
|
|
|
|
$this->assertStringEqualsFile($_FILES['Item']['tmp_name']['file'], 'item file content'); |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* @depends testParse |
|
|
|
|
*/ |
|
|
|
|