BackupMigrateQuickBackupTest.php in Backup and Migrate 5.0.x
File
tests/src/Functional/BackupMigrateQuickBackupTest.php
View source
<?php
namespace Drupal\Tests\backup_migrate\Functional;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Tests\BrowserTestBase;
class BackupMigrateQuickBackupTest extends BrowserTestBase {
use StringTranslationTrait;
public static $modules = [
'backup_migrate',
];
protected $strictConfigSchema = FALSE;
protected $defaultTheme = 'stark';
public function setUp() : void {
parent::setUp();
$path = 'private://backup_migrate/';
\Drupal::service('file_system')
->prepareDirectory($path, FileSystemInterface::CREATE_DIRECTORY);
$this
->drupalLogin($this
->drupalCreateUser([
'perform backup',
'access backup files',
'administer backup and migrate',
'administer site configuration',
]));
$this
->drupalGet('admin/config/media/file-system');
}
public function testQuickBackup() {
$this
->drupalGet('admin/config/development/backup_migrate');
$this
->assertSession()
->statusCodeEquals(200);
$data = [
'source_id' => 'default_db',
'destination_id' => 'private_files',
];
$this
->submitForm($data, $this
->t('Backup now'));
$this
->assertSession()
->pageTextContains('Backup Complete.');
$this
->drupalGet('admin/config/development/backup_migrate/backups');
$this
->assertSession()
->statusCodeEquals(200);
$page = $this
->getSession()
->getPage();
$table = $page
->find('css', 'table');
$row = $table
->find('css', sprintf('tbody tr:contains("%s")', '.mysql.gz'));
$this
->assertNotNull($row);
}
public function testBackupsCanBeRestored() {
$this
->testQuickBackup();
$this
->drupalGet('admin/config/development/backup_migrate/settings/destination/backups/private_files');
$session = $this
->assertSession();
$session
->statusCodeEquals(200);
$session
->linkExists('Restore');
$this
->clickLink('Restore');
$session = $this
->assertSession();
$session
->statusCodeEquals(200);
$session
->pageTextContains('Are you sure you want to restore this backup?');
$this
->submitForm([], 'Restore');
$session = $this
->assertSession();
$session
->statusCodeEquals(200);
$session
->addressEquals('admin/config/development/backup_migrate/settings/destination/backups/private_files');
$session
->pageTextContains('Restore Complete.');
}
public function testBackupsCanBeDeleted() {
$this
->testQuickBackup();
$this
->drupalGet('admin/config/development/backup_migrate/settings/destination/backups/private_files');
$session = $this
->assertSession();
$session
->statusCodeEquals(200);
$session
->linkExists('Delete');
$this
->clickLink('Delete');
$session = $this
->assertSession();
$session
->statusCodeEquals(200);
$session
->pageTextContains('Are you sure you want to delete this backup?');
$session
->pageTextNotContains('This will permanently remove from Private Files Directory.');
$this
->submitForm([], 'Delete');
$session = $this
->assertSession();
$session
->statusCodeEquals(200);
$session
->addressEquals('admin/config/development/backup_migrate/settings/destination/backups/private_files');
$session
->pageTextContains('There are no backups in this destination.');
}
}