trigger_example.test

  1. examples
    1. 7 trigger_example/trigger_example.test
    2. 8 trigger_example/trigger_example.test

test file for trigger_example module.

Classes

NameDescription
TriggerExampleTestCaseDefault test case for the trigger_example module.

File

trigger_example/trigger_example.test
View source
  1. <?php
  2. /**
  3. * @file
  4. * test file for trigger_example module.
  5. */
  6. /**
  7. * Default test case for the trigger_example module.
  8. */
  9. class TriggerExampleTestCase extends DrupalWebTestCase {
  10. public static function getInfo() {
  11. return array(
  12. 'name' => 'Trigger example',
  13. 'description' => 'Perform various tests on trigger_example module.' ,
  14. 'group' => 'Examples',
  15. );
  16. }
  17. function setUp() {
  18. parent::setUp('trigger', 'trigger_example');
  19. }
  20. /**
  21. * Test assigning a configurable action to the triggersomething event.
  22. */
  23. function testTriggersomethingEvent() {
  24. // Create an administrative user.
  25. $test_user = $this->drupalCreateUser(array('administer actions'));
  26. $this->drupalLogin($test_user);
  27. // Create a configurable action for display a message to the user
  28. $hash = drupal_hash_base64('system_message_action');
  29. $action_label = $this->randomName();
  30. $edit = array(
  31. 'actions_label' => $action_label,
  32. 'message' => $action_label,
  33. );
  34. $this->drupalPost('admin/config/system/actions/configure/' . $hash, $edit, t('Save'));
  35. $aid = db_query('SELECT aid FROM {actions} WHERE callback = :callback', array(':callback' => 'system_message_action'))->fetchField();
  36. // $aid is likely 3 but if we add more uses for the sequences table in
  37. // core it might break, so it is easier to get the value from the database.
  38. $edit = array('aid' => drupal_hash_base64($aid));
  39. // Note that this only works because there's just one item on the page.
  40. $this->drupalPost('admin/structure/trigger/trigger_example', $edit, t('Assign'));
  41. // Request triggersomething form and submit.
  42. $this->drupalPost('examples/trigger_example', array(), t('Run triggersomething event'));
  43. // Verify the message is shown to the user.
  44. $this->assertText($action_label, t('The triggersomething event executed the action.'));
  45. }
  46. function testUserLogin() {
  47. // Create an administrative user.
  48. $admin_user = $this->drupalCreateUser(array('administer actions'));
  49. $this->drupalLogin($admin_user);
  50. // Create a configurable action for display a message to the user
  51. $hash = drupal_hash_base64('system_message_action');
  52. $action_label = $this->randomName();
  53. $edit = array(
  54. 'actions_label' => $action_label,
  55. 'message' => $action_label,
  56. );
  57. $this->drupalPost('admin/config/system/actions/configure/' . $hash, $edit, t('Save'));
  58. $aid = db_query('SELECT aid FROM {actions} WHERE callback = :callback', array(':callback' => 'system_message_action'))->fetchField();
  59. $edit = array('aid' => drupal_hash_base64($aid));
  60. // Find the correct trigger
  61. $this->drupalPost('admin/structure/trigger/user', $edit, t('Assign'), array(), array(), 'trigger-user-first-time-login-assign-form');
  62. $test_user = $this->drupalCreateUser();
  63. $this->drupalLogin($test_user);
  64. $this->assertText($action_label);
  65. }
  66. }
Login or register to post comments