BmTestUpdate7310.test 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. /**
  3. * @file
  4. * Test module updates.
  5. */
  6. /**
  7. * Test module update 7310.
  8. */
  9. class BmTestUpdate7310 extends BmTestBase {
  10. /**
  11. * Define this test class.
  12. */
  13. public static function getInfo() {
  14. return array(
  15. 'name' => 'Update 7310',
  16. 'description' => 'Confirm update 7310 works as intended.',
  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. * Test update 7310.
  30. */
  31. public function testUpdate7310() {
  32. require_once dirname(__FILE__) . '/../includes/destinations.inc';
  33. require_once dirname(__FILE__) . '/../includes/schedules.inc';
  34. $this->assertEqual(function_exists('backup_migrate_update_7310'), TRUE, 'Update 7310 exists.');
  35. // First test what happens when there are no e-mail destinations.
  36. // Execute the update function.
  37. $result = backup_migrate_update_7310();
  38. // We should be getting a notice as a result.
  39. $message = "The following notice was displayed: &quot;$result&quot;";
  40. $expected = 'No destinations were affected by this change.';
  41. $this->assertEqual($expected, $result, $message);
  42. // Next, add e-mail destinations and see what happens then.
  43. // Create two mock e-mail destinations.
  44. $address = strtolower($this->randomName(10)) . '@example.com';
  45. $email_destination_id = strtolower($this->randomName(16));
  46. $this->submitDestinationEmail('Mock e-mail destination', $email_destination_id, $address);
  47. $address = strtolower($this->randomName(10)) . '@example.com';
  48. $email_destination_id = strtolower($this->randomName(16));
  49. $this->submitDestinationEmail('Mock e-mail destination', $email_destination_id, $address);
  50. $this->assertText(t('Your destination was saved'));
  51. // Create mock schedules with different types of destinations.
  52. $mock_schedule_1 = $this->randomName(10);
  53. $mock_schedule_2 = $this->randomName(10);
  54. $mock_schedule_3 = $this->randomName(10);
  55. $this->submitSchedule($mock_schedule_1, 'test_1', 'scheduled', '');
  56. $this->assertText(t('Your schedule was saved'));
  57. $this->submitSchedule($mock_schedule_2, 'test_2', $email_destination_id, '');
  58. $this->assertText(t('Your schedule was saved'));
  59. $this->submitSchedule($mock_schedule_3, 'test_3', 'scheduled', $email_destination_id);
  60. $this->assertText(t('Your schedule was saved'));
  61. $destinations = db_select('backup_migrate_destinations', 'bmd')->fields('bmd', array('machine_name'))->condition('subtype', 'email', '=')->execute()->fetchAllAssoc('machine_name', PDO::FETCH_ASSOC);
  62. $destinations = array_keys($destinations);
  63. // Execute the update function.
  64. $result = backup_migrate_update_7310();
  65. // We should be getting a notice as a result.
  66. $expected = htmlspecialchars("Schedules that back up to e-mail destinations have been disabled. Check that you are using the correct e-mail addresses, then re-enable manually. The following schedules have been disabled: <ul><li>{$mock_schedule_2}</li><li>{$mock_schedule_3}</li></ul>");
  67. $message = "The following notice was displayed: &quot;$result&quot;.";
  68. $this->assertEqual($expected, $result, $message);
  69. $schedules_query = db_select('backup_migrate_schedules', 'bms')->fields('bms', array('machine_name', 'enabled'));
  70. $schedules = $schedules_query->execute()->fetchAllAssoc('machine_name', PDO::FETCH_ASSOC);
  71. // Check that the correct values have changed.
  72. $this->assertEqual($schedules['test_1']['enabled'], 1, 'The file back-up schedule remained enabled.');
  73. $this->assertEqual($schedules['test_2']['enabled'], 0, 'The e-mail back-up schedule was disabled.');
  74. $this->assertEqual($schedules['test_2']['enabled'], 0, 'The file back-up schedule with an e-mail copy was disabled.');
  75. }
  76. /**
  77. * Submits the destination form for E-mails.
  78. *
  79. * @param string $name
  80. * The name of the destination.
  81. * @param string $machine_name
  82. * The machine name of the destination.
  83. * @param string $mail
  84. * The e-mail address of the destination.
  85. */
  86. public function submitDestinationEmail($name, $machine_name, $mail) {
  87. $this->drupalGet('admin/config/system/backup_migrate/settings/destination/add/email');
  88. $this->assertResponse(200);
  89. $edit = array();
  90. $edit['name'] = $name;
  91. $edit['machine_name'] = $machine_name;
  92. $edit['location'] = $mail;
  93. $this->drupalPost(NULL, $edit, t('Save destination'));
  94. $this->assertResponse(200);
  95. }
  96. /**
  97. * Submits the schedule form.
  98. *
  99. * @param string $name
  100. * The name of the destination.
  101. * @param string $machine_name
  102. * The machine name of the destination.
  103. * @param string $destination_id
  104. * The destination ID to use.
  105. * @param string $copy_destination_id
  106. * The destination ID to use for an optional copy.
  107. */
  108. public function submitSchedule($name, $machine_name, $destination_id, $copy_destination_id = NULL) {
  109. $this->drupalGet('admin/config/system/backup_migrate/schedule/add');
  110. $this->assertResponse(200);
  111. $edit = array();
  112. $edit['name'] = $name;
  113. $edit['machine_name'] = $machine_name;
  114. $edit['destination_id'] = $destination_id;
  115. if (!empty($copy_destination_id)) {
  116. $edit['copy'] = TRUE;
  117. $edit['copy_destination_id'] = $copy_destination_id;
  118. }
  119. $this->drupalPost(NULL, $edit, t('Save schedule'));
  120. $this->assertResponse(200);
  121. }
  122. }