drupalModuleEnable('trigger'); } /** * Assigns an action to a trigger type. * * @param $action represents the name of the action. * @param $hook represents the name of the hook. Defaults to 'nodeapi'. * @param $op represents the operation of the hook. Defaults to NULL. * @param $type represents the trigger type. Defaults to 'node'. */ function actionSet($action, $hook = 'nodeapi', $op = NULL, $type = 'node') { $test_user = $this->drupalCreateUserRolePerm(array('administer actions', 'create page content')); $this->drupalLoginUser($test_user); $hash = $this->getHash($action); // Set action id to the hash. $edit = array('aid' => $hash); $this->drupalPostRequest('admin/build/trigger/'. $type, $edit, 'Assign'); $this->_cleanup_actions[$hash] = array('action' => $action, 'hook' => $hook, 'op' => $op); } /** * Unassigns an action from a trigger type. * * @param $action represents the name of the action. * @param $hook represents the hook. * @param $op represents the operation of the hook. Defaults to NULL. */ function actionUnset($action, $hook, $op = NULL) { $hash = $this->getHash($action); $this->drupalPostRequest('admin/build/trigger/unassign/'. $hook . (is_null($op) ? '/'. $op : '') .'/'. $hash, array(), 'Unassign'); $this->assertWantedRaw(t('Action %action has been unassigned.', array('%action' => $action)), t('Check to make sure action can be unassigned from trigger.')); unset($this->_cleanup_actions[$hash]); } /** * Helper function that returns the hash of an action. * * @param $action represents the name of the action. * @return The hash of the action name. */ function getHash($action) { return md5($action); } /** * Helper function that checks to make sure the action fires. * * It will run the function pullTrigger[HookName]($op) to pull the trigger. * It will run the function actionConfirm[ActionNameWithoutSpaces]($object) to test to see if the action was fired. */ function assertActionFires($action, $hook, $op = NULL) { $object = $this->pullTrigger($hook, $op); $this->includeAction($action); $check = 'actionConfirm'. str_replace(' ', '', $action); if (is_null($object)) { $this->$check(); } else { $this->$check($object); } } /** * Helper function that checks to make sure the action DOES NOT fire. * * It will run the function pullTrigger[HookName]($op) to pull the trigger. * It will run the function actionConfirm[ActionNameWithoutSpaces]($object) to test to see if the action was fired. * This should not make any assertions, but return either TRUE or FALSE. */ function assertActionHolds($action, $hook, $op = NULL) { $object = $this->pullTrigger($hook, $op); $this->includeAction($action); $check = 'actionConfirm'. str_replace(' ', '', $action); if (is_null($object)) { $this->assertFalse($this->$check(), t('Check to make sure the action did not fire.')); } else { $this->assertFalse($this->$check($object), t('Check to make sure the action did not fire.')); } } /** * Helper function that pulls a given trigger. * * @param $hook represents the hook. * @param $op represents the operation. Defaults to NULL. */ function pullTrigger($hook, $op = NULL) { require_once(drupal_get_path('module', 'simpletest') .'/tests/'. $hook .'.test'); $trigger = 'pullTrigger'. $hook; if (is_null($op)) { $object = $this->$trigger(); } else { $object = $this->$trigger($op); } return $object; } /** * Helper function that includes the action. */ function includeAction($action) { $action = str_replace(' ', '_', $action); return require_once(drupal_get_path('module', 'simpletest') .'/tests/'. $action .'.test'); } /** * Helper function that does a series of actions/triggers tests based on passed in information. */ function actionsTest($action, $type, $hook, $op = NULL) { $this->assertNoAssignments(); $this->actionSet($action, $hook, $op, $type); $this->assertActionFires($action, $hook, $op); $this->actionSet($action, $hook, $op, $type); $this->assertWantedRaw(t('The action you choose is already assigned to that trigger.'), t('Check to make sure an error occurs when assigning an action to a trigger twice.')); $this->actionUnset($action, $hook, $op); $this->assertActionHolds($action, $hook, $op); $this->assertNoAssignments(); } function assertNoAssignments() { $assigned = db_result(db_query("SELECT COUNT(*) FROM {trigger_assignments}")); $this->assertTrue($assigned == 0, t('Check to make sure no actions were assigned to triggers.')); } function tearDown() { foreach ($this->_cleanup_actions as $hash => $info) { $this->actionUnset($info['action'], $info['hook'], $info['op']); } } } ?>