You are here

public function FileUploadHandlerTest::testFileSaveUploadSingleErrorFormSize in Drupal 10

Tests file size upload errors.

File

core/modules/file/tests/src/Kernel/FileUploadHandlerTest.php, line 40

Class

FileUploadHandlerTest
Tests the file upload handler.

Namespace

Drupal\Tests\file\Kernel

Code

public function testFileSaveUploadSingleErrorFormSize() {
  $file_name = $this
    ->randomMachineName();
  $file_info = $this
    ->createMock(UploadedFileInterface::class);
  $file_info
    ->expects($this
    ->once())
    ->method('getError')
    ->willReturn(UPLOAD_ERR_FORM_SIZE);
  $file_info
    ->expects($this
    ->once())
    ->method('getClientOriginalName')
    ->willReturn($file_name);
  $file_info
    ->expects($this
    ->once())
    ->method('getErrorMessage')
    ->willReturn(sprintf('The file "%s" could not be saved because it exceeds %s, the maximum allowed size for uploads.', $file_name, format_size(Environment::getUploadMaxSize())));
  $this
    ->expectException(FormSizeFileException::class);
  $this
    ->expectExceptionMessage(sprintf('The file "%s" could not be saved because it exceeds %s, the maximum allowed size for uploads.', $file_name, format_size(Environment::getUploadMaxSize())));
  $this->fileUploadHandler
    ->handleFileUpload($file_info);
}