You are here

function BotchaBaseWebTestCase::assertFormSubmission in BOTCHA Spam Prevention 6.2

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

Check whether our suspections are real.

4 calls to BotchaBaseWebTestCase::assertFormSubmission()
BotchaNoResubmitTestCase::assertFormSubmission in ./botcha.test
Check whether our suspections are real.
BotchaNoResubmitTestCase::setFormValues in ./botcha.test
Helper function to generate a default form values array for any form.
BotchaTestCase::testFormSubmission in ./botcha.test
BotchaTimegateTestCase::assertFormSubmission in ./botcha.test
Check whether our suspections are real.
2 methods override BotchaBaseWebTestCase::assertFormSubmission()
BotchaNoResubmitTestCase::assertFormSubmission in ./botcha.test
Check whether our suspections are real.
BotchaTimegateTestCase::assertFormSubmission in ./botcha.test
Check whether our suspections are real.

File

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

Class

BotchaBaseWebTestCase
Base class for BOTCHA tests.

Code

function assertFormSubmission($form, $edit, $should_pass = TRUE, $button = NULL, &$parameters = array()) {
  switch ($form) {

    // These ones for testing Form UI.
    case 'addForm':
      $this
        ->debug("Entered %method %case", array(
        '%method' => __METHOD__,
        '%case' => $form,
      ));

      // Make sure that the message appeared.

      //$this->assertText(t('Added BOTCHA form %form_id.', array('%form_id' => $parameters['botcha_form_id'])), 'BOTCHA form successfully added : Message displayed', 'BOTCHA');
      $this
        ->assertText("Added BOTCHA form {$parameters['botcha_form_id']}.", 'BOTCHA form successfully added : Message displayed', 'BOTCHA');

      // Ensure that the form was created.
      $this
        ->assertTrue(!Botcha::getForm($parameters['botcha_form_id'], FALSE) instanceof BotchaFormNone, 'BOTCHA form successfully added : Form saved to DB', 'BOTCHA');

      // Assert recipe book of the form.
      $recipebook = Botcha::getForm($parameters['botcha_form_id'], FALSE)
        ->getRecipebook();
      $this
        ->assertEqual($parameters['rbid'], $recipebook->id, "BOTCHA form successfully added : Recipe book {$parameters['rbid']} saved correctly as {$recipebook->id}", 'BOTCHA');
      break;
    case 'editForm':
      $this
        ->debug("Entered %method %case", array(
        '%method' => __METHOD__,
        '%case' => $form,
      ));

      // Make sure that the message appeared.
      $this
        ->assertText("Saved BOTCHA form settings for {$parameters['botcha_form_id']}.", 'BOTCHA form successfully saved : Message displayed', 'BOTCHA');

      // @todo ?Why we need to call getForm with $create = TRUE? What's wrong?
      $botcha_form = Botcha::getForm($parameters['botcha_form_id'], TRUE);

      // Assert recipe book of the form.
      $recipebook = $botcha_form
        ->getRecipebook();

      // Ensure recipe book.
      $this
        ->assertEqual($parameters['rbid'], $recipebook->id, "BOTCHA form successfully saved : Recipe book {$parameters['rbid']} saved correctly as {$recipebook->id}", 'BOTCHA');

      // Ensure enabled.
      $this
        ->assertEqual($parameters['botcha_enabled'], $botcha_form
        ->isEnabled(), 'BOTCHA form was successfully turned on/off', 'BOTCHA');
      break;
    case 'deleteForm':
      $this
        ->debug("Entered %method %case", array(
        '%method' => __METHOD__,
        '%case' => $form,
      ));
      $form_id = $parameters['botcha_form_id'];

      // Make sure that the message appeared.
      $this
        ->assertText("Deleted BOTCHA protection for form {$form_id}.", 'BOTCHA form successfully deleted : Message displayed', 'BOTCHA');

      // Ensure that the form was deleted.
      $this
        ->assertTrue(Botcha::getForm($form_id, FALSE) instanceof BotchaFormNone, 'BOTCHA form successfully deleted', 'BOTCHA');
      break;

    // These ones for testing Recipebook UI.
    case 'addRecipebook':
      $this
        ->debug("Entered %method %case", array(
        '%method' => __METHOD__,
        '%case' => $form,
      ));
      $this
        ->assertTrue($recipebook = Botcha::getRecipebook($edit['id'], FALSE), "Recipe book {$edit['id']} should exist", 'BOTCHA');
      foreach (array(
        'id',
        'title',
        'description',
      ) as $field) {
        $this
          ->assertEqual($recipebook->{$field}, $edit[$field], "Recipe book {$edit['id']} should have {$field} equal {$edit[$field]} (in fact it has {$recipebook->{$field}})", 'BOTCHA');
      }
      break;
    case 'editRecipebook':
      $this
        ->debug("Entered %method %case", array(
        '%method' => __METHOD__,
        '%case' => $form,
      ));
      $recipebook = Botcha::getRecipebook($parameters['id'], FALSE);
      foreach (array(
        'title',
        'description',
      ) as $field) {
        $this
          ->assertEqual($recipebook->{$field}, $edit[$field], "Recipe book {$parameters['id']} should have {$field} equal {$edit[$field]} (in fact it has {$recipebook->{$field}})", 'BOTCHA');
      }

      // @todo Add recipes assertion.
      break;
    case 'deleteRecipebook':
      $this
        ->debug("Entered %method %case", array(
        '%method' => __METHOD__,
        '%case' => $form,
      ));

      // @todo Case deleteRecipebook.
      break;

    // And these ones are for testing form submissions.
    case 'node':
      $this
        ->debug("Entered %method %case", array(
        '%method' => __METHOD__,
        '%case' => $form,
      ));
      $this
        ->assertNodeFormSubmission($edit, $should_pass, $button);
      break;
    case 'user_login':
      $this
        ->debug("Entered %method %case", array(
        '%method' => __METHOD__,
        '%case' => $form,
      ));
      $this
        ->assertUserLoginFormSubmission($edit, $should_pass, $button);
      break;
    case 'comment':
    default:
      $this
        ->debug("Entered %method %case", array(
        '%method' => __METHOD__,
        '%case' => $form,
      ));
      $this
        ->assertCommentFormSubmission($edit, $should_pass, $button);
      break;
  }
}