trigger_example.test 3.0 KB

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