You are here

public function BmTestUpdate7310::testUpdate7310 in Backup and Migrate 7.3

Test update 7310.

File

tests/BmTestUpdate7310.test, line 37
Test module updates.

Class

BmTestUpdate7310
Test module update 7310.

Code

public function testUpdate7310() {
  require_once dirname(__FILE__) . '/../includes/destinations.inc';
  require_once dirname(__FILE__) . '/../includes/schedules.inc';
  $this
    ->assertEqual(function_exists('backup_migrate_update_7310'), TRUE, 'Update 7310 exists.');

  // First test what happens when there are no e-mail destinations.
  // Execute the update function.
  $result = backup_migrate_update_7310();

  // We should be getting a notice as a result.
  $message = "The following notice was displayed: "{$result}"";
  $expected = 'No destinations were affected by this change.';
  $this
    ->assertEqual($expected, $result, $message);

  // Next, add e-mail destinations and see what happens then.
  // Create two mock e-mail destinations.
  $address = strtolower($this
    ->randomName(10)) . '@example.com';
  $email_destination_id = strtolower($this
    ->randomName(16));
  $this
    ->submitDestinationEmail('Mock e-mail destination', $email_destination_id, $address);
  $address = strtolower($this
    ->randomName(10)) . '@example.com';
  $email_destination_id = strtolower($this
    ->randomName(16));
  $this
    ->submitDestinationEmail('Mock e-mail destination', $email_destination_id, $address);
  $this
    ->assertText(t('Your destination was saved'));

  // Create mock schedules with different types of destinations.
  $mock_schedule_1 = $this
    ->randomName(10);
  $mock_schedule_2 = $this
    ->randomName(10);
  $mock_schedule_3 = $this
    ->randomName(10);
  $this
    ->submitSchedule($mock_schedule_1, 'test_1', 'scheduled', '');
  $this
    ->assertText(t('Your schedule was saved'));
  $this
    ->submitSchedule($mock_schedule_2, 'test_2', $email_destination_id, '');
  $this
    ->assertText(t('Your schedule was saved'));
  $this
    ->submitSchedule($mock_schedule_3, 'test_3', 'scheduled', $email_destination_id);
  $this
    ->assertText(t('Your schedule was saved'));
  $destinations = db_select('backup_migrate_destinations', 'bmd')
    ->fields('bmd', array(
    'machine_name',
  ))
    ->condition('subtype', 'email', '=')
    ->execute()
    ->fetchAllAssoc('machine_name', PDO::FETCH_ASSOC);
  $destinations = array_keys($destinations);

  // Execute the update function.
  $result = backup_migrate_update_7310();

  // We should be getting a notice as a result.
  $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>");
  $message = "The following notice was displayed: &quot;{$result}&quot;.";
  $this
    ->assertEqual($expected, $result, $message);
  $schedules_query = db_select('backup_migrate_schedules', 'bms')
    ->fields('bms', array(
    'machine_name',
    'enabled',
  ));
  $schedules = $schedules_query
    ->execute()
    ->fetchAllAssoc('machine_name', PDO::FETCH_ASSOC);

  // Check that the correct values have changed.
  $this
    ->assertEqual($schedules['test_1']['enabled'], 1, 'The file back-up schedule remained enabled.');
  $this
    ->assertEqual($schedules['test_2']['enabled'], 0, 'The e-mail back-up schedule was disabled.');
  $this
    ->assertEqual($schedules['test_2']['enabled'], 0, 'The file back-up schedule with an e-mail copy was disabled.');
}