action_example.test 3.6 KB

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