You are here

function CaptchaAdminTestCase::testCaptchaPointAdministrationByNonAdmin in CAPTCHA 6.2

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

Method for testing the CAPTCHA point administration

File

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

Class

CaptchaAdminTestCase

Code

function testCaptchaPointAdministrationByNonAdmin() {

  // First add a CAPTCHA point (as admin)
  $this
    ->drupalLogin($this->admin_user);
  $captcha_point_form_id = 'form_' . strtolower($this
    ->randomName(32));
  $captcha_point_module = 'captcha';
  $captcha_point_type = 'Math';
  $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');

  // Switch from admin to nonadmin
  $this
    ->drupalGet(url('logout', array(
    'absolute' => TRUE,
  )));
  $this
    ->drupalLogin($this->normal_user);

  // Try to set CAPTCHA point through admin/user/captcha/captcha/captcha_point
  $this
    ->drupalGet(self::CAPTCHA_ADMIN_PATH . '/captcha/captcha_point');
  $this
    ->assertText(t('You are not authorized to access this page.'), 'Non admin should not be able to set a CAPTCHA point');

  // Try to set CAPTCHA point through admin/user/captcha/captcha/captcha_point/$form_id
  $this
    ->drupalGet(self::CAPTCHA_ADMIN_PATH . '/captcha/captcha_point/' . 'form_' . strtolower($this
    ->randomName(32)));
  $this
    ->assertText(t('You are not authorized to access this page.'), 'Non admin should not be able to set a CAPTCHA point');

  // Try to disable the CAPTCHA point
  $this
    ->drupalGet(self::CAPTCHA_ADMIN_PATH . '/captcha/captcha_point/' . $captcha_point_form_id . '/disable');
  $this
    ->assertText(t('You are not authorized to access this page.'), 'Non admin should not be able to disable a CAPTCHA point');

  // Try to delete the CAPTCHA point
  $this
    ->drupalGet(self::CAPTCHA_ADMIN_PATH . '/captcha/captcha_point/' . $captcha_point_form_id . '/delete');
  $this
    ->assertText(t('You are not authorized to access this page.'), 'Non admin should not be able to delete a CAPTCHA point');

  // Switch from nonadmin to admin again
  $this
    ->drupalGet(url('logout', array(
    'absolute' => TRUE,
  )));
  $this
    ->drupalLogin($this->admin_user);

  // Check if original CAPTCHA point still exists in database
  $result = $this
    ->getCaptchaPointSettingFromDatabase($captcha_point_form_id);
  $this
    ->assertEqual($result->module, $captcha_point_module, 'Enabled CAPTCHA point should still have module set');
  $this
    ->assertEqual($result->captcha_type, $captcha_point_type, 'Enabled CAPTCHA point should still 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');
}