public function FileUploadTest::testFileUploadLargerFileSize in Drupal 9
Same name and namespace in other branches
- 8 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.
File
- core/
modules/ jsonapi/ tests/ src/ Functional/ FileUploadTest.php, line 584
Class
- FileUploadTest
- Tests binary data file upload route.
Namespace
Drupal\Tests\jsonapi\FunctionalCode
public function testFileUploadLargerFileSize() {
// Set a limit of 50 bytes.
$this->field
->setSetting('max_filesize', 50)
->save();
$this
->rebuildAll();
$this
->setUpAuthorization('POST');
$this
->config('jsonapi.settings')
->set('read_only', FALSE)
->save(TRUE);
$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');
}