trigger_test.module

Mock module to aid in testing trigger.module.

File

drupal-7.x/modules/trigger/tests/trigger_test.module
View source
  1. <?php
  2. /**
  3. * @file
  4. * Mock module to aid in testing trigger.module.
  5. */
  6. /**
  7. * Implements hook_action_info().
  8. */
  9. function trigger_test_action_info() {
  10. // Register an action that can be assigned to the trigger "cron".
  11. return array(
  12. 'trigger_test_system_cron_action' => array(
  13. 'type' => 'system',
  14. 'label' => t('Cron test action'),
  15. 'configurable' => FALSE,
  16. 'triggers' => array('cron'),
  17. ),
  18. 'trigger_test_system_cron_conf_action' => array(
  19. 'type' => 'system',
  20. 'label' => t('Cron test configurable action'),
  21. 'configurable' => TRUE,
  22. 'triggers' => array('cron'),
  23. ),
  24. 'trigger_test_generic_action' => array(
  25. 'type' => 'system',
  26. 'label' => t('Generic test action'),
  27. 'configurable' => FALSE,
  28. 'triggers' => array(
  29. 'taxonomy_term_insert',
  30. 'taxonomy_term_update',
  31. 'taxonomy_delete',
  32. 'comment_insert',
  33. 'comment_update',
  34. 'comment_delete',
  35. 'user_insert',
  36. 'user_update',
  37. 'user_delete',
  38. 'user_login',
  39. 'user_logout',
  40. 'user_view',
  41. ),
  42. ),
  43. 'trigger_test_generic_any_action' => array(
  44. 'type' => 'system',
  45. 'label' => t('Generic test action for any trigger'),
  46. 'configurable' => FALSE,
  47. 'triggers' => array('any'),
  48. ),
  49. );
  50. }
  51. /**
  52. * Implements hook_trigger_info().
  53. */
  54. function trigger_test_trigger_info() {
  55. // Register triggers that this module provides. The first is an additional
  56. // node trigger and the second is our own, which should create a new tab
  57. // on the trigger assignment page. The last tests long trigger names.
  58. return array(
  59. 'node' => array(
  60. 'node_triggertest' => array(
  61. 'label' => t('A test trigger is fired'),
  62. ),
  63. ),
  64. 'trigger_test' => array(
  65. 'trigger_test_triggertest' => array(
  66. 'label' => t('Another test trigger is fired'),
  67. ),
  68. 'trigger_test_we_sweat_it_out_in_the_streets_of_a_runaway_american_dream' => array(
  69. 'label' => t('A test trigger with a name over 64 characters'),
  70. ),
  71. ),
  72. );
  73. }
  74. /**
  75. * Action fired during the "cron run" trigger test.
  76. */
  77. function trigger_test_system_cron_action() {
  78. // Indicate successful execution by setting a persistent variable.
  79. variable_set('trigger_test_system_cron_action', TRUE);
  80. }
  81. /**
  82. * Implement a configurable Drupal action.
  83. */
  84. function trigger_test_system_cron_conf_action($object, $context) {
  85. // Indicate successful execution by incrementing a persistent variable.
  86. $value = variable_get('trigger_test_system_cron_conf_action', 0) + 1;
  87. variable_set('trigger_test_system_cron_conf_action', $value);
  88. }
  89. /**
  90. * Form for configurable test action.
  91. */
  92. function trigger_test_system_cron_conf_action_form($context) {
  93. if (!isset($context['subject'])) {
  94. $context['subject'] = '';
  95. }
  96. $form['subject'] = array(
  97. '#type' => 'textfield',
  98. '#default_value' => $context['subject'],
  99. );
  100. return $form;
  101. }
  102. /**
  103. * Form submission handler for configurable test action.
  104. */
  105. function trigger_test_system_cron_conf_action_submit($form, $form_state) {
  106. $form_values = $form_state['values'];
  107. // Process the HTML form to store configuration. The keyed array that
  108. // we return will be serialized to the database.
  109. $params = array(
  110. 'subject' => $form_values['subject'],
  111. );
  112. return $params;
  113. }
  114. /**
  115. * Action fired during the "taxonomy", "comment", and "user" trigger tests.
  116. */
  117. function trigger_test_generic_action($context) {
  118. // Indicate successful execution by setting a persistent variable.
  119. variable_set('trigger_test_generic_action', TRUE);
  120. }
  121. /**
  122. * Action fired during the additional trigger tests.
  123. */
  124. function trigger_test_generic_any_action($context) {
  125. // Indicate successful execution by setting a persistent variable.
  126. variable_set('trigger_test_generic_any_action', variable_get('trigger_test_generic_any_action', 0) + 1);
  127. }