You are here

public function BotchaTestAdminLinks::testAdminLinks in BOTCHA Spam Prevention 7.3

Same name and namespace in other branches
  1. 6.3 tests/botcha.simpletest.test \BotchaTestAdminLinks::testAdminLinks()

Testing of the BOTCHA administration links.

File

tests/botcha.simpletest.test, line 863
Simpletest-tests for BOTCHA module.

Class

BotchaTestAdminLinks

Code

public function testAdminLinks() {
  $form_controller = $this->application
    ->getController(Botcha::CONTROLLER_TYPE_FORM);

  // 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::ADMIN_PATH . '/form', $edit, t('Save configuration'));

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

  // @todo Abstract it.

  //$form_id = 'comment_form';
  $form_id = 'comment_node_page_form';
  $botcha_form = $form_controller
    ->getForm($form_id);

  // Allow BOTCHA to protect it ...
  $botcha_form
    ->setEnabled(TRUE);

  // ... and also make it belonging to no recipebook.
  $botcha_form
    ->unsetRecipebook();
  $form_controller
    ->save($botcha_form);

  // 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 = $form_controller
    ->getForm($form_id, FALSE);
  $recipebook_id = $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');
      *
      */
}