Test file uploads

This commit is contained in:
Michael 2021-05-24 07:43:42 +00:00
parent ca5fd01f75
commit 3e303fb366
3 changed files with 15 additions and 5 deletions

View file

@ -141,7 +141,7 @@ class HTTPInputData
return ['variables' => $variables, 'files' => $files]; return ['variables' => $variables, 'files' => $files];
} }
private static function fetchFileData($stream, string $boundary, array $headers, string $filename) protected static function fetchFileData($stream, string $boundary, array $headers, string $filename)
{ {
$error = UPLOAD_ERR_OK; $error = UPLOAD_ERR_OK;

View file

@ -83,4 +83,16 @@ class HTTPInputDataDouble extends HTTPInputData
{ {
return static::$injectedContentType; return static::$injectedContentType;
} }
protected static function fetchFileData($stream, string $boundary, array $headers, string $filename)
{
$data = parent::fetchFileData($stream, $boundary, $headers, $filename);
if (!empty($data['tmp_name'])) {
unlink($data['tmp_name']);
$data['tmp_name'] = $data['name'];
}
return $data;
}
} }

View file

@ -64,7 +64,6 @@ class HTTPInputDataTest extends MockedTest
'files' => [] 'files' => []
] ]
], ],
/*
'multipart-file' => [ 'multipart-file' => [
'contenttype' => 'multipart/form-data;boundary=6d4d5a40-651a-4468-a62e-5a6ca2bf350d;charset=utf8', 'contenttype' => 'multipart/form-data;boundary=6d4d5a40-651a-4468-a62e-5a6ca2bf350d;charset=utf8',
'input' => file_get_contents(__DIR__ . '/../../datasets/http/multipart-file.httpinput'), 'input' => file_get_contents(__DIR__ . '/../../datasets/http/multipart-file.httpinput'),
@ -87,21 +86,20 @@ class HTTPInputDataTest extends MockedTest
'avatar' => [ 'avatar' => [
'name' => '8ZUCS34Y5XNH', 'name' => '8ZUCS34Y5XNH',
'type' => 'image/png', 'type' => 'image/png',
'tmp_name' => '/tmp/phpf85nKJ', 'tmp_name' => '8ZUCS34Y5XNH',
'error' => 0, 'error' => 0,
'size' => 349330 'size' => 349330
], ],
'header' => [ 'header' => [
'name' => 'V2B6Z1IICGPM', 'name' => 'V2B6Z1IICGPM',
'type' => 'image/png', 'type' => 'image/png',
'tmp_name' => '/tmp/phpe3sqHT', 'tmp_name' => 'V2B6Z1IICGPM',
'error' => 0, 'error' => 0,
'size' => 1323635 'size' => 1323635
] ]
] ]
] ]
], ],
*/
'form-urlencoded' => [ 'form-urlencoded' => [
'contenttype' => 'application/x-www-form-urlencoded;charset=utf8', 'contenttype' => 'application/x-www-form-urlencoded;charset=utf8',
'input' => file_get_contents(__DIR__ . '/../../datasets/http/form-urlencoded.httpinput'), 'input' => file_get_contents(__DIR__ . '/../../datasets/http/form-urlencoded.httpinput'),