function FileUploadTest::testFileUploadLargerFileSize
Same name in other branches
- 9 core/modules/jsonapi/tests/src/Functional/FileUploadTest.php \Drupal\Tests\jsonapi\Functional\FileUploadTest::testFileUploadLargerFileSize()
- 10 core/modules/jsonapi/tests/src/Functional/FileUploadTest.php \Drupal\Tests\jsonapi\Functional\FileUploadTest::testFileUploadLargerFileSize()
- 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.
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->assertFileNotExists('public://foobar/example.txt');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.