protected function FileUploadResourceTestBase::fileRequest in Drupal 9
Same name and namespace in other branches
- 8 core/modules/rest/tests/src/Functional/FileUploadResourceTestBase.php \Drupal\Tests\rest\Functional\FileUploadResourceTestBase::fileRequest()
- 10 core/modules/rest/tests/src/Functional/FileUploadResourceTestBase.php \Drupal\Tests\rest\Functional\FileUploadResourceTestBase::fileRequest()
Performs a file upload request. Wraps the Guzzle HTTP client.
Parameters
\Drupal\Core\Url $url: URL to request.
string $file_contents: The file contents to send as the request body.
array $headers: Additional headers to send with the request. Defaults will be added for Content-Type and Content-Disposition. In order to remove the defaults set the header value to FALSE.
Return value
\Psr\Http\Message\ResponseInterface
See also
\GuzzleHttp\ClientInterface::request()
11 calls to FileUploadResourceTestBase::fileRequest()
- FileUploadResourceTestBase::testFileUploadInvalidFileType in core/
modules/ rest/ tests/ src/ Functional/ FileUploadResourceTestBase.php - Tests using the file upload route with an invalid file type.
- FileUploadResourceTestBase::testFileUploadLargerFileSize in core/
modules/ rest/ tests/ src/ Functional/ FileUploadResourceTestBase.php - Tests using the file upload route with a file size larger than allowed.
- FileUploadResourceTestBase::testFileUploadMaliciousExtension in core/
modules/ rest/ tests/ src/ Functional/ FileUploadResourceTestBase.php - Tests using the file upload POST route with malicious extensions.
- FileUploadResourceTestBase::testFileUploadNoExtensionSetting in core/
modules/ rest/ tests/ src/ Functional/ FileUploadResourceTestBase.php - Tests using the file upload POST route no extension configured.
- FileUploadResourceTestBase::testFileUploadStrippedFilePath in core/
modules/ rest/ tests/ src/ Functional/ FileUploadResourceTestBase.php - Tests using the file upload route with any path prefixes being stripped.
File
- core/
modules/ rest/ tests/ src/ Functional/ FileUploadResourceTestBase.php, line 765
Class
- FileUploadResourceTestBase
- Tests binary data file upload route.
Namespace
Drupal\Tests\rest\FunctionalCode
protected function fileRequest(Url $url, $file_contents, array $headers = []) {
// Set the format for the response.
$url
->setOption('query', [
'_format' => static::$format,
]);
$request_options = [];
$headers = $headers + [
// Set the required (and only accepted) content type for the request.
'Content-Type' => 'application/octet-stream',
// Set the required Content-Disposition header for the file name.
'Content-Disposition' => 'file; filename="example.txt"',
];
$request_options[RequestOptions::HEADERS] = array_filter($headers, function ($value) {
return $value !== FALSE;
});
$request_options[RequestOptions::BODY] = $file_contents;
$request_options = NestedArray::mergeDeep($request_options, $this
->getAuthenticationRequestOptions('POST'));
return $this
->request('POST', $url, $request_options);
}