You are here

function BotchaAdminTestCase::testBotchaPointAdministrationByNonAdmin in BOTCHA Spam Prevention 7

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

Method for testing the BOTCHA point administration

File

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

Class

BotchaAdminTestCase

Code

function testBotchaPointAdministrationByNonAdmin() {

  // First add a BOTCHA point (as admin)
  $this
    ->drupalLogin($this->admin_user);
  $botcha_point_form_id = 'form_' . strtolower($this
    ->randomName(32));
  $botcha_point_type = 'default';
  $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');

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

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

  // Try to set BOTCHA point through admin/user/botcha/botcha_point/$form_id
  $this
    ->drupalGet(self::BOTCHA_ADMIN_PATH . '/botcha_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 BOTCHA point');

  // Try to disable the BOTCHA point
  $this
    ->drupalGet(self::BOTCHA_ADMIN_PATH . '/botcha_point/' . $botcha_point_form_id . '/disable');
  $this
    ->assertText(t('You are not authorized to access this page.'), 'Non admin should not be able to disable a BOTCHA point');

  // Try to delete the BOTCHA point
  $this
    ->drupalGet(self::BOTCHA_ADMIN_PATH . '/botcha_point/' . $botcha_point_form_id . '/delete');
  $this
    ->assertText(t('You are not authorized to access this page.'), 'Non admin should not be able to delete a BOTCHA point');

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

  // Check if original BOTCHA point still exists in database
  $result = $this
    ->getBotchaPointSettingFromDatabase($botcha_point_form_id);
  $this
    ->assertEqual($result->botcha_type, $botcha_point_type, 'Enabled BOTCHA point should still 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');
}