View source
<?php
namespace Drupal\Tests\backup_migrate\Functional;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Tests\BrowserTestBase;
class AdminFunctionalityTest extends BrowserTestBase {
public static $modules = [
'backup_migrate',
];
protected $strictConfigSchema = FALSE;
protected $defaultTheme = 'stark';
public function setUp() {
parent::setUp();
$this->container
->get('router.builder')
->rebuild();
$path = 'private://backup_migrate/';
\Drupal::service('file_system')
->prepareDirectory($path, FileSystemInterface::CREATE_DIRECTORY);
$account = $this
->drupalCreateUser([
'access backup files',
'administer backup and migrate',
'perform backup',
'restore from backup',
'administer site configuration',
]);
$this
->drupalLogin($account);
}
public function testPages($path, $string_on_page) {
$this
->drupalGet($path);
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains($string_on_page);
}
public function pagesListProvider() {
return [
[
'admin/config/development/backup_migrate',
'Quick Backup',
],
[
'admin/config/development/backup_migrate/advanced',
'Advanced Backup',
],
[
'admin/config/development/backup_migrate/restore',
'Restore',
],
[
'admin/config/development/backup_migrate/backups',
'Backups',
],
[
'admin/config/development/backup_migrate/schedule',
'Schedule',
],
[
'admin/config/development/backup_migrate/schedule/add',
'Add schedule',
],
[
'admin/config/development/backup_migrate/settings',
'Settings',
],
[
'admin/config/development/backup_migrate/settings/add',
'Add settings profile',
],
[
'admin/config/development/backup_migrate/settings/destination',
'Backup Destination',
],
[
'admin/config/development/backup_migrate/settings/destination/add',
'Add destination',
],
[
'admin/config/development/backup_migrate/settings/source',
'Backup sources',
],
[
'admin/config/development/backup_migrate/settings/source/add',
'Add Backup Source',
],
];
}
public function testDestinationsAdmin() {
$this
->drupalGet('admin/config/development/backup_migrate/settings/destination');
$session = $this
->assertSession();
$session
->statusCodeEquals(200);
$session
->pageTextContains('Backup Destination');
$session
->pageTextContains('Private Files Directory');
$session
->pageTextContains('private_files');
$session
->pageTextContains('Server File Directory');
$this
->drupalGet('admin/config/development/backup_migrate/settings/destination/add');
$session = $this
->assertSession();
$session
->statusCodeEquals(200);
$session
->pageTextContains('Add destination');
$session
->fieldExists('label');
$session
->fieldExists('id');
$session
->fieldExists('type');
$session
->buttonExists('Save and edit');
$edit = [
'label' => 'Test destination',
'id' => 'test_destination',
'type' => 'Directory',
];
$this
->drupalPostForm(NULL, $edit, 'Save and edit');
$session = $this
->assertSession();
$session
->statusCodeEquals(200);
$session
->addressEquals('admin/config/development/backup_migrate/settings/destination/edit/test_destination');
$session
->pageTextContains('Created Test destination.');
$session
->fieldExists('label');
$session
->fieldExists('config[directory]');
$session
->buttonExists('Save');
$session
->linkExists('Delete');
$edit = [
'config[directory]' => 'test_path',
];
$this
->drupalPostForm(NULL, $edit, 'Save');
$session = $this
->assertSession();
$session
->statusCodeEquals(200);
$session
->addressEquals('admin/config/development/backup_migrate/settings/destination');
$session
->pageTextContains('Saved Test destination.');
$session
->pageTextContains('Private Files Directory');
$session
->pageTextContains('private_files');
$session
->pageTextContains('Test destination');
$session
->pageTextContains('test_destination');
}
public function testSourcesAdmin() {
$this
->drupalGet('admin/config/development/backup_migrate/settings/source');
$session = $this
->assertSession();
$session
->statusCodeEquals(200);
$session
->pageTextContains('Backup Source');
$session
->pageTextContains('Default Drupal Database');
$session
->pageTextContains('default_db');
$session
->pageTextContains('Default Database');
$session
->pageTextContains('Entire Site');
$session
->pageTextContains('entire_site');
$session
->pageTextContains('Entire Site');
$session
->pageTextContains('Private Files Directory');
$session
->pageTextContains('private_files');
$session
->pageTextContains('Public Files');
$this
->drupalGet('admin/config/development/backup_migrate/settings/source/add');
$session = $this
->assertSession();
$session
->statusCodeEquals(200);
$session
->pageTextContains('Add Backup Source');
$session
->fieldExists('label');
$session
->fieldExists('type');
$session
->buttonExists('Save and edit');
$edit = [
'label' => 'Test FileDirectory source',
'id' => 'test_filedirectory_source',
'type' => 'FileDirectory',
];
$this
->drupalPostForm(NULL, $edit, 'Save and edit');
$session = $this
->assertSession();
$session
->statusCodeEquals(200);
$session
->addressEquals('admin/config/development/backup_migrate/settings/source/edit/test_filedirectory_source');
$session
->pageTextContains('Created Test FileDirectory source.');
$session
->fieldExists('label');
$session
->fieldExists('config[directory]');
$session
->buttonExists('Save');
$session
->linkExists('Delete');
$edit = [
'config[directory]' => 'test_path',
];
$this
->drupalPostForm(NULL, $edit, 'Save');
$session = $this
->assertSession();
$session
->statusCodeEquals(200);
$session
->addressEquals('admin/config/development/backup_migrate/settings/source');
$session
->pageTextContains('Saved Test FileDirectory source.');
$session
->pageTextContains('Default Drupal Database');
$session
->pageTextContains('default_db');
$session
->pageTextContains('Entire Site');
$session
->pageTextContains('entire_site');
$session
->pageTextContains('Private Files Directory');
$session
->pageTextContains('private_files');
$session
->pageTextContains('Test FileDirectory source');
$session
->pageTextContains('test_filedirectory_source');
$session
->pageTextContains('File Directory');
$this
->drupalGet('admin/config/development/backup_migrate/settings/source/add');
$session = $this
->assertSession();
$session
->statusCodeEquals(200);
$session
->pageTextContains('Add Backup Source');
$session
->fieldExists('label');
$session
->fieldExists('type');
$session
->buttonExists('Save and edit');
$edit = [
'label' => 'Test MySQL source',
'id' => 'test_mysql_source',
'type' => 'MySQL',
];
$this
->drupalPostForm(NULL, $edit, 'Save and edit');
$session = $this
->assertSession();
$session
->statusCodeEquals(200);
$session
->addressEquals('admin/config/development/backup_migrate/settings/source/edit/test_mysql_source');
$session
->pageTextContains('Created Test MySQL source.');
$session
->fieldExists('label');
$session
->fieldExists('config[host]');
$session
->fieldExists('config[database]');
$session
->fieldExists('config[username]');
$session
->fieldExists('config[password]');
$session
->fieldExists('config[port]');
$session
->buttonExists('Save');
$session
->linkExists('Delete');
$edit = [
'config[host]' => 'test_host',
'config[database]' => 'test_dbname',
'config[username]' => 'test_user',
'config[password]' => 'test_pw',
'config[port]' => '12345',
];
$this
->drupalPostForm(NULL, $edit, 'Save');
$session = $this
->assertSession();
$session
->statusCodeEquals(200);
$session
->addressEquals('admin/config/development/backup_migrate/settings/source');
$session
->pageTextContains('Saved Test MySQL source.');
$session
->pageTextContains('Default Drupal Database');
$session
->pageTextContains('default_db');
$session
->pageTextContains('Entire Site');
$session
->pageTextContains('entire_site');
$session
->pageTextContains('Private Files Directory');
$session
->pageTextContains('private_files');
$session
->pageTextContains('Test MySQL source');
$session
->pageTextContains('test_mysql_source');
$session
->pageTextContains('MySQL Database');
}
public function testSchedulesAdmin() {
$this
->drupalGet('admin/config/development/backup_migrate/schedule');
$session = $this
->assertSession();
$session
->statusCodeEquals(200);
$session
->pageTextContains('Schedule Name');
$session
->pageTextContains('Enabled');
$session
->pageTextContains('Frequency');
$session
->pageTextContains('Last Run');
$session
->pageTextContains('Next Run');
$session
->pageTextContains('Keep');
$session
->pageTextContains('Daily Schedule');
$session
->pageTextContains('No');
$session
->pageTextContains('Every 0 weeks');
$session
->pageTextContains('Never');
$session
->pageTextContains('Disabled');
$session
->pageTextContains('Last backups');
$this
->drupalGet('admin/config/development/backup_migrate/schedule/edit/daily_schedule');
$session = $this
->assertSession();
$session
->statusCodeEquals(200);
$session
->fieldExists('Schedule enabled');
$edit = [
'enabled' => TRUE,
'period_number' => 1,
'period_type' => 'days',
];
$this
->drupalPostForm(NULL, $edit, 'Save');
$session = $this
->assertSession();
$session
->statusCodeEquals(200);
$session
->pageTextContains('Saved the Daily Schedule Schedule.');
$session
->pageTextContains('Yes');
$session
->pageTextContains('Daily');
$session
->pageTextContains('Never');
$session
->pageTextContains('Next cron run');
$session
->pageTextNotContains('Disabled');
$this
->drupalGet('admin/config/development/backup_migrate/schedule/add');
$session = $this
->assertSession();
$session
->statusCodeEquals(200);
$session
->pageTextContains('Add schedule');
$session
->fieldExists('label');
$session
->fieldExists('id');
$session
->fieldExists('enabled');
$session
->fieldExists('source_id');
$session
->fieldExists('destination_id');
$session
->fieldExists('period_number');
$session
->fieldExists('period_type');
$session
->fieldExists('keep');
$session
->buttonExists('Save');
$edit = [
'label' => 'Test schedule',
'id' => 'test_schedule',
'enabled' => TRUE,
'source_id' => 'default_db',
'destination_id' => 'private_files',
'period_number' => 14400,
'period_type' => 'minutes',
'keep' => 1000,
];
$this
->drupalPostForm(NULL, $edit, 'Save');
$session = $this
->assertSession();
$session
->statusCodeEquals(200);
$session
->addressEquals('admin/config/development/backup_migrate/schedule');
$session
->pageTextContains('Created the Test schedule Schedule.');
$session
->pageTextContains('Every 10 days');
$session
->pageTextContains('Last 1000 backups');
$session
->pageTextContains('Yes');
}
public function testProfilesAdmin() {
$this
->drupalGet('admin/config/development/backup_migrate/settings');
$session = $this
->assertSession();
$session
->statusCodeEquals(200);
$session
->pageTextContains('Settings');
$session
->pageTextContains('Profile Name');
$this
->drupalGet('admin/config/development/backup_migrate/settings/add');
$session = $this
->assertSession();
$session
->statusCodeEquals(200);
$session
->pageTextContains('Add settings profile');
$session
->fieldExists('label');
$session
->fieldExists('id');
$session
->fieldExists('config[namer][filename]');
$session
->fieldExists('config[namer][timestamp]');
$session
->fieldExists('config[namer][timestamp_format]');
$session
->fieldExists('config[compressor][compression]');
$session
->fieldExists('config[utils][site_offline]');
$session
->fieldExists('config[metadata][description]');
$session
->fieldExists('config[db_exclude][exclude_tables][]');
$session
->fieldExists('config[db_exclude][nodata_tables][]');
$session
->fieldExists('config[private_files_exclude][exclude_filepaths]');
$session
->fieldExists('config[public_files_exclude][exclude_filepaths]');
$session
->buttonExists('Save');
$edit = [
'label' => 'Test profile',
'id' => 'test_profile',
'config[namer][filename]' => 'test_backup',
'config[namer][timestamp]' => 'Y-m-d\\TH-i-s',
'config[compressor][compression]' => 'none',
'config[utils][site_offline]' => 1,
'config[metadata][description]' => 'Test description text.',
'config[db_exclude][exclude_tables][]' => [],
'config[db_exclude][nodata_tables][]' => [],
'config[private_files_exclude][exclude_filepaths]' => 'test_private_exclude',
'config[public_files_exclude][exclude_filepaths]' => 'test_public_exclude',
];
$this
->drupalPostForm(NULL, $edit, 'Save');
$session = $this
->assertSession();
$session
->statusCodeEquals(200);
$session
->addressEquals('admin/config/development/backup_migrate/settings');
$session
->pageTextContains('Created the Test profile Settings Profile.');
$session
->pageTextContains('Profile Name');
$session
->pageTextContains('Machine name');
$session
->pageTextContains('Compression');
$session
->pageTextContains('Take site offline');
$session
->pageTextContains('Description');
$session
->pageTextContains('Test profile');
$session
->pageTextContains('test_profile');
$session
->pageTextContains('none');
$session
->pageTextContains('1');
$session
->pageTextContains('Test description text.');
}
public function testCron() {
$this
->drupalGet('admin/config/development/backup_migrate/schedule/edit/daily_schedule');
$session = $this
->assertSession();
$session
->statusCodeEquals(200);
$session
->fieldExists('Schedule enabled');
$edit = [
'enabled' => TRUE,
'period_number' => 1,
'period_type' => 'days',
];
$this
->drupalPostForm(NULL, $edit, 'Save');
$session = $this
->assertSession();
$session
->statusCodeEquals(200);
$session
->pageTextContains('Saved the Daily Schedule Schedule.');
$session
->pageTextContains('Never');
$session
->pageTextContains('Next cron run');
$this
->drupalGet('admin/config/development/backup_migrate/settings/destination/backups/private_files');
$session = $this
->assertSession();
$session
->statusCodeEquals(200);
$session
->pageTextContains('There are no backups in this destination.');
$this
->drupalGet('admin/reports/status');
$session = $this
->assertSession();
$session
->statusCodeEquals(200);
$session
->linkExists('Run cron');
$this
->clickLink('Run cron');
$session = $this
->assertSession();
$session
->statusCodeEquals(200);
$session
->addressEquals('admin/reports/status');
$session
->pageTextContains('Cron ran successfully.');
$this
->drupalGet('admin/config/development/backup_migrate/schedule/edit/daily_schedule');
$session = $this
->assertSession();
$session
->statusCodeEquals(200);
$this
->drupalGet('admin/config/development/backup_migrate/settings/destination/backups/private_files');
$session = $this
->assertSession();
$session
->statusCodeEquals(200);
$session
->pageTextNotContains('There are no backups in this destination.');
}
}