You are here

function BackupMigrateUnitTest::testTempFile in Backup and Migrate 5

File

tests/BackupMigrateUnitTest.test, line 347

Class

BackupMigrateUnitTest
Unit tests for Backup and Migrate module.

Code

function testTempFile() {
  $dir = file_directory_path() . "/backup_migrate/manual/";
  _backup_migrate_check_destination_dir('manual');
  for ($i = 0; $i < 5; $i++) {
    $ext = $this
      ->randomName($i, '');
    $files[$i] = _backup_migrate_temp_file($ext);
    touch($files[$i]);
    $this
      ->assertTrue(file_exists($files[$i]), t('Checking that the temporary file is available for writing'));
    $this
      ->assertTrue(file_check_location($files[$i], file_directory_temp()), t('Check that the file is in the temp directory'));
    if ($ext) {
      $this
        ->assertEqual(substr($files[$i], -strlen($ext)), $ext, t('Check that the temp file has the right extension'));
    }
    else {
      $this
        ->assertTrue(strpos($files[$i], '.') === false, $ext, t('Check that the temp file has no extension'));
    }
  }

  // delete them
  _backup_migrate_temp_file(NULL, $true);
  for ($i = 0; $i < 5; $i++) {
    $this
      ->assertFalse(file_exists($file[$i]), t('Check that the temp file has been deleted'));
  }
}