function BackupMigrateFunctionalityTest::testRestoreFromUpload in Backup and Migrate 6.2
Same name and namespace in other branches
- 5 tests/BackupMigrateFunctionalityTest.test \BackupMigrateFunctionalityTest::testRestoreFromUpload()
- 6.3 tests/backup_migrate.functionality.test \BackupMigrateFunctionalityTest::testRestoreFromUpload()
File
- tests/
backup_migrate.functionality.test, line 59
Class
- BackupMigrateFunctionalityTest
- Unit tests for Backup and Migrate module.
Code
function testRestoreFromUpload() {
$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;
// Not logged in
$this
->drupalGet("admin/content/backup_migrate/restore");
$this
->assertResponse(array(
"401",
"403",
), t("Checking that an anonymous user was access denied"));
// user without restore access
// check access only permissions
$permissions = array(
'access backup files',
);
$user = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($user);
$this
->drupalGet("admin/content/backup_migrate/restore");
$this
->assertResponse(array(
"401",
"403",
), t("Checking that a user without 'restore from backup' permission was access denied"));
// user with restore access
// check access only permissions
$permissions = array(
'access backup files',
'restore from backup',
);
$user = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($user);
$this
->drupalGet("admin/content/backup_migrate/restore");
$this
->drupalPost("admin/content/backup_migrate/restore", $edit, t('Restore now'));
// check that the file was imported into the db
$tables = $this
->database_tables();
$this
->assertTrue(isset($tables[$test_table]), t("Checking that the test table is present."));
db_query("DROP TABLE {$test_table};");
$test_table = $this
->randomName(10, 'testtable_');
$file = file_directory_temp() . '/' . $this
->randomName(10, '') . '.sql';
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;
$edit['filters[utils_site_offline]'] = 1;
$this
->drupalGet("admin/content/backup_migrate/restore");
$this
->assertFieldByName('filters[utils_site_offline]', '', t('Checking that the take site offline checbox is present and unchecked.'));
$this
->drupalPost("admin/content/backup_migrate/restore", $edit, t('Restore now'));
// check that the file was imported into the db
$tables = $this
->database_tables();
$this
->assertTrue(isset($tables[$test_table]), t("Checking that the test table is present after site offline test."));
$this
->assertText(t('Site was taken offline.'));
$this
->assertText(t('Site was taken online.'));
$this
->drupalGet("logout");
}