You are here

public function FileUploadResourceTestBase::testFileUploadNoExtensionSetting in Drupal 9

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

Tests using the file upload POST route no extension configured.

File

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

Class

FileUploadResourceTestBase
Tests binary data file upload route.

Namespace

Drupal\Tests\rest\Functional

Code

public function testFileUploadNoExtensionSetting() {
  $this
    ->initAuthentication();
  $this
    ->provisionResource([
    static::$format,
  ], static::$auth ? [
    static::$auth,
  ] : [], [
    'POST',
  ]);
  $this
    ->setUpAuthorization('POST');
  $uri = Url::fromUri('base:' . static::$postUri);
  $this->field
    ->setSetting('file_extensions', '')
    ->save();
  $this
    ->refreshTestStateAfterRestConfigChange();
  $response = $this
    ->fileRequest($uri, $this->testFileData, [
    'Content-Disposition' => 'filename="example.txt"',
  ]);
  $expected = $this
    ->getExpectedNormalizedEntity(1, 'example.txt', TRUE);
  $this
    ->assertResponseData($expected, $response);
  $this
    ->assertFileExists('public://foobar/example.txt');
}