You are here

public function TriggerExampleTestCase::testUserLogin in Examples for Developers 7

Test triggers at user login.

File

trigger_example/trigger_example.test, line 66
test file for trigger_example module.

Class

TriggerExampleTestCase
Default test case for the trigger_example module.

Code

public function testUserLogin() {

  // Create an administrative user.
  $admin_user = $this
    ->drupalCreateUser(array(
    'administer actions',
  ));
  $this
    ->drupalLogin($admin_user);

  // Create a configurable action for display a message to the user.
  $hash = drupal_hash_base64('system_message_action');
  $action_label = $this
    ->randomName();
  $edit = array(
    'actions_label' => $action_label,
    'message' => $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' => 'system_message_action',
  ))
    ->fetchField();
  $edit = array(
    'aid' => drupal_hash_base64($aid),
  );

  // Find the correct trigger.
  $this
    ->drupalPost('admin/structure/trigger/user', $edit, t('Assign'), array(), array(), 'trigger-user-first-time-login-assign-form');
  $test_user = $this
    ->drupalCreateUser();
  $this
    ->drupalLogin($test_user);
  $this
    ->assertText($action_label);
}