You are here

function CaptchaPersistenceTestCase::testPersistenceOnlyOnce in CAPTCHA 7

Same name and namespace in other branches
  1. 6.2 captcha.test \CaptchaPersistenceTestCase::testPersistenceOnlyOnce()

File

./captcha.test, line 932
Tests for CAPTCHA module.

Class

CaptchaPersistenceTestCase

Code

function testPersistenceOnlyOnce() {

  // Set up of persistence and CAPTCHAs.
  $this
    ->setUpPersistence(CAPTCHA_PERSISTENCE_SKIP_ONCE_SUCCESSFUL);

  // Go to login form and check if there is a CAPTCHA on the login form.
  $this
    ->drupalGet('user');
  $this
    ->assertCaptchaPresence(TRUE);
  $captcha_sid_initial = $this
    ->getCaptchaSidFromForm();

  // Try to with wrong user name and password, but correct CAPTCHA.
  $edit = array(
    'name' => 'foobar',
    'pass' => 'bazlaz',
    'captcha_response' => 'Test 123',
  );
  $this
    ->drupalPost(NULL, $edit, t('Log in'));

  // Check that there was no error message for the CAPTCHA.
  $this
    ->assertCaptchaResponseAccepted();

  // There shouldn't be a CAPTCHA on the new form.
  $this
    ->assertCaptchaPresence(FALSE);
  $this
    ->assertPreservedCsid($captcha_sid_initial);

  // Start a new form instance/session
  $this
    ->drupalGet('node');
  $this
    ->drupalGet('user');
  $this
    ->assertCaptchaPresence(FALSE);
  $this
    ->assertDifferentCsid($captcha_sid_initial);

  // Check another form
  $this
    ->drupalGet('user/register');
  $this
    ->assertCaptchaPresence(FALSE);
  $this
    ->assertDifferentCsid($captcha_sid_initial);
}