You are here

function BotchaAdminTestCase::testBotchaPointAdministration in BOTCHA Spam Prevention 6

Same name and namespace in other branches
  1. 7 botcha.test \BotchaAdminTestCase::testBotchaPointAdministration()

Method for testing the BOTCHA point administration

File

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

Class

BotchaAdminTestCase

Code

function testBotchaPointAdministration() {

  // Generate BOTCHA point data:
  // Drupal form ID should consist of lowercase alphanumerics and underscore)
  $botcha_point_form_id = 'form_' . strtolower($this
    ->randomName(32));

  // the 'default' BOTCHA is always available, so let's use it
  $botcha_point_type = 'default';

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

  // Set BOTCHA point through admin/user/botcha/botcha_point
  $form_values = array(
    'botcha_point_form_id' => $botcha_point_form_id,
    'botcha_type' => $botcha_point_type,
  );
  $this
    ->drupalPost(self::BOTCHA_ADMIN_PATH . '/botcha_point', $form_values, t('Save'));
  $this
    ->assertText(t('Saved BOTCHA point settings.'), 'Saving of BOTCHA point settings');

  // Check in database
  $result = $this
    ->getBotchaPointSettingFromDatabase($botcha_point_form_id);
  $this
    ->assertEqual($result->botcha_type, $botcha_point_type, 'Enabled BOTCHA point should have type set');

  // Disable BOTCHA point again
  $this
    ->drupalPost(self::BOTCHA_ADMIN_PATH . '/botcha_point/' . $botcha_point_form_id . '/disable', array(), t('Disable'));
  $this
    ->assertRaw(t('Disabled BOTCHA for form %form_id.', array(
    '%form_id' => $botcha_point_form_id,
  )), 'Disabling of BOTCHA point');

  // Check in database
  $result = $this
    ->getBotchaPointSettingFromDatabase($botcha_point_form_id);
  $this
    ->assertNull($result->botcha_type, 'Disabled BOTCHA point should have NULL as type');

  // Set BOTCHA point through admin/user/botcha/botcha_point/$form_id
  $form_values = array(
    'botcha_type' => $botcha_point_type,
  );
  $this
    ->drupalPost(self::BOTCHA_ADMIN_PATH . '/botcha_point/' . $botcha_point_form_id, $form_values, t('Save'));
  $this
    ->assertText(t('Saved BOTCHA point settings.'), 'Saving of BOTCHA point settings');

  // Check in database
  $result = $this
    ->getBotchaPointSettingFromDatabase($botcha_point_form_id);
  $this
    ->assertEqual($result->botcha_type, $botcha_point_type, 'Enabled BOTCHA point should have type set');

  // Delete BOTCHA point
  $this
    ->drupalPost(self::BOTCHA_ADMIN_PATH . '/botcha_point/' . $botcha_point_form_id . '/delete', array(), t('Delete'));
  $this
    ->assertRaw(t('Deleted BOTCHA for form %form_id.', array(
    '%form_id' => $botcha_point_form_id,
  )), 'Deleting of BOTCHA point');

  // Check in database
  $result = $this
    ->getBotchaPointSettingFromDatabase($botcha_point_form_id);
  $this
    ->assertFalse($result, 'Deleted BOTCHA point should be in database');
}