You are here

bm_test.module in Backup and Migrate 7.3

Mock module to help and test hooks.

File

tests/bm_test.module
View source
<?php

/**
 * @file
 * Mock module to help and test hooks.
 */

/**
 * A base class for mock exportables.
 */
class BmTestItem {

  /**
   * Edit this to true to make a default item disabled initially.
   *
   * @var bool
   */
  public $disabled = FALSE;

  /**
   * Indicates the API version to use.
   *
   * @var int
   */
  public $api_version = 1;

}

/**
 * Implements hook_ctools_plugin_api().
 */
function bm_test_ctools_plugin_api($module = NULL, $api = NULL) {
  if ($module == "backup_migrate" && $api == "backup_migrate_exportables") {
    return array(
      "version" => "1",
    );
  }
}

/**
 * Implements hook_exportables_backup_migrate_schedules().
 */
function bm_test_exportables_backup_migrate_schedules() {
  $export = array();
  $item = new BmTestItem();
  $mock_record = _bm_test_get_mock_schedule();
  foreach ($mock_record as $key => $field) {
    $item->{$key} = $field;
  }
  $export['mock_db_weekly'] = $item;
  return $export;
}

/**
 * Helper function to create a mock schedule.
 */
function _bm_test_get_mock_schedule() {
  return array(
    'machine_name' => 'mock_db_weekly',
    'name' => 'Mock weekly database schedule',
    'source_id' => 'db',
    'destination_id' => 'scheduled',
    'copy_destination_id' => '',
    'profile_id' => 'default',
    'keep' => 4,
    'period' => 604800,
    'enabled' => TRUE,
    'cron' => 'builtin',
    'cron_schedule' => '0 4 * * *',
  );
}

/**
 * Implements hook_exportables_backup_migrate_sources().
 */
function bm_test_exportables_backup_migrate_sources() {
  $export = array();
  $item = new BmTestItem();
  $mock_record = _bm_test_get_mock_source();
  foreach ($mock_record as $key => $field) {
    $item->{$key} = $field;
  }
  $export['mock_file_directory'] = $item;
  return $export;
}

/**
 * Helper function to create a mock source.
 */
function _bm_test_get_mock_source() {
  return array(
    'machine_name' => 'mock_file_directory',
    'name' => 'Mock file directory',
    'location' => '/dev/null',
    'subtype' => 'filesource',
  );
}

/**
 * Implements hook_exportables_backup_migrate_destinations().
 */
function bm_test_exportables_backup_migrate_destinations() {
  $export = array();
  $item = new BmTestItem();
  $mock_record = _bm_test_get_mock_destination();
  foreach ($mock_record as $key => $field) {
    $item->{$key} = $field;
  }
  $export['mock_email'] = $item;
  return $export;
}

/**
 * Helper function to create a mock destination.
 */
function _bm_test_get_mock_destination() {
  return array(
    'machine_name' => 'mock_email',
    'name' => 'Mock e-mail destination',
    'location' => 'test@example.com',
    'subtype' => 'email',
  );
}

Functions

Namesort descending Description
bm_test_ctools_plugin_api Implements hook_ctools_plugin_api().
bm_test_exportables_backup_migrate_destinations Implements hook_exportables_backup_migrate_destinations().
bm_test_exportables_backup_migrate_schedules Implements hook_exportables_backup_migrate_schedules().
bm_test_exportables_backup_migrate_sources Implements hook_exportables_backup_migrate_sources().
_bm_test_get_mock_destination Helper function to create a mock destination.
_bm_test_get_mock_schedule Helper function to create a mock schedule.
_bm_test_get_mock_source Helper function to create a mock source.

Classes

Namesort descending Description
BmTestItem A base class for mock exportables.