Index: modules/simpletest/drupal_web_test_case.php
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/drupal_web_test_case.php,v
retrieving revision 1.201
diff -u -p -r1.201 drupal_web_test_case.php
--- modules/simpletest/drupal_web_test_case.php	7 Mar 2010 08:10:26 -0000	1.201
+++ modules/simpletest/drupal_web_test_case.php	7 Mar 2010 08:49:50 -0000
@@ -1586,8 +1586,12 @@ class DrupalWebTestCase extends DrupalTe
    * @param $headers
    *   An array containing additional HTTP request headers, each formatted as
    *   "name: value".
+   * @param $form_id
+   *   The optional string identifying the form to be submitted. On some pages
+   *   there are many identical forms, so just using the value of the submit
+   *   button is not enough.
    */
-  protected function drupalPost($path, $edit, $submit, array $options = array(), array $headers = array()) {
+  protected function drupalPost($path, $edit, $submit, array $options = array(), array $headers = array(), $form_id = NULL) {
     $submit_matches = FALSE;
     $ajax = is_array($submit);
     if (isset($path)) {
@@ -1596,7 +1600,11 @@ class DrupalWebTestCase extends DrupalTe
     if ($this->parse()) {
       $edit_save = $edit;
       // Let's iterate over all the forms.
-      $forms = $this->xpath('//form');
+      $xpath = "//form";
+      if (!empty($form_id)) {
+        $xpath .= "[@id='" . drupal_html_id($form_id) . "']";
+      }
+      $forms = $this->xpath($xpath);
       foreach ($forms as $form) {
         // We try to set the fields of this form as specified in $edit.
         $edit = $edit_save;
Index: modules/trigger/trigger.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/trigger/trigger.test,v
retrieving revision 1.27
diff -u -p -r1.27 trigger.test
--- modules/trigger/trigger.test	7 Mar 2010 07:22:42 -0000	1.27
+++ modules/trigger/trigger.test	7 Mar 2010 08:49:50 -0000
@@ -1,7 +1,35 @@
 <?php
 // $Id: trigger.test,v 1.27 2010/03/07 07:22:42 webchick Exp $
 
-class TriggerContentTestCase extends DrupalWebTestCase {
+/**
+ * Class with common helper methods.
+ */
+class TriggerWebTestCase extends DrupalWebTestCase {
+
+  /**
+   * Configure 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 = md5($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();
+  }
+
+}
+
+class TriggerContentTestCase extends TriggerWebTestCase {
   var $_cleanup_roles = array();
   var $_cleanup_users = array();
 
@@ -116,7 +144,7 @@ class TriggerContentTestCase extends Dru
 /**
  * Test cron trigger.
  */
-class TriggerCronTestCase extends DrupalWebTestCase {
+class TriggerCronTestCase extends TriggerWebTestCase {
   public static function getInfo() {
     return array(
       'name' => 'Trigger cron (system) actions',
@@ -146,14 +174,12 @@ class TriggerCronTestCase extends Drupal
     $this->drupalPost('admin/structure/trigger/system', $edit, t('Assign'));
 
     // Assign a configurable action to the cron trigger.
-    $hash = md5('trigger_test_system_cron_conf_action');
     $action_label = $this->randomName();
     $edit = array(
       'actions_label' => $action_label,
       'subject' => $action_label,
     );
-    $this->drupalPost('admin/config/system/actions/configure/' . $hash, $edit, t('Save'));
-    $aid = db_query('SELECT aid FROM {actions} WHERE callback = :callback', array(':callback' => 'trigger_test_system_cron_conf_action'))->fetchField();
+    $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' => md5($aid));
@@ -165,8 +191,8 @@ class TriggerCronTestCase extends Drupal
       'actions_label' => $action_label,
       'subject' => $action_label,
     );
-    $this->drupalPost('admin/config/system/actions/configure/' . $hash, $edit, t('Save'));
-    $edit = array('aid' => md5($aid + 1));
+    $aid = $this->configureAdvancedAction('trigger_test_system_cron_conf_action', $edit);
+    $edit = array('aid' => md5($aid));
     $this->drupalPost('admin/structure/trigger/system', $edit, t('Assign'));
 
     // Force a cron run.
@@ -185,7 +211,7 @@ class TriggerCronTestCase extends Drupal
 /**
  * Test other triggers.
  */
-class TriggerOtherTestCase extends DrupalWebTestCase {
+class TriggerOtherTestCase extends TriggerWebTestCase {
   var $_cleanup_roles = array();
   var $_cleanup_users = array();
 
@@ -198,11 +224,11 @@ class TriggerOtherTestCase extends Drupa
   }
 
   function setUp() {
-    parent::setUp('trigger', 'trigger_test');
+    parent::setUp('trigger', 'trigger_test', 'contact');
   }
 
   /**
-   * Test triggering on user create.
+   * Test triggering on user create and user login.
    */
   function testActionsUser() {
     // Assign an action to the create user trigger.
@@ -233,7 +259,29 @@ class TriggerOtherTestCase extends Drupa
     $this->assertTrue(variable_get($action_id, FALSE), t('Check that creating a user triggered the test action.'));
 
     // Reset the action variable.
-    variable_set( $action_id, FALSE );
+    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' => md5($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), t('One Action assigned to the hook'));
+    $this->assertEqual($actions[$aid]['label'], $action_edit['actions_label'], t('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']);
   }
 
   /**
@@ -249,7 +297,7 @@ class TriggerOtherTestCase extends Drupa
     $this->drupalPost('admin/structure/trigger/comment', $edit, t('Assign'));
 
     // Set action variable to FALSE.
-    variable_set( $action_id, 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', 'post comments without approval', 'post comments'));
@@ -278,7 +326,7 @@ class TriggerOtherTestCase extends Drupa
     $this->drupalPost('admin/structure/trigger/taxonomy', $edit, t('Assign'));
 
     // Set action variable to FALSE.
-    variable_set( $action_id, FALSE );
+    variable_set($action_id, FALSE);
 
     // Create a taxonomy vocabulary and add a term to it.
 
@@ -300,6 +348,7 @@ class TriggerOtherTestCase extends Drupa
     // Verify that the action variable has been set.
     $this->assertTrue(variable_get($action_id, FALSE), t('Check that creating a taxonomy term triggered the action.'));
   }
+
 }
 
 /**
