function BotchaTestCase::testBotchaOnLoginForm in BOTCHA Spam Prevention 6
Same name and namespace in other branches
- 7 botcha.test \BotchaTestCase::testBotchaOnLoginForm()
 
Testing the protection of the user log in form.
File
- ./
botcha.test, line 235  - Tests for BOTCHA module.
 
Class
Code
function testBotchaOnLoginForm() {
  // Create user and test log in without BOTCHA.
  $user = $this
    ->drupalCreateUser();
  $this
    ->drupalLogin($user);
  // Log out again.
  $this
    ->drupalLogout();
  // Set a BOTCHA on login form
  botcha_set_form_id_setting('user_login', 'default');
  // Check if there is a BOTCHA on the login form (look for the title).
  $this
    ->drupalGet('user');
  $this
    ->assertBotchaPresence(TRUE);
  // Try to log in, which should fail (due to JS required for 'default' BOTCHA recipe is not present in simpletest browser).
  $edit = array(
    'name' => $user->name,
    'pass' => $user->pass_raw,
  );
  $this
    ->drupalPost('user', $edit, t('Log in'));
  // Check for error message.
  $this
    ->assertText(t(BOTCHA_WRONG_RESPONSE_ERROR_MESSAGE), 'BOTCHA should block user login form', 'BOTCHA');
  // And make sure that user is not logged in: check for name and password fields on ?q=user
  $this
    ->drupalGet('user');
  $this
    ->assertField('name', t('Username field found.'), 'BOTCHA');
  $this
    ->assertField('pass', t('Password field found.'), 'BOTCHA');
}