function ValidatorTest::testFileValidateSize

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

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