You are here

function BotchaAdminTestCase::testBotchaAdminLinks in BOTCHA Spam Prevention 7

Same name and namespace in other branches
  1. 6 botcha.test \BotchaAdminTestCase::testBotchaAdminLinks()
  2. 6.2 botcha.test \BotchaAdminTestCase::testBotchaAdminLinks()
  3. 7.2 botcha.test \BotchaAdminTestCase::testBotchaAdminLinks()

Testing of the BOTCHA administration links.

File

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

Class

BotchaAdminTestCase

Code

function testBotchaAdminLinks() {

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

  // Test for [#1861016]
  $this
    ->drupalGet('user/' . $this->admin_user->uid . '/edit');
  $this
    ->assertText($this->admin_user->name, t('User name found.'), 'BOTCHA');

  // Enable BOTCHA administration links.
  $edit = array(
    'botcha_administration_mode' => TRUE,
  );
  $this
    ->drupalPost(self::BOTCHA_ADMIN_PATH, $edit, 'Save configuration');

  // Create a node with comments enabled.
  $node = $this
    ->createNodeWithCommentsEnabled();

  // Go to node page
  $this
    ->drupalGet('node/' . $node->nid);

  // Click the add new comment link
  $this
    ->clickLink(t('Add new comment'));
  $add_comment_url = $this
    ->getUrl();

  // Remove fragment part from comment URL to avoid problems with later asserts
  $add_comment_url = strtok($add_comment_url, "#");

  ////////////////////////////////////////////////////////////

  // Click the BOTCHA admin link to enable a challenge.
  $this
    ->clickLink(t('Add BOTCHA protection on form'));

  // Enable 'default' BOTCHA.
  $edit = array(
    'botcha_type' => 'default',
  );
  $this
    ->drupalPost($this
    ->getUrl(), $edit, t('Save'));

  // Check if returned to original comment form.
  $this
    ->assertUrl($add_comment_url, array(), 'After setting BOTCHA with BOTCHA admin links: should return to original form.', 'BOTCHA');

  // Check if BOTCHA was successfully enabled (on BOTCHA admin links fieldset).
  $this
    ->assertText(t('Saved BOTCHA point settings.', array(
    '@type' => 'default',
  )), 'Enable a challenge through the BOTCHA admin links', 'BOTCHA');

  // Check if BOTCHA was successfully enabled (through API).
  $this
    ->assertBotchaSetting(self::COMMENT_FORM_ID, 'default');

  //////////////////////////////////////////////////////

  // Edit challenge type through BOTCHA admin links.
  $this
    ->clickLink(t('change'));

  // Enable 'default' BOTCHA.
  $edit = array(
    'botcha_type' => 'default',
  );
  $this
    ->drupalPost($this
    ->getUrl(), $edit, t('Save'));

  // Check if returned to original comment form.
  $this
    ->assertEqual($add_comment_url, $this
    ->getUrl(), 'After editing challenge type BOTCHA admin links: should return to original form.', 'BOTCHA');

  // Check if BOTCHA was successfully changed (on BOTCHA admin links fieldset).
  // This is actually the same as the previous setting because the botcha/Math is the
  // default for the default challenge. TODO Make sure the edit is a real change.
  $this
    ->assertText(t('Saved BOTCHA point settings.', array(
    '@type' => 'default',
  )), 'Enable a challenge through the BOTCHA admin links', 'BOTCHA');

  // Check if BOTCHA was successfully edited (through API).
  $this
    ->assertBotchaSetting(self::COMMENT_FORM_ID, 'default');

  //////////////////////////////////////////////////////

  // Disable challenge through BOTCHA admin links.
  $this
    ->clickLink(t('disable'));

  // And confirm.
  $this
    ->drupalPost($this
    ->getUrl(), array(), 'Disable');

  // Check if returned to original comment form.
  $this
    ->assertEqual($add_comment_url, $this
    ->getUrl(), 'After disablin challenge with BOTCHA admin links: should return to original form.', 'BOTCHA');

  // Check if BOTCHA was successfully disabled (on BOTCHA admin links fieldset).
  $this
    ->assertText(t('Disabled BOTCHA for form'), 'Disable challenge through the BOTCHA admin links', 'BOTCHA');

  // Check if BOTCHA was successfully disabled (through API).
  $this
    ->assertBotchaSetting(self::COMMENT_FORM_ID, 'none');
}