You are here

public function BotchaBaseWebTestCase::assertFormSubmission in BOTCHA Spam Prevention 7.3

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

Check whether our suspections are real.

6 calls to BotchaBaseWebTestCase::assertFormSubmission()
BotchaNoResubmitTestCase::assertFormSubmission in tests/botcha.simpletest.test
Check whether our suspections are real.
BotchaNoResubmitTestCase::setFormValues in tests/botcha.simpletest.test
Helper function to generate a default form values array for any form.
BotchaTestCase::testFormSubmission in tests/botcha.simpletest.test
BotchaTestFormUI::testFormUI in tests/botcha.simpletest.test
Tests for creating, modifying and deleting botcha forms.
BotchaTestRecipebookUI::testRecipebookUI in tests/botcha.simpletest.test
Tests for creating, modifying and deleting recipe books.

... See full list

2 methods override BotchaBaseWebTestCase::assertFormSubmission()
BotchaNoResubmitTestCase::assertFormSubmission in tests/botcha.simpletest.test
Check whether our suspections are real.
BotchaTimegateTestCase::assertFormSubmission in tests/botcha.simpletest.test
Check whether our suspections are real.

File

tests/botcha.simpletest.test, line 522
Simpletest-tests for BOTCHA module.

Class

BotchaBaseWebTestCase
Base class for BOTCHA tests.

Code

public function assertFormSubmission($form, $edit, $should_pass = TRUE, $button = NULL, &$parameters = array()) {
  $form_controller = $this->application
    ->getController(Botcha::CONTROLLER_TYPE_FORM);
  $recipe_controller = $this->application
    ->getController(Botcha::CONTROLLER_TYPE_RECIPE);
  $recipebook_controller = $this->application
    ->getController(Botcha::CONTROLLER_TYPE_RECIPEBOOK);

  // @todo Refactor all these switches with classes.
  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(!$form_controller
        ->getForm($parameters['botcha_form_id'], FALSE) instanceof BotchaFormNone, 'BOTCHA form successfully added : Form saved to DB', 'BOTCHA');

      // Assert recipe book of the form.
      $recipebook_id = $form_controller
        ->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 = $form_controller
        ->getForm($parameters['botcha_form_id'], TRUE);

      // Assert recipe book of the form.
      $recipebook_id = $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($form_controller
        ->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 = $recipebook_controller
        ->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 = $recipebook_controller
        ->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;
  }
}