function FileUploadResourceTestBase::testFileUploadZeroByteFile

Same name in other branches
  1. 9 core/modules/rest/tests/src/Functional/FileUploadResourceTestBase.php \Drupal\Tests\rest\Functional\FileUploadResourceTestBase::testFileUploadZeroByteFile()
  2. 8.9.x core/modules/rest/tests/src/Functional/FileUploadResourceTestBase.php \Drupal\Tests\rest\Functional\FileUploadResourceTestBase::testFileUploadZeroByteFile()
  3. 10 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\Functional

Code

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.