You are here

function CaptchaAdminTestCase::testCaptchaPointAdministration in CAPTCHA 7

Same name and namespace in other branches
  1. 6.2 captcha.test \CaptchaAdminTestCase::testCaptchaPointAdministration()

Method for testing the CAPTCHA point administration

File

./captcha.test, line 656
Tests for CAPTCHA module.

Class

CaptchaAdminTestCase

Code

function testCaptchaPointAdministration() {

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

  // the Math CAPTCHA by the CAPTCHA module is always available, so let's use it
  $captcha_point_module = 'captcha';
  $captcha_point_type = 'Math';

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

  // Set CAPTCHA point through admin/user/captcha/captcha/captcha_point
  $form_values = array(
    'captcha_point_form_id' => $captcha_point_form_id,
    'captcha_type' => $captcha_point_module . '/' . $captcha_point_type,
  );
  $this
    ->drupalPost(self::CAPTCHA_ADMIN_PATH . '/captcha/captcha_point', $form_values, t('Save'));
  $this
    ->assertText(t('Saved CAPTCHA point settings.'), 'Saving of CAPTCHA point settings');

  // Check in database
  $result = $this
    ->getCaptchaPointSettingFromDatabase($captcha_point_form_id);
  $this
    ->assertEqual($result->module, $captcha_point_module, 'Enabled CAPTCHA point should have module set');
  $this
    ->assertEqual($result->captcha_type, $captcha_point_type, 'Enabled CAPTCHA point should have type set');

  // Disable CAPTCHA point again
  $this
    ->drupalPost(self::CAPTCHA_ADMIN_PATH . '/captcha/captcha_point/' . $captcha_point_form_id . '/disable', array(), t('Disable'));
  $this
    ->assertRaw(t('Disabled CAPTCHA for form %form_id.', array(
    '%form_id' => $captcha_point_form_id,
  )), 'Disabling of CAPTCHA point');

  // Check in database
  $result = $this
    ->getCaptchaPointSettingFromDatabase($captcha_point_form_id);
  $this
    ->assertNull($result->module, 'Disabled CAPTCHA point should have NULL as module');
  $this
    ->assertNull($result->captcha_type, 'Disabled CAPTCHA point should have NULL as type');

  // Set CAPTCHA point through admin/user/captcha/captcha/captcha_point/$form_id
  $form_values = array(
    'captcha_type' => $captcha_point_module . '/' . $captcha_point_type,
  );
  $this
    ->drupalPost(self::CAPTCHA_ADMIN_PATH . '/captcha/captcha_point/' . $captcha_point_form_id, $form_values, t('Save'));
  $this
    ->assertText(t('Saved CAPTCHA point settings.'), 'Saving of CAPTCHA point settings');

  // Check in database
  $result = $this
    ->getCaptchaPointSettingFromDatabase($captcha_point_form_id);
  $this
    ->assertEqual($result->module, $captcha_point_module, 'Enabled CAPTCHA point should have module set');
  $this
    ->assertEqual($result->captcha_type, $captcha_point_type, 'Enabled CAPTCHA point should have type set');

  // Delete CAPTCHA point
  $this
    ->drupalPost(self::CAPTCHA_ADMIN_PATH . '/captcha/captcha_point/' . $captcha_point_form_id . '/delete', array(), t('Delete'));
  $this
    ->assertRaw(t('Deleted CAPTCHA for form %form_id.', array(
    '%form_id' => $captcha_point_form_id,
  )), 'Deleting of CAPTCHA point');

  // Check in database
  $result = $this
    ->getCaptchaPointSettingFromDatabase($captcha_point_form_id);
  $this
    ->assertFalse($result, 'Deleted CAPTCHA point should be in database');
}