function FileUploadResourceTestBase::testFileUploadNoExtensionSetting

Same name in other branches
  1. 9 core/modules/rest/tests/src/Functional/FileUploadResourceTestBase.php \Drupal\Tests\rest\Functional\FileUploadResourceTestBase::testFileUploadNoExtensionSetting()
  2. 8.9.x core/modules/rest/tests/src/Functional/FileUploadResourceTestBase.php \Drupal\Tests\rest\Functional\FileUploadResourceTestBase::testFileUploadNoExtensionSetting()
  3. 11.x 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 635

Class

FileUploadResourceTestBase
Tests binary data file upload route.

Namespace

Drupal\Tests\rest\Functional

Code

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.