Asserting a failed login attempt on Simpletest I want to test a module that adds an additional login validation clause. Only users whitelisted somewhere else are allowed to log in to the system.

In order to test this behaviour with Simpletest, I would like to assert that a random user has no access to the system.

I have tried to create this random user and then to call drupalLogin(). Unfortunately, my test fails because drupalLogin() is checking whether the log in succeeded, by calling assertLink() internally.

This is what I have tried:

    $user = $this-&gt;drupalCreateUser(array());
    $user-&gt;roles[] = 'authenticated user';
    user_save($user);

    // Try to login with it
    // It fails, because of the additional validation performed by my custom module
    $this-&gt;drupalLogin($user);

    // I would like to assert it here instead:
    $this-&gt;assertFalse(isset($this-&gt;loggedInUser-&gt;uid));


What should I do in order to avoid the assertion to fail at drupalLogin(), so that I can assert it myself?

Any help will be appreciated.
In case someone else wonders about this... It wasn't difficult, but I didn't realise at first that it can be done by copying part of the DrupalWebTestCase::drupalLogin() source code:

$edit = array(
  'name' =&gt; $user-&gt;name,
  'pass' =&gt; $user-&gt;pass_raw,
);
$this-&gt;drupalPost('user', $edit, t('Log in'));


And then asserting that the user could not log in:

// Assert that the user is not logged in
$this-&gt;assertNoLink(t('Log out'), 0, t('User not logged in.'), t('User login'));