You are here

public function ValidatorTest::testFileValidateSize in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/file/tests/src/Kernel/ValidatorTest.php \Drupal\Tests\file\Kernel\ValidatorTest::testFileValidateSize()

Test file_validate_size().

File

core/modules/file/tests/src/Kernel/ValidatorTest.php, line 145

Class

ValidatorTest
Tests the functions used to validate uploaded files.

Namespace

Drupal\Tests\file\Kernel

Code

public function testFileValidateSize() {

  // Create a file with a size of 1000 bytes, and quotas of only 1 byte.
  $file = File::create([
    'filesize' => 1000,
  ]);
  $errors = file_validate_size($file, 0, 0);
  $this
    ->assertCount(0, $errors, 'No limits means no errors.');
  $errors = file_validate_size($file, 1, 0);
  $this
    ->assertCount(1, $errors, 'Error for the file being over the limit.');
  $errors = file_validate_size($file, 0, 1);
  $this
    ->assertCount(1, $errors, 'Error for the user being over their limit.');
  $errors = file_validate_size($file, 1, 1);
  $this
    ->assertCount(2, $errors, 'Errors for both the file and their limit.');
}