function FileUploadResourceTestBase::testFileUploadZeroByteFile
Same name in other branches
- 9 core/modules/rest/tests/src/Functional/FileUploadResourceTestBase.php \Drupal\Tests\rest\Functional\FileUploadResourceTestBase::testFileUploadZeroByteFile()
- 8.9.x core/modules/rest/tests/src/Functional/FileUploadResourceTestBase.php \Drupal\Tests\rest\Functional\FileUploadResourceTestBase::testFileUploadZeroByteFile()
- 11.x core/modules/rest/tests/src/Functional/FileUploadResourceTestBase.php \Drupal\Tests\rest\Functional\FileUploadResourceTestBase::testFileUploadZeroByteFile()
Tests using the file upload route with a zero byte file.
File
-
core/
modules/ rest/ tests/ src/ Functional/ FileUploadResourceTestBase.php, line 436
Class
- FileUploadResourceTestBase
- Tests binary data file upload route.
Namespace
Drupal\Tests\rest\FunctionalCode
public function testFileUploadZeroByteFile() : void {
$this->initAuthentication();
$this->provisionResource([
static::$format,
], static::$auth ? [
static::$auth,
] : [], [
'POST',
]);
$this->setUpAuthorization('POST');
$uri = Url::fromUri('base:' . static::$postUri);
// Test with a zero byte file.
$response = $this->fileRequest($uri, NULL);
$this->assertSame(201, $response->getStatusCode());
$expected = $this->getExpectedNormalizedEntity();
// Modify the default expected data to account for the 0 byte file.
$expected['filesize'][0]['value'] = 0;
$this->assertResponseData($expected, $response);
// Check the actual file data.
$this->assertSame('', file_get_contents('public://foobar/example.txt'));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.