You are here

public function CaptchaAfterGlobalThresholdTestCase::testCaptchaAfterSubmitThreshold in CAPTCHA After 7

Same name and namespace in other branches
  1. 6 captcha_after.test \CaptchaAfterGlobalThresholdTestCase::testCaptchaAfterSubmitThreshold()

Testing of submit threshold for user login form.

File

./captcha_after.test, line 47
Captcha After tests.

Class

CaptchaAfterGlobalThresholdTestCase
Global threashold tests for the CAPTCHA After module.

Code

public function testCaptchaAfterSubmitThreshold() {

  // Configure captcha protection for user login form.
  module_load_include('inc', 'captcha');
  captcha_set_form_id_setting('user_login', 'captcha/Test');

  // Enable captcha_after for user_login form.
  captcha_after_db_set_form('user_login', array(
    'enable' => 1,
  ));

  // Test enabling of submit threshold.
  variable_set('captcha_after_submit_threshold', 3);
  $this
    ->drupalGet('user');
  $this
    ->assertNoField('captcha_response');

  // Test clean login.
  $edit = array(
    'name' => $this->test_user->name,
    'pass' => $this->test_user->pass_raw,
  );
  $this
    ->drupalPost('user', $edit, t('Log in'));
  $this
    ->assertLink(t('Log out'));
  $this
    ->drupalLogout();

  // Test bad login threshold limit 1.
  $edit['pass'] .= 'wrong pass';
  $this
    ->drupalPost('user', $edit, t('Log in'));
  $this
    ->assertText('Sorry, unrecognized username or password.');
  $this
    ->assertNoField('captcha_response');

  // Test bad login threshold limit 2.
  $this
    ->drupalPost('user', $edit, t('Log in'));
  $this
    ->assertText('Sorry, unrecognized username or password.');
  $this
    ->assertNoField('captcha_response');

  // Test bad login threshold limit 3.
  $this
    ->drupalPost('user', $edit, t('Log in'));
  $this
    ->assertText('Sorry, unrecognized username or password.');
  $this
    ->assertField('captcha_response');

  // Test disabling of submit threshold.
  variable_set('captcha_after_submit_threshold', 0);
  $this
    ->drupalGet('user');
  $this
    ->assertNoField('captcha_response');

  // Try to login with incorect captcha solution.
  variable_set('captcha_after_submit_threshold', 3);
  $edit['pass'] = $this->test_user->pass_raw;
  $edit['captcha_response'] = '?';
  $this
    ->drupalPost('user', $edit, t('Log in'));
  $this
    ->assertText(CAPTCHA_WRONG_RESPONSE_ERROR_MESSAGE);
  $this
    ->assertField('captcha_response');

  // Try to login with correct captcha solution.
  $edit['captcha_response'] = 'Test 123';
  $this
    ->drupalPost('user', $edit, t('Log in'));
  $this
    ->assertLink(t('Log out'));
  $this
    ->assertNoField('captcha_response', 'Submit threshold test finished.');
}