You are here

function BotchaAdminTestCase::testBotchaAdminLinks in BOTCHA Spam Prevention 6.2

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

Testing of the BOTCHA administration links.

File

./botcha.test, line 749
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(Botcha::BOTCHA_ADMIN_PATH . '/form', $edit, 'Save configuration');

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

  // @todo Abstract it.

  //$form_id = 'comment_node_page_form';
  $form_id = 'comment_form';

  // Allow BOTCHA to protect it...
  Botcha::getForm($form_id, FALSE)
    ->setEnabled(TRUE)
    ->unsetRecipebook()
    ->save();

  // Assert precondition.
  $this
    ->assertTrue(($recipebook = Botcha::getForm($form_id, FALSE)
    ->getRecipebook()) instanceof BotchaRecipebookNone, "There should be no recipe book assigned at all (in fact we have {$recipebook->id})", 'BOTCHA');

  // 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'));
  $this
    ->assertFieldByName('botcha_form_id', $form_id, 'Form id has been automatically filled in');

  // Enable 'default' BOTCHA.
  $edit = array(
    'botcha_form_recipebook' => 'default',
  );
  $this
    ->drupalPost(NULL, $edit, t('Add'));

  // 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.
  $this
    ->assertText("Added BOTCHA form {$form_id}.", 'Message displayed', 'BOTCHA');

  // Check the links appearance.
  $botcha_form = Botcha::getForm($form_id, FALSE);
  $recipebook = $botcha_form
    ->getRecipebook();
  $this
    ->assertLink(t('edit'));
  $this
    ->assertLink(t('disable'));

  // Check if BOTCHA was successfully enabled (through API).
  $this
    ->assertFalse($botcha_form instanceof BotchaFormNone, "Botcha protection for {$form_id} form added via admin link", 'BOTCHA');
  $this
    ->assertEqual($recipebook->id, 'default', "Recipe book is chosen for {$form_id} form via admin link", 'BOTCHA');

  /* @todo Delete it since it is already tested in testFormUI.
     // Edit challenge type through BOTCHA admin links.
     $this->clickLink(t('edit'));
     // 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');
     // Delete challenge through BOTCHA admin links.
     $this->clickLink(t('delete'));
     // 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');
      *
      */
}