protected function AgreementTestCase::drupalLogin in Agreement 7.2
Same name and namespace in other branches
- 6.2 agreement.test \AgreementTestCase::drupalLogin()
- 6 agreement.test \AgreementTestCase::drupalLogin()
Log in a user with the internal browser.
If a user is already logged in, then the current user is logged out before logging in the specified user.
Please note that neither the global $user nor the passed-in user object is populated with data of the logged in user. If you need full access to the user object after logging in, it must be updated manually. If you also need access to the plain-text password of the user (set by drupalCreateUser()), e.g. to log in the same user again, then it must be re-assigned manually. For example:
// Create a user.
$account = $this
->drupalCreateUser(array());
$this
->drupalLogin($account);
// Load real user object.
$pass_raw = $account->pass_raw;
$account = user_load($account->uid);
$account->pass_raw = $pass_raw;
Parameters
$account: User object representing the user to log in.
Overrides DrupalWebTestCase::drupalLogin
See also
drupalCreateUser()
8 calls to AgreementTestCase::drupalLogin()
- AgreementCustomUnprivilegedUserTestCase::testAgreementFrequency in ./
agreement.test - Tests the agreement frequency setting.
- AgreementMultipleRoleTestCase::requiredUserLogin in ./
agreement.test - Creates user with role and login.
- AgreementMultipleRoleTestCase::setUp in ./
agreement.test - Sets up a Drupal site for running functional and integration tests.
- AgreementMultipleTestCase::testAgreement in ./
agreement.test - Tests that multiple agreements can function independently.
- AgreementRevokeTestCase::revokeUserLogin in ./
agreement.test - Creates an user with the "revoke own agreement" permission and login.
File
- ./
agreement.test, line 178 - Tests for Agreement module.
Class
- AgreementTestCase
- Agreement base test class.
Code
protected function drupalLogin(stdClass $user, $destination = 'user') {
if ($this->loggedInUser) {
$this
->drupalLogout();
}
$edit = array(
'name' => $user->name,
'pass' => $user->pass_raw,
);
$this
->drupalPost($destination, $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) {
$this->loggedInUser = $user;
}
}