function FileUploadTest::testFileUploadInvalidFileType

Same name and namespace in other branches
  1. 9 core/modules/jsonapi/tests/src/Functional/FileUploadTest.php \Drupal\Tests\jsonapi\Functional\FileUploadTest::testFileUploadInvalidFileType()
  2. 8.9.x core/modules/jsonapi/tests/src/Functional/FileUploadTest.php \Drupal\Tests\jsonapi\Functional\FileUploadTest::testFileUploadInvalidFileType()
  3. 10 core/modules/jsonapi/tests/src/Functional/FileUploadTest.php \Drupal\Tests\jsonapi\Functional\FileUploadTest::testFileUploadInvalidFileType()

Tests using the file upload route with an invalid file type.

1 call to FileUploadTest::testFileUploadInvalidFileType()
FileUploadTest::testInvalidFileUploads in core/modules/jsonapi/tests/src/Functional/FileUploadTest.php
Tests invalid file uploads.

File

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

Class

FileUploadTest
Tests binary data file upload route.

Namespace

Drupal\Tests\jsonapi\Functional

Code

protected function testFileUploadInvalidFileType() {
    $uri = Url::fromUri('base:' . static::$postUri);
    // Test with a JSON file.
    $response = $this->fileRequest($uri, '{"test":123}', [
        'Content-Disposition' => 'filename="example.json"',
    ]);
    $this->assertResourceErrorResponse(422, PlainTextOutput::renderFromHtml("Unprocessable Entity: file validation failed.\nOnly files with the following extensions are allowed: <em class=\"placeholder\">txt</em>."), $uri, $response);
    // Make sure that no file was saved.
    $this->assertEmpty(File::load(1));
    $this->assertFileDoesNotExist('public://foobar/example.txt');
}

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