You are here

public function ValidatorTest::testFileValidateSize in Drupal 9

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

Tests file_validate_size().

File

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

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.');
}