[177a560] | 1 | <?php |
---|
| 2 | |
---|
| 3 | /** |
---|
| 4 | * @file |
---|
| 5 | * Tests for the token_actions module. |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | class TokenActionsTestCase extends DrupalWebTestCase { |
---|
| 9 | public static function getInfo() { |
---|
| 10 | return array( |
---|
| 11 | 'name' => t('Token action tests'), |
---|
| 12 | 'description' => t('Test some of the token actions and tokens.'), |
---|
| 13 | 'group' => t('Token'), |
---|
| 14 | ); |
---|
| 15 | } |
---|
| 16 | |
---|
| 17 | function setUp() { |
---|
| 18 | parent::setUp('token', 'token_actions', 'trigger'); |
---|
| 19 | $user = $this->drupalCreateUser(array('administer actions', 'administer site configuration', 'administer users')); |
---|
| 20 | $this->drupalLogin($user); |
---|
| 21 | } |
---|
| 22 | |
---|
| 23 | /** |
---|
| 24 | * Test user actions and triggers. |
---|
| 25 | */ |
---|
| 26 | function testUserActions() { |
---|
| 27 | $insert_action = $this->createAction('token_actions_message_action', array( |
---|
| 28 | 'message' => 'Yay [site-name] has a new user [user] with an ID of [uid] and e-mail address of [mail]!', |
---|
| 29 | )); |
---|
| 30 | $this->assignTriggerAction('user', 'insert', $insert_action); |
---|
| 31 | |
---|
| 32 | // Create a user to trigger the action. |
---|
| 33 | $edit = array(); |
---|
| 34 | $edit['name'] = $this->randomName(); |
---|
| 35 | $edit['mail'] = $edit['name'] .'@example.com'; |
---|
| 36 | $edit['pass[pass1]'] = $this->randomName(); |
---|
| 37 | $edit['pass[pass2]'] = $edit['pass[pass1]']; |
---|
| 38 | |
---|
| 39 | $this->drupalPost('admin/user/user/create', $edit, t('Create new account')); |
---|
| 40 | $account = user_load(array('name' => $edit['name'])); |
---|
| 41 | $this->assertText("Yay Drupal has a new user {$account->name} with an ID of {$account->uid} and e-mail address of {$account->mail}!", 'Tokenized message displays'); |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | /** |
---|
| 45 | * Create an action. |
---|
| 46 | * |
---|
| 47 | * @param $action |
---|
| 48 | * The machine name of the action. |
---|
| 49 | * @param $edit |
---|
| 50 | * An optional array to pass onto drupalPost() for configuring the action. |
---|
| 51 | * |
---|
| 52 | * @return |
---|
| 53 | * The created action object. |
---|
| 54 | */ |
---|
| 55 | function createAction($action, $edit = array()) { |
---|
| 56 | $edit += array( |
---|
| 57 | 'actions_description' => $this->randomName(), |
---|
| 58 | ); |
---|
| 59 | $this->drupalPost('admin/settings/actions/configure/'. md5($action), $edit, t('Save')); |
---|
| 60 | $this->assertText('The action has been successfully saved.'); |
---|
| 61 | return db_fetch_object(db_query("SELECT * FROM {actions} WHERE type = 'system' AND callback = '%s' AND description = '%s'", $action, $edit['actions_description'])); |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | /** |
---|
| 65 | * Assign an action to a trigger. |
---|
| 66 | * |
---|
| 67 | * @param $type |
---|
| 68 | * The trigger type. |
---|
| 69 | * @param $trigger |
---|
| 70 | * The trigger. |
---|
| 71 | * @param $action |
---|
| 72 | * The action object. |
---|
| 73 | */ |
---|
| 74 | function assignTriggerAction($type, $trigger, $action) { |
---|
| 75 | $edit['aid'] = md5($action->aid); |
---|
| 76 | $this->drupalPost("admin/build/trigger/{$type}", $edit, 'Assign', array(), array(), "trigger-{$type}-{$trigger}-assign-form"); |
---|
| 77 | return $this->assertLinkByHref("admin/build/trigger/unassign/{$type}/{$trigger}/{$edit['aid']}", 0, t('Action assigned to @type @trigger trigger.', array('@type' => $type, '@trigger' => $trigger))); |
---|
| 78 | } |
---|
| 79 | } |
---|