From dd590b30800fdbb7652673cc9b48e005048df557 Mon Sep 17 00:00:00 2001 From: Angie Byron Date: Wed, 27 May 2009 16:29:05 +0000 Subject: #246096 by andypost, mr.baileys, and Sutharsan: Fix typo so that cron triggers may be executed (with tests). --- modules/trigger/tests/trigger_test.info | 7 ++++++ modules/trigger/tests/trigger_test.module | 32 +++++++++++++++++++++++++ modules/trigger/trigger.module | 4 ++-- modules/trigger/trigger.test | 40 +++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 modules/trigger/tests/trigger_test.info create mode 100644 modules/trigger/tests/trigger_test.module (limited to 'modules/trigger') diff --git a/modules/trigger/tests/trigger_test.info b/modules/trigger/tests/trigger_test.info new file mode 100644 index 000000000..878f9f98b --- /dev/null +++ b/modules/trigger/tests/trigger_test.info @@ -0,0 +1,7 @@ +; $Id$ +name = "Trigger Test" +description = "Support module for Trigger tests." +package = Testing +core = 7.x +files[] = trigger_test.module +hidden = TRUE diff --git a/modules/trigger/tests/trigger_test.module b/modules/trigger/tests/trigger_test.module new file mode 100644 index 000000000..c44360d52 --- /dev/null +++ b/modules/trigger/tests/trigger_test.module @@ -0,0 +1,32 @@ + array( + 'type' => 'system', + 'description' => t('Cron test action'), + 'configurable' => FALSE, + '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); +} diff --git a/modules/trigger/trigger.module b/modules/trigger/trigger.module index f7c931ca3..9cf0a4f84 100644 --- a/modules/trigger/trigger.module +++ b/modules/trigger/trigger.module @@ -371,10 +371,10 @@ function _trigger_comment($a1, $op) { * Implementation of hook_cron(). */ function trigger_cron() { - $aids = _trigger_get_hook_aids('cron'); + $aids = _trigger_get_hook_aids('cron', 'run'); $context = array( 'hook' => 'cron', - 'op' => '', + 'op' => 'run', ); // Cron does not act on any specific object. $object = NULL; diff --git a/modules/trigger/trigger.test b/modules/trigger/trigger.test index a662e33e7..72a496909 100644 --- a/modules/trigger/trigger.test +++ b/modules/trigger/trigger.test @@ -109,3 +109,43 @@ class TriggerContentTestCase extends DrupalWebTestCase { return $info[$action]; } } + +/** + * Test cron trigger. + */ +class TriggerCronTestCase extends DrupalWebTestCase { + function getInfo() { + return array( + 'name' => t('Trigger cron (system) actions'), + 'description' => t('Perform various tests with cron trigger.') , + 'group' => t('Trigger'), + ); + } + + function setUp() { + parent::setUp('trigger', 'trigger_test'); + } + + /** + * Assign an action to a trigger, then pull the trigger, and make sure the actions fire. + */ + function testActionsCron() { + $action = 'trigger_test_system_cron_action'; + $hash = md5($action); + + // Create administrative user. + $test_user = $this->drupalCreateUser(array('administer actions')); + $this->drupalLogin($test_user); + + // Select our test action and assign it to a cron run trigger. + $edit = array('aid' => $hash); + $this->drupalPost('admin/build/trigger/cron', $edit, t('Assign')); + + // Force a cron run. + drupal_cron_run(); + + // Make sure the actions fire. + $action_run = variable_get('trigger_test_system_cron_action', FALSE); + $this->assertTrue($action_run, t('Check that the cron run triggered the test action.')); + } +} -- cgit v1.2.3