function DrupalTestCase::drupalLoginUser in SimpleTest 5
Same name and namespace in other branches
- 6 drupal_test_case.php \DrupalTestCase::drupalLoginUser()
Logs in a user with the internal browser
Parameters
object user object with pass_raw property!:
$submit value of submit button on log in form:
10 calls to DrupalTestCase::drupalLoginUser()
- ImageModuleTest::testImageNode in tests/
image_module.test - PageCreationTest::testPageCreation in tests/
page_creation.test - PageViewTest::testPageView in tests/
page_view.test - TaxonomyTestNodeApi::testTaxonomyNode in tests/
taxonomy.module.test - UploadPictureTests::testNoPicture in tests/
upload_tests.test
File
- ./
drupal_test_case.php, line 315
Class
- DrupalTestCase
- Test case for typical Drupal tests. Extends WebTestCase for comfortable browser usage but also implements all UnitTestCase methods, I wish WebTestCase would do this.
Code
function drupalLoginUser($user = NULL, $submit = 'Log in') {
$this
->drupalGet(url("user", NULL, NULL, TRUE));
// Going to the page retrieves the cookie, as the browser should save it
if ($user === NULL) {
$user = $this
->drupalCreateUserRolePerm();
}
$edit = array(
'name' => $user->name,
'pass' => $user->pass_raw,
);
$this
->drupalPostRequest('user', $edit, $submit);
$this
->assertText($user->name, ' [login] found name: ' . $user->name);
$this
->assertNoText(t('The username %name has been blocked.', array(
'%name' => $user->name,
)), ' [login] not blocked');
$this
->assertNoText(t('The name %name is a reserved username.', array(
'%name' => $user->name,
)), ' [login] not reserved');
return $user;
}