You are here

public function FileUploadResourceTestBase::testFileUploadUnicodeFilename in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/rest/tests/src/Functional/FileUploadResourceTestBase.php \Drupal\Tests\rest\Functional\FileUploadResourceTestBase::testFileUploadUnicodeFilename()
  2. 10 core/modules/rest/tests/src/Functional/FileUploadResourceTestBase.php \Drupal\Tests\rest\Functional\FileUploadResourceTestBase::testFileUploadUnicodeFilename()

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

File

core/modules/rest/tests/src/Functional/FileUploadResourceTestBase.php, line 411

Class

FileUploadResourceTestBase
Tests binary data file upload route.

Namespace

Drupal\Tests\rest\Functional

Code

public function testFileUploadUnicodeFilename() {
  $this
    ->initAuthentication();
  $this
    ->provisionResource([
    static::$format,
  ], static::$auth ? [
    static::$auth,
  ] : [], [
    'POST',
  ]);
  $this
    ->setUpAuthorization('POST');
  $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
    ->getExpectedNormalizedEntity(1, 'Èxample-✓.txt', TRUE);
  $this
    ->assertResponseData($expected, $response);
  $this
    ->assertSame($this->testFileData, file_get_contents('public://foobar/Èxample-✓.txt'));
}