1 backup.test public BackupUpdateTestCase::testUpdateWithBackup()

Tests running an update with a backup and then restoring it.

File

core/modules/simpletest/tests/backup.test, line 337
Test classes for verifying Backup and Restore functionality.

Class

BackupUpdateTestCase
Tests backup and restore via update.php and restore.php.

Code

public function testUpdateWithBackup() {
  $this->backdropLogin($this->adminUser);

  // Store the original site name.
  $original_site_name = 'Original site name ' . $this->randomName(16);
  $edit = array(
    'site_name' => $original_site_name,
  );
  $this->backdropPost('admin/config/system/site-information', $edit, t('Save configuration'));

  // Create a few pieces of content to confirm they exist after restore.
  $test_node1 = $this->backdropCreateNode();
  $test_user1 = $this->backdropCreateUser();

  $this->performUpgradeWithBackup();

  // Create content after creating the backup.
  $test_node2 = $this->backdropCreateNode();
  $test_user2 = $this->backdropCreateUser();

  // Change the site name to test configuration being reverted.
  $new_site_name = 'New site name ' . $this->randomName(16);
  $edit = array(
    'site_name' => $new_site_name,
  );
  $this->backdropPost('admin/config/system/site-information', $edit, t('Save configuration'));
  $this->assertText(t('The configuration options have been saved.'));

  $this->backdropGet('<front>');
  $this->assertText($new_site_name);
  $this->assertNoText($original_site_name);

  $this->restoreBackup();

  $this->backdropGet('<front>');
  $this->assertText('Powered by Backdrop CMS', 'The home page of the restored site loads successfully.');

  // Verify the site title has been reverted.
  $this->assertText($original_site_name);
  $this->assertNoText($new_site_name);

  // Verify content before the backup still exists.
  $this->backdropGet('node/' . $test_node1->nid);
  $this->assertResponse(200, 'Test content from before backup is accessible.');
  $this->backdropGet('user/' . $test_user1->uid);
  $this->assertResponse(200, 'Test user from before backup is accessible.');

  // Verify the content after the backup has been wiped out.
  $this->backdropGet('node/' . $test_node2->nid);
  $this->assertResponse(404, 'Test content from after backup has been removed.');
  $this->backdropGet('user/' . $test_user2->uid);
  $this->assertResponse(404, 'Test user from after backup has been removed.');
}