You are here

protected function BotchaBaseWebTestCase::assertCommentFormSubmission in BOTCHA Spam Prevention 7.2

Same name and namespace in other branches
  1. 6.2 botcha.test \BotchaBaseWebTestCase::assertCommentFormSubmission()
  2. 6.3 tests/botcha.simpletest.test \BotchaBaseWebTestCase::assertCommentFormSubmission()
  3. 7.3 tests/botcha.simpletest.test \BotchaBaseWebTestCase::assertCommentFormSubmission()

Assert function for testing if comment posting works as it should.

Creates node with comment writing enabled, tries to post comment with given BOTCHA response (caller should enable the desired challenge on page node comment forms) and checks if the result is as expected.

Parameters

$node existing node to post comments to (if NULL, will be created):

$should_pass boolean describing if the posting should pass or should be blocked:

$message message to prefix to nested asserts:

$button name of button to click (t('Save') by default):

1 call to BotchaBaseWebTestCase::assertCommentFormSubmission()
BotchaBaseWebTestCase::assertFormSubmission in ./botcha.test
Check whether our suspections are real.

File

./botcha.test, line 606
Tests for BOTCHA module.

Class

BotchaBaseWebTestCase
Base class for BOTCHA tests.

Code

protected function assertCommentFormSubmission($edit, $should_pass, $button) {

  // Assertion itself.
  switch ($should_pass) {
    case FALSE:

      // Check for error message.
      $this
        ->assertText(BOTCHA_WRONG_RESPONSE_ERROR_MESSAGE, 'Comment submission should be blocked.', 'BOTCHA');

      // Check that there is still BOTCHA after failed submit.
      $this
        ->assertBotchaPresence(TRUE);
      $this
        ->assertNoText($edit['subject'], 'Comment should not show up on node page.', 'BOTCHA');

      // !!? Do we need to check message body?

      //$this->assertNoText($comment_body, $message . ' Comment should not show up on node page.', 'BOTCHA');
      break;
    case TRUE:
    default:
      switch ($button) {
        case t('Preview'):

          // Check that there is still BOTCHA after preview.
          $this
            ->assertBotchaPresence(TRUE);
          break;
        case t('Save'):
        default:

          // There should be no error message.
          $this
            ->assertBotchaResponseAccepted();
          $this
            ->assertText($edit['subject'], 'Comment should show up on node page.', 'BOTCHA');

          // !!? Do we need to check message body?

          //$this->assertText($edit['comment_body'], $message . ' Comment should show up on node page.', 'BOTCHA');
          break;
      }
      break;
  }
}