You are here

public function FileUploadTest::testFileUploadUnicodeFilename in JSON:API 8.2

Tests using the file upload route with a unicode file name.

File

tests/src/Functional/FileUploadTest.php, line 497

Class

FileUploadTest
Tests binary data file upload route.

Namespace

Drupal\Tests\jsonapi\Functional

Code

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

  // It is important that the filename starts with a unicode character. See
  // https://bugs.php.net/bug.php?id=77239.
  $response = $this
    ->fileRequest($uri, $this->testFileData, [
    'Content-Disposition' => 'file; filename="Èxample-✓.txt"',
  ]);
  $this
    ->assertSame(201, $response
    ->getStatusCode());
  $expected = $this
    ->getExpectedDocument(1, 'Èxample-✓.txt', TRUE);
  $this
    ->assertResponseData($expected, $response);
  $this
    ->assertSame($this->testFileData, file_get_contents('public://foobar/Èxample-✓.txt'));
}