BmTestProfiles.test 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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' => 'Destination 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. // Load the main B&M page.
  45. $this->drupalGet(BACKUP_MIGRATE_MENU_PATH . '/settings/profile/add');
  46. $this->assertResponse(200);
  47. backup_migrate_include('files', 'profiles');
  48. $filename = _backup_migrate_default_filename();
  49. $defaults = _backup_migrate_profile_default_profile();
  50. // Verify all of the expected fields exist.
  51. $this->assertFieldByName('name');
  52. $this->assertFieldByName('name', 'Untitled Profile');
  53. $this->assertFieldByName('machine_name');
  54. $this->assertFieldByName('filename');
  55. $this->assertFieldByName('filename', $filename);
  56. // @todo Confirm all of the expected options are present.
  57. $this->assertFieldByName('append_timestamp');
  58. $this->assertFieldByName('timestamp_format');
  59. $this->assertFieldByName('timestamp_format', $defaults['timestamp_format']);
  60. $this->assertFieldByName('filters[compression]');
  61. $items = $this->supportedCompressors();
  62. $this->assertSelectOptions('edit-filters-compression', $items);
  63. $this->assertOptionSelected('edit-filters-compression', 'gzip');
  64. $this->assertFieldByName('filters[sources][db][exclude_tables][]');
  65. $this->assertFieldByName('filters[sources][db][nodata_tables][]');
  66. $this->assertFieldByName('filters[sources][db][utils_lock_tables]');
  67. $this->assertFieldByName('filters[sources][files][exclude_filepaths]');
  68. $this->assertFieldByName('filters[sources][archive][exclude_filepaths]');
  69. $this->assertFieldByName('filters[utils_site_offline]');
  70. $this->assertFieldByName('filters[utils_site_offline_message]');
  71. $this->assertFieldByName('filters[utils_description]');
  72. $this->assertFieldByName('filters[use_cli]');
  73. $this->assertFieldByName('filters[ignore_errors]');
  74. $this->assertFieldByName('filters[notify_success_enable]');
  75. $this->assertFieldByName('filters[notify_success_email]');
  76. $this->assertFieldByName('filters[notify_failure_enable]');
  77. $this->assertFieldByName('filters[notify_failure_email]');
  78. }
  79. /**
  80. * Confirm the backup filename processes work as expected.
  81. */
  82. public function testFilenameOptions() {
  83. // Load the profile. This will be interacted with directly because otherwise
  84. // the number of form fields will likely make it impossible to execute
  85. // properly due to the max_input_vars setting defaulting to 1000.
  86. $profile = $this->getProfile();
  87. // Run a backup.
  88. $this->runBackup();
  89. // Confirm that there is only one file and it has a timestamp of some sort.
  90. $files1 = $this->listBackupFiles();
  91. $this->verbose($files1);
  92. $this->assertTrue(count($files1) === 1, 'One backup file was found.');
  93. $this->assertFileTimestamp(array_shift($files1));
  94. // Run another backup.
  95. $this->runBackup();
  96. // Confirm that there are two backup files.
  97. $files1b = $this->listBackupFiles();
  98. $this->verbose($files1b);
  99. $this->assertTrue(count($files1b) === 2, 'Two backup files were found.');
  100. // Cleanup before the next test - purge existing backups.
  101. $this->deleteBackups();
  102. // Change settings to "create separate backups".
  103. $profile->append_timestamp = 0;
  104. $profile->save();
  105. // Run a backup.
  106. $this->runBackup();
  107. // Confirm that separate files are retained.
  108. $files2 = $this->listBackupFiles();
  109. $this->verbose($files2);
  110. $this->assertTrue(count($files2) === 1, 'One backup file was found.');
  111. $this->assertNoFileTimestamp(array_shift($files2));
  112. // Run another backup.
  113. $this->runBackup();
  114. // Confirm that separate files are retained.
  115. $files2b = $this->listBackupFiles();
  116. $this->verbose($files2b);
  117. $this->assertTrue(count($files2b) === 2, 'Two backup files were found.');
  118. // Cleanup before the next test - purge existing backups.
  119. $this->deleteBackups();
  120. // Change settings to "overwrite".
  121. $profile->append_timestamp = 2;
  122. $profile->save();
  123. // Run a backup.
  124. $this->runBackup();
  125. // Confirm that a new file was created.
  126. $files3 = $this->listBackupFiles();
  127. $this->verbose($files3);
  128. $this->assertTrue(count($files3) === 1, 'One backup file was found.');
  129. $this->assertNoFileTimestamp(array_shift($files3));
  130. // Run the backup again.
  131. $this->runBackup();
  132. // Confirm that a new file was not created.
  133. $files3b = $this->listBackupFiles();
  134. $this->verbose($files3b);
  135. $this->assertTrue(count($files3b) === 1, 'One backup file was found.');
  136. // Cleanup - purge all backups.
  137. $this->deleteBackups();
  138. }
  139. }