backup_migrate.unit.test in Backup and Migrate 6.3
File
tests/backup_migrate.unit.test
View source
<?php
class BackupMigrateUnitTest extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Backup and Migrate Unit Testing',
'desc' => 'Executes the unit test suite for backup and migrate.',
'group' => 'Backup and Migrate module',
);
}
function setUp() {
}
function tearDown() {
}
function testTakeOfflineOnline() {
require_once './' . drupal_get_path('module', 'backup_migrate') . "/includes/filters.inc";
require_once './' . drupal_get_path('module', 'backup_migrate') . "/includes/filters.utils.inc";
$offline_message = filter_xss_admin(variable_get('site_offline_message', t('@site is currently under maintenance. We should be back shortly. Thank you for your patience.', array(
'@site' => variable_get('site_name', 'Drupal'),
))));
$util = new backup_migrate_filter_utils();
$settings = (object) array(
'filters' => array(
'utils_site_offline' => TRUE,
),
);
$util
->take_site_offline($settings);
$this
->drupalGet('');
$this
->assertText($offline_message);
$util
->take_site_online($settings);
$this
->drupalGet('');
$this
->assertNoText($offline_message);
$custom_message = $this
->randomName(50);
$settings = (object) array(
'filters' => array(
'utils_site_offline' => TRUE,
'utils_site_offline_message' => $custom_message,
),
);
$util
->take_site_offline($settings);
$this
->drupalGet('');
$this
->assertText($custom_message);
$util
->take_site_online($settings);
$this
->drupalGet('');
$this
->assertNoText($custom_message);
$this
->assertEqual(variable_get('site_offline_message', ''), $offline_message, t('Checking that the offline message was set back to what it was.'));
}
private function outputScreenContents($description, $basename) {
$file_dir = file_directory_path() . '/../simpletest_output_pages';
if (!is_dir($file_dir)) {
mkdir($file_dir, 0777, TRUE);
}
$output_path = "{$file_dir}/{$basename}." . $this
->randomName(10) . '.html';
$rv = file_put_contents($output_path, $this
->drupalGetContent());
$this
->pass("{$description}: Contents of result page are " . l('here', $output_path));
}
}