function LegacyValidatorTest::testFileValidateSize

Same name in other branches
  1. 10 core/modules/file/tests/src/Kernel/LegacyValidatorTest.php \Drupal\Tests\file\Kernel\LegacyValidatorTest::testFileValidateSize()

Tests file_validate_size().

File

core/modules/file/tests/src/Kernel/LegacyValidatorTest.php, line 241

Class

LegacyValidatorTest
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,
    ]);
    $this->expectDeprecation('file_validate_size() is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use the \'file.validator\' service instead. See https://www.drupal.org/node/3363700');
    $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.