function FileUploadTest::testFileUploadLargerFileSize

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

Tests using the file upload route with a file size larger than allowed.

1 call to FileUploadTest::testFileUploadLargerFileSize()
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 560

Class

FileUploadTest
Tests binary data file upload route.

Namespace

Drupal\Tests\jsonapi\Functional

Code

protected function testFileUploadLargerFileSize() {
    // Set a limit of 50 bytes.
    $this->field
        ->setSetting('max_filesize', 50)
        ->save();
    \Drupal::service('router.builder')->rebuild();
    $uri = Url::fromUri('base:' . static::$postUri);
    // Generate a string larger than the 50 byte limit set.
    $response = $this->fileRequest($uri, $this->randomString(100));
    $this->assertResourceErrorResponse(422, PlainTextOutput::renderFromHtml("Unprocessable Entity: file validation failed.\nThe file is <em class=\"placeholder\">100 bytes</em> exceeding the maximum file size of <em class=\"placeholder\">50 bytes</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.