function ValidatorTest::testFileValidateSize

Test file_validate_size().

File

drupal/core/modules/file/lib/Drupal/file/Tests/ValidatorTest.php, line 131
Definition of Drupal\file\Tests\ValidatorTest.

Class

ValidatorTest
This will run tests against the file validation functions (file_validate_*).

Namespace

Drupal\file\Tests

Code

function testFileValidateSize() {
  global $user;
  $original_user = $user;
  drupal_save_session(FALSE);

  // Run these tests as a regular user.
  $user = $this
    ->drupalCreateUser();

  // 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, t('No limits means no errors.'), 'File');
  $errors = file_validate_size($file, 1, 0);
  $this
    ->assertEqual(count($errors), 1, t('Error for the file being over the limit.'), 'File');
  $errors = file_validate_size($file, 0, 1);
  $this
    ->assertEqual(count($errors), 1, t('Error for the user being over their limit.'), 'File');
  $errors = file_validate_size($file, 1, 1);
  $this
    ->assertEqual(count($errors), 2, t('Errors for both the file and their limit.'), 'File');
  $user = $original_user;
  drupal_save_session(TRUE);
}