function ValidatorTest::testFileValidateNameLength

This will ensure the filename length is valid.

File

drupal/core/modules/file/lib/Drupal/file/Tests/ValidatorTest.php, line 106
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 testFileValidateNameLength() {

  // Create a new file entity.
  $file = entity_create('file', array());

  // Add a filename with an allowed length and test it.
  $file->filename = str_repeat('x', 240);
  $this
    ->assertEqual(strlen($file->filename), 240);
  $errors = file_validate_name_length($file);
  $this
    ->assertEqual(count($errors), 0, t('No errors reported for 240 length filename.'), 'File');

  // Add a filename with a length too long and test it.
  $file->filename = str_repeat('x', 241);
  $errors = file_validate_name_length($file);
  $this
    ->assertEqual(count($errors), 1, t('An error reported for 241 length filename.'), 'File');

  // Add a filename with an empty string and test it.
  $file->filename = '';
  $errors = file_validate_name_length($file);
  $this
    ->assertEqual(count($errors), 1, t('An error reported for 0 length filename.'), 'File');
}