You are here

function CaptchaAdminTestCase::testUntrustedUserPosting in CAPTCHA 7

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

File

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

Class

CaptchaAdminTestCase

Code

function testUntrustedUserPosting() {

  // Set CAPTCHA on comment form.
  captcha_set_form_id_setting(self::COMMENT_FORM_ID, 'captcha/Math');

  // Create a node with comments enabled.
  $node = $this
    ->createNodeWithCommentsEnabled();

  // Log in as normal (untrusted) user.
  $this
    ->drupalLogin($this->normal_user);

  // Go to node page and click the "add comment" link.
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->clickLink(t('Add new comment'));
  $add_comment_url = $this
    ->getUrl();

  // Check if CAPTCHA is visible on form.
  $this
    ->assertCaptchaPresence(TRUE);

  // Try to post a comment with wrong answer.
  $edit = $this
    ->getCommentFormValues();
  $edit['captcha_response'] = 'xx';
  $this
    ->drupalPost($add_comment_url, $edit, t('Preview'));
  $this
    ->assertText(t(CAPTCHA_WRONG_RESPONSE_ERROR_MESSAGE), 'wrong CAPTCHA should block form submission.', 'CAPTCHA');

  //TODO: more testing for untrusted posts.
}