action_example.test

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

test file for action_example module.

Classes

NameDescription
ActionExampleTestCaseDefault test case for the action_example module.

File

action_example/action_example.test
View source
  1. <?php
  2. /**
  3. * @file
  4. * test file for action_example module.
  5. */
  6. /**
  7. * Default test case for the action_example module.
  8. */
  9. class ActionExampleTestCase extends TriggerWebTestCase {
  10. public static function getInfo() {
  11. return array(
  12. 'name' => 'Action example',
  13. 'description' => 'Perform various tests on action_example module.' ,
  14. 'group' => 'Examples',
  15. );
  16. }
  17. function setUp() {
  18. parent::setUp('trigger', 'action_example');
  19. }
  20. /**
  21. * Test Action Example.
  22. *
  23. * 1. action_example_basic_action: Configure a action_example_basic_action to
  24. * happen when user logs in.
  25. * 2. action_example_unblock_user_action: When a user's profile is being
  26. * viewed, unblock that user.
  27. * 3. action_example_node_sticky_action: Create a user, configure that user
  28. * to always be stickied using advanced configuration. Have the user
  29. * create content; verify that it gets stickied.
  30. */
  31. function testActionExample() {
  32. // Create an administrative user.
  33. $admin_user = $this->drupalCreateUser(array('administer actions', 'access comments', 'access content', 'post comments', 'skip comment approval', 'create article content', 'access user profiles', 'administer users'));
  34. $this->drupalLogin($admin_user);
  35. // 1. Assign basic action; then logout and login user and see if it puts
  36. // the message on the screen.
  37. $hash = drupal_hash_base64('action_example_basic_action');
  38. $edit = array('aid' => $hash);
  39. $this->drupalPost('admin/structure/trigger/user', $edit, t('Assign'), array(), array(), 'trigger-user-login-assign-form');
  40. $this->drupalLogout();
  41. $this->drupalLogin($admin_user);
  42. $this->assertText(t('action_example_basic_action fired'));
  43. // 2. Unblock: When a user's profile is being viewed, unblock.
  44. $normal_user = $this->drupalCreateUser();
  45. user_save($normal_user, array('status' => 0)); // Blocked user.
  46. $normal_user = user_load($normal_user->uid, TRUE);
  47. $this->assertFalse($normal_user->status, t('Normal user status has been set to blocked'));
  48. $hash = drupal_hash_base64('action_example_unblock_user_action');
  49. $edit = array('aid' => $hash);
  50. $this->drupalPost('admin/structure/trigger/user', $edit, t('Assign'), array(), array(), 'trigger-user-view-assign-form');
  51. $this->drupalGet("user/$normal_user->uid");
  52. $normal_user = user_load($normal_user->uid, TRUE);
  53. $this->assertTrue($normal_user->status, t('Normal user status has been set to unblocked'));
  54. $this->assertRaw(t('Unblocked user %name', array('%name' => $normal_user->name)));
  55. // 3. Create a user whose posts are always to be stickied.
  56. $sticky_user = $this->drupalCreateUser(array('access comments', 'access content', 'post comments', 'skip comment approval', 'create article content'));
  57. $action_label = $this->randomName();
  58. $edit = array(
  59. 'actions_label' => $action_label,
  60. 'author' => $sticky_user -> name,
  61. );
  62. $aid = $this->configureAdvancedAction('action_example_node_sticky_action', $edit);
  63. $edit = array('aid' => drupal_hash_base64($aid));
  64. $this->drupalPost('admin/structure/trigger/node', $edit, t('Assign'), array(), array(), 'trigger-node-insert-assign-form');
  65. // Now create a node and verify that it gets stickied.
  66. $this->drupalLogout();
  67. $this->drupalLogin($sticky_user);
  68. $node = $this->drupalCreateNode();
  69. $this->assertTrue($node->sticky, t('Node was set to sticky on creation'));
  70. }
  71. }
Login or register to post comments