class FileModuleTest

Tests file.module methods.

@group file

Hierarchy

  • class \Drupal\Tests\file\Kernel\FileModuleTest extends \Drupal\KernelTests\KernelTestBase

Expanded class hierarchy of FileModuleTest

File

core/modules/file/tests/src/Kernel/FileModuleTest.php, line 15

Namespace

Drupal\Tests\file\Kernel
View source
class FileModuleTest extends KernelTestBase {
  
  /**
   * {@inheritdoc}
   */
  public static $modules = [
    'file',
  ];
  
  /**
   * Tests file size upload errors.
   *
   * @throws \Drupal\Core\Entity\EntityStorageException
   */
  public function testFileSaveUploadSingleErrorFormSize() {
    $file_name = $this->randomMachineName();
    $file_info = $this->createMock(UploadedFile::class);
    $file_info->expects($this->once())
      ->method('getError')
      ->willReturn(UPLOAD_ERR_FORM_SIZE);
    $file_info->expects($this->once())
      ->method('getClientOriginalName')
      ->willReturn($file_name);
    $this->assertFalse(\_file_save_upload_single($file_info, 'name'));
    $expected_message = new TranslatableMarkup('The file %file could not be saved because it exceeds %maxsize, the maximum allowed size for uploads.', [
      '%file' => $file_name,
      '%maxsize' => format_size(Environment::getUploadMaxSize()),
    ]);
    $this->assertEquals($expected_message, \Drupal::messenger()->all()['error'][0]);
  }

}

Members

Title Sort descending Modifiers Object type Summary
FileModuleTest::$modules public static property
FileModuleTest::testFileSaveUploadSingleErrorFormSize public function Tests file size upload errors.

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