You are here

function FileValidatorTest::testFileValidateNameLength in SimpleTest 7

This will ensure the filename length is valid.

File

tests/file.test, line 432
This provides SimpleTests for the core file handling functionality. These include FileValidateTest and FileSaveTest.

Class

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

Code

function testFileValidateNameLength() {

  // Create a new file object.
  $file = new stdClass();

  // 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');
}