You are here

function BackupMigrateFunctionalityTest::testRestoreFromUpload in Backup and Migrate 5

Same name and namespace in other branches
  1. 6.3 tests/backup_migrate.functionality.test \BackupMigrateFunctionalityTest::testRestoreFromUpload()
  2. 6.2 tests/backup_migrate.functionality.test \BackupMigrateFunctionalityTest::testRestoreFromUpload()

File

tests/BackupMigrateFunctionalityTest.test, line 409

Class

BackupMigrateFunctionalityTest
Unit tests for Backup and Migrate module.

Code

function testRestoreFromUpload() {
  $directory = _backup_migrate_check_destination_dir($type);
  $file = file_directory_temp() . '/' . $this
    ->randomName(10, '') . '.sql';
  $test_table = $this
    ->randomName(10, 'testtable_');
  file_put_contents($file, "CREATE TABLE {$test_table} (testid int(10));");
  $this
    ->assertTrue(file_exists($file), t("Reality checking that the test file was created"));
  $edit = array();
  $edit['files[backup_migrate_restore_upload]'] = $file;

  // user without restore access
  // check access only permissions
  $permissions = array(
    'access backup files',
  );
  $user = $this
    ->drupalCreateUserRolePerm($permissions);
  $this
    ->drupalLoginUser($user);
  $this
    ->drupalGet(url("admin/content/backup_migrate/restore/", NULL, NULL, TRUE));
  $this
    ->assertResponse(array(
    "401",
    "403",
  ), t("Checking that the user was access denied"));
  $this
    ->post(url("admin/content/backup_migrate/restore/", NULL, NULL, TRUE), $edit);
  $this
    ->assertResponse(array(
    "401",
    "403",
  ), t("Checking that the user was access denied"));
  $this
    ->drupalGet(url("logout", NULL, NULL, TRUE));

  // user with restore access
  // check access only permissions
  $permissions = array(
    'access backup files',
    'restore from backup',
  );
  $user = $this
    ->drupalCreateUserRolePerm($permissions);
  $this
    ->drupalLoginUser($user);
  $this
    ->drupalGet(url("admin/content/backup_migrate/restore/", NULL, NULL, TRUE));
  $this
    ->assertSubmit(t("Restore Database"), t('Checking that the restore button is there'));
  $this
    ->drupalPostRequest("admin/content/backup_migrate/restore/", $edit, t('Restore Database'));

  // check that the file was imported into the db
  $this
    ->assertTrue(in_array($test_table, _backup_migrate_get_table_names()), t("Checking that the test table is present."));
  $this
    ->drupalGet(url("logout", NULL, NULL, TRUE));
  db_query("DROP TABLE {$test_table};");
}