You are here

public function BotchaTestAdminGeneral::testAdminGeneral in BOTCHA Spam Prevention 7.3

Same name and namespace in other branches
  1. 6.3 tests/botcha.simpletest.test \BotchaTestAdminGeneral::testAdminGeneral()

Testing general BOTCHA admin functionality.

File

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

Class

BotchaTestAdminGeneral

Code

public function testAdminGeneral() {
  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::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');
}