BmTestProfiles.test 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. /**
  3. * @file
  4. * Tests the profiles functionality.
  5. */
  6. /**
  7. * Test that the front page still loads.
  8. */
  9. class BmTestProfiles extends BmTestBase {
  10. /**
  11. * Define this test class.
  12. */
  13. public static function getInfo() {
  14. return array(
  15. 'name' => 'Profiles tests',
  16. 'description' => 'Run through basic scenarios and functionality.',
  17. 'group' => 'backup_migrate',
  18. );
  19. }
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public function setUp(array $modules = array()) {
  24. parent::setUp($modules);
  25. // Log in as user 1, so that permissions are irrelevant.
  26. $this->loginUser1();
  27. }
  28. /**
  29. * Verify the profile page has the expected functionality available.
  30. */
  31. public function testProfilePage() {
  32. // Load the main B&M page.
  33. $this->drupalGet(BACKUP_MIGRATE_MENU_PATH . '/settings');
  34. $this->assertResponse(200);
  35. // Confirm the page has the expected settings details.
  36. $this->assertText('Settings Profiles');
  37. $this->assertText('Default Settings');
  38. $this->assertLink('Create a new settings profile');
  39. }
  40. /**
  41. * Confirm adding a new backup process works.
  42. */
  43. public function testAddDefaultProfile() {
  44. require_once dirname(__FILE__) . '/../includes/files.inc';
  45. require_once dirname(__FILE__) . '/../includes/profiles.inc';
  46. // Load the main B&M page.
  47. $this->drupalGet(BACKUP_MIGRATE_MENU_PATH . '/settings/profile/add');
  48. $this->assertResponse(200);
  49. $filename = _backup_migrate_default_filename();
  50. $defaults = _backup_migrate_profile_default_profile();
  51. // Verify all of the expected fields exist.
  52. $this->assertFieldByName('name');
  53. $this->assertFieldByName('name', 'Untitled Profile');
  54. $this->assertFieldByName('machine_name');
  55. $this->assertFieldByName('filename');
  56. $this->assertFieldByName('filename', $filename);
  57. // @todo Confirm all of the expected options are present.
  58. $this->assertFieldByName('append_timestamp');
  59. $this->assertFieldByName('timestamp_format');
  60. $this->assertFieldByName('timestamp_format', $defaults['timestamp_format']);
  61. $this->assertFieldByName('filters[compression]');
  62. $items = $this->supportedCompressors();
  63. $this->assertSelectOptions('edit-filters-compression', $items);
  64. $this->assertOptionSelected('edit-filters-compression', 'gzip');
  65. $this->assertFieldByName('filters[sources][db][exclude_tables][]');
  66. $this->assertFieldByName('filters[sources][db][nodata_tables][]');
  67. $this->assertFieldByName('filters[sources][db][utils_lock_tables]');
  68. $this->assertFieldByName('filters[sources][files][exclude_filepaths]');
  69. $this->assertFieldByName('filters[sources][archive][exclude_filepaths]');
  70. $this->assertFieldByName('filters[utils_site_offline]');
  71. $this->assertFieldByName('filters[utils_site_offline_message]');
  72. $this->assertFieldByName('filters[utils_description]');
  73. $this->assertFieldByName('filters[use_cli]');
  74. $this->assertFieldByName('filters[ignore_errors]');
  75. $this->assertFieldByName('filters[notify_success_enable]');
  76. $this->assertFieldByName('filters[notify_success_email]');
  77. $this->assertFieldByName('filters[notify_failure_enable]');
  78. $this->assertFieldByName('filters[notify_failure_email]');
  79. }
  80. /**
  81. * Confirm the backup filename processes work as expected.
  82. */
  83. public function testFilenameOptions() {
  84. // Load the profile. This will be interacted with directly because otherwise
  85. // the number of form fields will likely make it impossible to execute
  86. // properly due to the max_input_vars setting defaulting to 1000.
  87. $profile = $this->getProfile();
  88. // Run a backup.
  89. $this->runBackup();
  90. // Confirm that there is only one file and it has a timestamp of some sort.
  91. $files1 = $this->listBackupFiles();
  92. $this->verbose($files1);
  93. $this->assertTrue(count($files1) === 1, 'One backup file was found.');
  94. $this->assertFileTimestamp(array_shift($files1));
  95. // Run another backup.
  96. $this->runBackup();
  97. // Confirm that there are two backup files.
  98. $files1b = $this->listBackupFiles();
  99. $this->verbose($files1b);
  100. $this->assertTrue(count($files1b) === 2, 'Two backup files were found.');
  101. // Cleanup before the next test - purge existing backups.
  102. $this->deleteBackups();
  103. // Change settings to "create separate backups".
  104. $profile->append_timestamp = 0;
  105. $profile->save();
  106. // Run a backup.
  107. $this->runBackup();
  108. // Confirm that separate files are retained.
  109. $files2 = $this->listBackupFiles();
  110. $this->verbose($files2);
  111. $this->assertTrue(count($files2) === 1, 'One backup file was found.');
  112. $this->assertNoFileTimestamp(array_shift($files2));
  113. // Run another backup.
  114. $this->runBackup();
  115. // Confirm that separate files are retained.
  116. $files2b = $this->listBackupFiles();
  117. $this->verbose($files2b);
  118. $this->assertTrue(count($files2b) === 2, 'Two backup files were found.');
  119. // Cleanup before the next test - purge existing backups.
  120. $this->deleteBackups();
  121. // Change settings to "overwrite".
  122. $profile->append_timestamp = 2;
  123. $profile->save();
  124. // Run a backup.
  125. $this->runBackup();
  126. // Confirm that a new file was created.
  127. $files3 = $this->listBackupFiles();
  128. $this->verbose($files3);
  129. $this->assertTrue(count($files3) === 1, 'One backup file was found.');
  130. $this->assertNoFileTimestamp(array_shift($files3));
  131. // Run the backup again.
  132. $this->runBackup();
  133. // Confirm that a new file was not created.
  134. $files3b = $this->listBackupFiles();
  135. $this->verbose($files3b);
  136. $this->assertTrue(count($files3b) === 1, 'One backup file was found.');
  137. // Cleanup - purge all backups.
  138. $this->deleteBackups();
  139. }
  140. }