You are here

function BackupMigrateUnitTest::testSaveToDisk in Backup and Migrate 5

File

tests/BackupMigrateUnitTest.test, line 512

Class

BackupMigrateUnitTest
Unit tests for Backup and Migrate module.

Code

function testSaveToDisk() {
  $directory = file_directory_path() . "/backup_migrate";
  $tempfile = file_directory_temp() . "/" . $this
    ->randomName(10, '');
  $contents = $this
    ->randomName(128, '');
  $filename = $this
    ->randomName(10, '');

  // check manual
  $this
    ->delete_directory($directory);
  file_put_contents($tempfile, $contents);
  _backup_migrate_save_to_disk($tempfile, $filename, 'manual');
  $this
    ->assertTrue(file_exists($directory . '/manual/' . $filename), t('Checking that the file was saved to the server'));
  $this
    ->assertEqual($contents, file_get_contents($directory . '/manual/' . $filename), t('Checking that the file contains the right contents'));
  $this
    ->assertFalse(file_exists($tempfile), t('Checking that the temp file is no longer there'));

  // check scheduled
  $this
    ->delete_directory($directory);
  file_put_contents($tempfile, $contents);
  _backup_migrate_save_to_disk($tempfile, $filename, 'scheduled');
  $this
    ->assertTrue(file_exists($directory . '/scheduled/' . $filename), t('Checking that the file was saved to the server'));
  $this
    ->assertEqual($contents, file_get_contents($directory . '/scheduled/' . $filename), t('Checking that the file contains the right contents'));
  $this
    ->assertFalse(file_exists($tempfile), t('Checking that the temp file is no longer there'));
  $this
    ->delete_directory($directory);
}