You are here

public function FileUploadResourceTestBase::testFileUploadZeroByteFile in Drupal 10

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

Class

FileUploadResourceTestBase
Tests binary data file upload route.

Namespace

Drupal\Tests\rest\Functional

Code

public function testFileUploadZeroByteFile() {
  $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'));
}