function FileUploadTest::testPostFileUploadInvalidHeaders

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

Tests using the file upload POST route with invalid headers.

1 call to FileUploadTest::testPostFileUploadInvalidHeaders()
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 367

Class

FileUploadTest
Tests binary data file upload route.

Namespace

Drupal\Tests\jsonapi\Functional

Code

protected function testPostFileUploadInvalidHeaders() {
    $uri = Url::fromUri('base:' . static::$postUri);
    // The wrong content type header should return a 415 code.
    $response = $this->fileRequest($uri, $this->testFileData, [
        'Content-Type' => 'application/vnd.api+json',
    ]);
    $this->assertSame(415, $response->getStatusCode());
    // An empty Content-Disposition header should return a 400.
    $response = $this->fileRequest($uri, $this->testFileData, [
        'Content-Disposition' => FALSE,
    ]);
    $this->assertResourceErrorResponse(400, '"Content-Disposition" header is required. A file name in the format "filename=FILENAME" must be provided.', $uri, $response);
    // An empty filename with a context in the Content-Disposition header should
    // return a 400.
    $response = $this->fileRequest($uri, $this->testFileData, [
        'Content-Disposition' => 'file; filename=""',
    ]);
    $this->assertResourceErrorResponse(400, 'No filename found in "Content-Disposition" header. A file name in the format "filename=FILENAME" must be provided.', $uri, $response);
    // An empty filename without a context in the Content-Disposition header
    // should return a 400.
    $response = $this->fileRequest($uri, $this->testFileData, [
        'Content-Disposition' => 'filename=""',
    ]);
    $this->assertResourceErrorResponse(400, 'No filename found in "Content-Disposition" header. A file name in the format "filename=FILENAME" must be provided.', $uri, $response);
    // An invalid key-value pair in the Content-Disposition header should return
    // a 400.
    $response = $this->fileRequest($uri, $this->testFileData, [
        'Content-Disposition' => 'not_a_filename="example.txt"',
    ]);
    $this->assertResourceErrorResponse(400, 'No filename found in "Content-Disposition" header. A file name in the format "filename=FILENAME" must be provided.', $uri, $response);
    // Using filename* extended format is not currently supported.
    $response = $this->fileRequest($uri, $this->testFileData, [
        'Content-Disposition' => 'filename*="UTF-8 \' \' example.txt"',
    ]);
    $this->assertResourceErrorResponse(400, 'The extended "filename*" format is currently not supported in the "Content-Disposition" header.', $uri, $response);
}

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