You are here

function ValidatorTest::testFileValidateSize in Zircon Profile 8

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

Test file_validate_size().

File

core/modules/file/src/Tests/ValidatorTest.php, line 146
Contains \Drupal\file\Tests\ValidatorTest.

Class

ValidatorTest
Tests the functions used to validate uploaded files.

Namespace

Drupal\file\Tests

Code

function testFileValidateSize() {

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