You are here

function CaptchaAdminTestCase::testCaptchAdminLinks in CAPTCHA 7

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

Testing of the CAPTCHA administration links.

File

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

Class

CaptchaAdminTestCase

Code

function testCaptchAdminLinks() {

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

  // Enable CAPTCHA administration links.
  $edit = array(
    'captcha_administration_mode' => TRUE,
  );
  $this
    ->drupalPost(self::CAPTCHA_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 CAPTCHA admin link to enable a challenge.
  $this
    ->clickLink(t('Place a CAPTCHA here for untrusted users.'));

  // Enable Math CAPTCHA.
  $edit = array(
    'captcha_type' => 'captcha/Math',
  );
  $this
    ->drupalPost($this
    ->getUrl(), $edit, t('Save'));

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

  // Check if CAPTCHA was successfully enabled (on CAPTCHA admin links fieldset).
  $this
    ->assertText(t('CAPTCHA: challenge "@type" enabled', array(
    '@type' => 'Math',
  )), 'Enable a challenge through the CAPTCHA admin links', 'CAPTCHA');

  // Check if CAPTCHA was successfully enabled (through API).
  $this
    ->assertCaptchaSetting(self::COMMENT_FORM_ID, 'captcha/Math');

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

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

  // Enable Math CAPTCHA.
  $edit = array(
    'captcha_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 CAPTCHA admin links: should return to original form.', 'CAPTCHA');

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

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

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

  // Disable challenge through CAPTCHA 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 CAPTCHA admin links: should return to original form.', 'CAPTCHA');

  // Check if CAPTCHA was successfully disabled (on CAPTCHA admin links fieldset).
  $this
    ->assertText(t('CAPTCHA: no challenge enabled'), 'Disable challenge through the CAPTCHA admin links', 'CAPTCHA');

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