You are here

protected function ConflictWebTestCase::drupalLogin in Conflict 7

Overrides DrupalWebTestCase::drupalLogin().

Parameters

stdClass $user: The user account to log in.

bool $create_concurrent_session: (optional) Whether to create a new, concurrent user session. Pass TRUE for first login. Defaults to FALSE, which means that the currently logged in user, if logged in, is logged out and back in (default behavior).

Overrides DrupalWebTestCase::drupalLogin

2 calls to ConflictWebTestCase::drupalLogin()
ConflictSwitchExampleTestCase::testConcurrentLogin in ./conflict.test
Test internal concurrent session functional.
ConflictTestCase::setUp in ./conflict.test
Sets up a Drupal site for running functional and integration tests.

File

./conflict.test, line 71
Tests for conflict.module.

Class

ConflictWebTestCase
@file Tests for conflict.module.

Code

protected function drupalLogin(stdClass $user, $create_concurrent_session = FALSE) {

  // If we're asked to create a new session, unset the current.
  if ($create_concurrent_session) {
    unset($this->curlHandle);
    $this->loggedInUser = FALSE;
  }
  elseif ($this
    ->drupalSwitchUser($user)) {
    $this
      ->verbose($this
      ->drupalGetcontent());
    $this
      ->pass(t('User %name is still logged in.', array(
      '%name' => $user->name,
    )), t('User login'));
    return;
  }

  // If we are logged in already and are asked to re-login, log out first.
  if ($this->loggedInUser && $this->loggedInUser->uid == $user->uid) {
    $this
      ->drupalLogout();
  }
  $edit = array(
    'name' => $user->name,
    'pass' => $user->pass_raw,
  );
  $this
    ->drupalPost('user', $edit, t('Log in'));

  // If a "log out" link appears on the page, it is almost certainly because
  // the login was successful.
  $pass = $this
    ->assertLink(t('Log out'), 0, t('User %name successfully logged in.', array(
    '%name' => $user->name,
  )), t('User login'));
  if ($pass) {

    // Save the user's session on the account itself.
    if (!isset($user->session)) {
      $user->session = new stdClass();
    }
    $user->session->curlHandle = $this->curlHandle;

    // Switch the currently logged in user.
    $this->loggedInUser = $user;
  }
}