You are here

public function CaptchaAfterGlobalThresholdTestCase::doTestCaptchaAfterGlobalFloodingThreshold in CAPTCHA After 6

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

Testing of global flooding threshold.

1 call to CaptchaAfterGlobalThresholdTestCase::doTestCaptchaAfterGlobalFloodingThreshold()
CaptchaAfterGlobalThresholdTestCase::testCaptchaAfterFloodingThresholds in ./captcha_after.test
Testing of flooding thresholds for node/add/page form.

File

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

Class

CaptchaAfterGlobalThresholdTestCase
Global threashold tests for the CAPTCHA After module.

Code

public function doTestCaptchaAfterGlobalFloodingThreshold() {

  // Test global flooding threshold.
  variable_set('captcha_after_submit_threshold', 3);
  variable_set('captcha_after_flooding_threshold', 10);

  // While testing we are on a same ip so this needs to be bigger then global floding value.
  variable_set('captcha_after_global_flooding_threshold', 5);

  // Four global submits per hour.
  // Lets test two more submits for other test user.
  $this
    ->drupalLogin($this->test_user1);
  $this
    ->drupalGet('node/add/page');
  $this
    ->assertNoField('captcha_response');
  $edit = array(
    'title' => $this
      ->randomName(8),
    'body' => $this
      ->randomString(32),
  );
  $this
    ->drupalPost('node/add/page', $edit, t('Save'));
  $this
    ->assertText(t('Page @title has been created', array(
    '@title' => $edit['title'],
  )));
  $this
    ->drupalGet('node/add/page');
  $this
    ->assertNoField('captcha_response');
  $this
    ->drupalPost('node/add/page', $edit, t('Save'));
  $this
    ->assertText(t('Page @title has been created', array(
    '@title' => $edit['title'],
  )));
  $this
    ->drupalGet('node/add/page');
  $this
    ->assertField('captcha_response');

  // Try with bad captcha solution.
  $edit['captcha_response'] = '?';
  $this
    ->drupalPost('node/add/page', $edit, t('Save'));
  $this
    ->assertText(CAPTCHA_WRONG_RESPONSE_ERROR_MESSAGE);
  $this
    ->assertField('captcha_response', 'Global flooding threshold test finished.');

  // Try with good captcha solution.
  $edit['captcha_response'] = 'Test 123';
  $this
    ->drupalPost('node/add/page', $edit, t('Save'));
  $this
    ->assertText(t('Page @title has been created', array(
    '@title' => $edit['title'],
  )), 'Global flooding threshold test finished.');
}