You are here

public function FileUploadTest::testFileUploadZeroByteFile in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/jsonapi/tests/src/Functional/FileUploadTest.php \Drupal\Tests\jsonapi\Functional\FileUploadTest::testFileUploadZeroByteFile()

Tests using the file upload route with a zero byte file.

File

core/modules/jsonapi/tests/src/Functional/FileUploadTest.php, line 545

Class

FileUploadTest
Tests binary data file upload route.

Namespace

Drupal\Tests\jsonapi\Functional

Code

public function testFileUploadZeroByteFile() {
  $this
    ->setUpAuthorization('POST');
  $this
    ->config('jsonapi.settings')
    ->set('read_only', FALSE)
    ->save(TRUE);
  $uri = Url::fromUri('base:' . static::$postUri);

  // Test with a zero byte file.
  $response = $this
    ->fileRequest($uri, NULL);
  $this
    ->assertSame(201, $response
    ->getStatusCode());
  $expected = $this
    ->getExpectedDocument();

  // Modify the default expected data to account for the 0 byte file.
  $expected['data']['attributes']['filesize'] = 0;
  $this
    ->assertResponseData($expected, $response);

  // Check the actual file data.
  $this
    ->assertSame('', file_get_contents('public://foobar/example.txt'));
}