You are here

function BackupMigrateUnitTest::testCleanFileName in Backup and Migrate 5

File

tests/BackupMigrateUnitTest.test, line 261

Class

BackupMigrateUnitTest
Unit tests for Backup and Migrate module.

Code

function testCleanFileName() {

  // for the purposes of this module, safe filenames only contain letters, numbers, dots, dashes and underscores
  $safe_pattern = "/[A-Za-z0-9\\-\\_\\.]+/";

  // test the cleaning power
  $unsafe_name = "@#/\$he*ll&o, world!";
  $safe_name = _backup_migrate_clean_filename($unsafe_name);
  $this
    ->assertTrue(preg_match($safe_pattern, $safe_name), t('Testing that filename does not contain unsafe characters'));
  $this
    ->assertEqual($safe_name, "helloworld", t('Testing that filename is consistent with input'));

  // check shortening
  $unsafe_name = str_repeat("abc", 50);
  $safe_name = _backup_migrate_clean_filename($unsafe_name);
  $this
    ->assertTrue(strlen($safe_name) <= 50, t('Testing that filename is not too long'));

  // check empty string
  $safe_name = _backup_migrate_clean_filename("");
  $this
    ->assertTrue(strlen($safe_name) > 1, t('Testing that filename is not non existant'));
}