summaryrefslogtreecommitdiff
path: root/modules/trigger/tests/trigger_test.module
blob: bb973ba111f7ab0d3204054f5ce05cf1ee569843 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
// $Id$

/**
 * @file
 * Mock module to aid in testing trigger.module.
 */

/**
 * Implementation of hook_action_info().
 */
function trigger_test_action_info() {
  // Register an action that can be assigned to the trigger "cron run".
  return array(
    'trigger_test_system_cron_action' => array(
      'type' => 'system',
      'description' => t('Cron test action'),
      'configurable' => FALSE,
      'hooks' => array(
        'cron' => array('run'),
      ),
    ),
    'trigger_test_system_cron_conf_action' => array(
      'type' => 'system',
      'description' => t('Cron test configurable action'),
      'configurable' => TRUE,
      'hooks' => array(
        'cron' => array('run'),
      ),
    ),
  );
}

/**
 * Action fired during the "cron run" trigger test.
 */
function trigger_test_system_cron_action() {
  // Indicate successful execution by setting a persistent variable.
  variable_set('trigger_test_system_cron_action', TRUE);
}

/**
 * Implement a configurable Drupal action.
 */
function trigger_test_system_cron_conf_action($object, $context) {
  // Indicate successful execution by incrementing a persistent variable.
  $value = variable_get('trigger_test_system_cron_conf_action', 0) + 1;
  variable_set('trigger_test_system_cron_conf_action', $value);
}

/**
 * Form for configurable test action.
 */
function trigger_test_system_cron_conf_action_form($context) {
  if (!isset($context['subject'])) {
    $context['subject'] = '';
  }
  $form['subject'] = array(
    '#type' => 'textfield',
    '#default_value' => $context['subject'],
  );
  return $form;
}

/**
 * Form submission handler for configurable test action.
 */
function trigger_test_system_cron_conf_action_submit($form, $form_state) {
  $form_values = $form_state['values'];
  // Process the HTML form to store configuration. The keyed array that
  // we return will be serialized to the database.
  $params = array(
    'subject' => $form_values['subject'],
  );
  return $params;
}