You are here

function BotchaAdminTestCase::testAdminGeneral in BOTCHA Spam Prevention 7.2

Testing general BOTCHA admin functionality.

File

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

Class

BotchaAdminTestCase

Code

function testAdminGeneral() {

  // Log in as admin
  $this
    ->drupalLogin($this->admin_user);

  // Clean the environment.
  Botcha::clean();
  variable_set('botcha_form_passed_counter', $pass_cnt = rand(0, 10000));
  variable_set('botcha_form_blocked_counter', $block_cnt = rand(1, 10000));
  $build_cnt = $pass_cnt + $block_cnt;

  // Assert that the statistics is present.
  $this
    ->drupalGet(Botcha::BOTCHA_ADMIN_PATH);
  $this
    ->assertText("Already {$block_cnt} blocked form submissions.", 'BOTCHA blocked count statistics is present', 'BOTCHA');
  $percent = sprintf("%0.3f", 100 * $block_cnt / $build_cnt);
  $this
    ->assertText("({$percent}% of total {$build_cnt} processed)", 'BOTCHA total count statistics is present', 'BOTCHA');

  // Reset BOTCHA statistics.
  $this
    ->drupalPost(NULL, array(), t('Reset BOTCHA statistics'));

  // Assert that the statistics is reset.
  $this
    ->assertText("BOTCHA statistics have been reset.", "Message displayed", 'BOTCHA');
  $this
    ->assertText("Already 0 blocked form submissions.", 'BOTCHA blocked count statistics is reset', 'BOTCHA');
  $this
    ->assertNoText("({$percent}% of total {$build_cnt} processed)", 'BOTCHA total count statistics is reset', 'BOTCHA');
}