You are here

answers_best_answer.test in Answers 7.4

File

answers_best_answer/answers_best_answer.test
View source
<?php

/**
 * @file
 * Tests for answers_best_answer.module.
 */

/**
 * Tests the functionality of the answers_userpoints module admin settings.
 */
class AnswersBestTestCase extends DrupalWebTestCase {

  /**
   * Default test user.
   *
   * @var User
   */
  protected $answersUser;

  /**
   * Test getInfo.
   */
  public static function getInfo() {
    return array(
      'name' => 'Answers Best',
      'description' => 'Answers Best Answer Tests',
      'group' => 'Answers',
    );
  }

  /**
   * Enable modules and create users with specific permissions.
   */
  public function setUp() {
    parent::setUp('answers_best_answer');
    $this->answersUser = $this
      ->drupalCreateUser(array(
      'delete own answers_question content',
      'delete own answers_answer content',
    ));
  }

  /**
   * Test Answers config.
   */
  public function testNormalConfig() {
    $langcode = LANGUAGE_NONE;
    $big_user = $this
      ->drupalCreateUser(array(
      'administer content types',
    ));
    $this
      ->drupalLogin($big_user);
    $this
      ->drupalGet('admin/config/content/answers');
    $this
      ->assertResponse(200);
    $config = array(
      'answers_best_answer_lock_questions_p' => FALSE,
      'answers_best_answer_lock_choice_p' => FALSE,
    );
    $this
      ->drupalPost('admin/config/content/answers', $config, 'Save configuration');
    $this
      ->drupalGet('node/add/answers-question');
    $question = array();
    $question['title'] = 'Woodchucks';
    $question["body[{$langcode}][0][value]"] = "How much wood could a woodchuck chuck?";
    $this
      ->drupalPost('node/add/answers-question', $question, 'Save');
    $answer = array();
    $answer["body[{$langcode}][0][value]"] = "Exactly 42 cords of wood.";
    $this
      ->drupalPost('node/1', $answer, 'Save');
    $this
      ->clickLink('Best');
    $this
      ->assertNoText('Note: This question is locked.');
    $this
      ->clickLink('Unbest');
  }

  /**
   * Test Best Answer locks question.
   */
  public function testBestAnswerLocksConfig() {
    $langcode = LANGUAGE_NONE;
    $big_user = $this
      ->drupalCreateUser(array(
      'administer content types',
    ));
    $this
      ->drupalLogin($big_user);
    $this
      ->drupalGet('admin/config/content/answers');
    $this
      ->assertResponse(200);
    $config = array(
      'answers_best_answer_lock_questions_p' => TRUE,
      'answers_best_answer_lock_choice_p' => FALSE,
    );
    $this
      ->drupalPost('admin/config/content/answers', $config, 'Save configuration');
    $this
      ->drupalGet('node/add/answers-question');
    $question = array();
    $question['title'] = 'Woodchucks';
    $question["body[{$langcode}][0][value]"] = "How much wood could a woodchuck chuck?";
    $this
      ->drupalPost('node/add/answers-question', $question, 'Save');
    $answer = array();
    $answer["body[{$langcode}][0][value]"] = "Exactly 42 cords of wood.";
    $this
      ->drupalPost('node/1', $answer, 'Save');
    $this
      ->clickLink('Best');
    $this
      ->assertText('Note: This question is locked.');
    $this
      ->clickLink('Unbest');
    $this
      ->assertNoText('Note: This question is locked.');
  }

  /**
   * Test Best Answer is locked.
   */
  public function testBestAnswerIsLockedConfig() {
    $langcode = LANGUAGE_NONE;
    $big_user = $this
      ->drupalCreateUser(array(
      'administer content types',
    ));
    $this
      ->drupalLogin($big_user);
    $this
      ->drupalGet('admin/config/content/answers');
    $this
      ->assertResponse(200);
    $config = array(
      'answers_best_answer_lock_questions_p' => TRUE,
      'answers_best_answer_lock_choice_p' => TRUE,
    );
    $this
      ->drupalPost('admin/config/content/answers', $config, 'Save configuration');
    $this
      ->drupalGet('node/add/answers-question');
    $question = array();
    $question['title'] = 'Woodchucks';
    $question["body[{$langcode}][0][value]"] = "How much wood could a woodchuck chuck?";
    $this
      ->drupalPost('node/add/answers-question', $question, 'Save');
    $answer = array();
    $answer["body[{$langcode}][0][value]"] = "Exactly 42 cords of wood.";
    $this
      ->drupalPost('node/1', $answer, 'Save');
    $this
      ->clickLink('Best');
    $this
      ->assertText('Note: This question is locked.');
    $this
      ->assertNoLink('Unbest');
    $this
      ->assertNoLink('Best');
  }

  /**
   * Test deleting best answer.
   */
  public function testDeleteBestAnswer() {
    $langcode = LANGUAGE_NONE;
    $this
      ->drupalLogin($this->answersUser);
    $this
      ->drupalGet('node/add/answers-question');
    $question = array();
    $question['title'] = 'Woodchucks';
    $question["body[{$langcode}][0][value]"] = "How much wood could a woodchuck chuck?";
    $this
      ->drupalPost('node/add/answers-question', $question, 'Save');
    $answer = array();
    $answer["body[{$langcode}][0][value]"] = "Exactly 42 cords of wood.";
    $this
      ->drupalPost('node/1', $answer, 'Save');
    $this
      ->clickLink('Best');
    $answer["body[{$langcode}][0][value]"] = "Woodchucks do not chuckwood.";
    $this
      ->drupalPost('node/1', $answer, 'Save');
    $this
      ->drupalGet('node/2/delete');
    $this
      ->drupalPost('node/2/delete', array(), 'Delete');
    $this
      ->drupalGet('node/1');
    $this
      ->clickLink('Best');
    $this
      ->drupalGet('node/1/delete');
    $this
      ->drupalPost('node/1/delete', array(), 'Delete');
  }

  /**
   * Test changing best answer.
   */
  public function testChangeBestAnswer() {
    $langcode = LANGUAGE_NONE;
    $this
      ->drupalLogin($this->answersUser);
    $this
      ->drupalGet('node/add/answers-question');
    $question = array();
    $question['title'] = 'Woodchucks';
    $question["body[{$langcode}][0][value]"] = "How much wood could a woodchuck chuck?";
    $this
      ->drupalPost('node/add/answers-question', $question, 'Save');
    $answer = array();
    $answer["body[{$langcode}][0][value]"] = "Exactly 42 cords of wood.";
    $this
      ->drupalPost('node/1', $answer, 'Save');
    $this
      ->clickLink('Best');
    $answer["body[{$langcode}][0][value]"] = "Woodchucks do not chuckwood.";
    $this
      ->drupalPost('node/1', $answer, 'Save');
    $this
      ->clickLink('Best');
  }

}

/**
 * Tests the functionality of the answers_userpoints module admin settings.
 */
class AnswersBestViewTestCase extends DrupalWebTestCase {

  /**
   * Default test user.
   *
   * @var User
   */
  protected $answersUser;

  /**
   * Test getInfo.
   */
  public static function getInfo() {
    return array(
      'name' => 'Answers Best Views',
      'description' => 'Answers Best View Tests',
      'group' => 'Answers',
    );
  }

  /**
   * Enable modules and create users with specific permissions.
   */
  public function setUp() {
    parent::setUp('answers_best_answer');
    $this->answersUser = $this
      ->drupalCreateUser();
  }

  /**
   * Test Qustions view page.
   */
  public function testQuestionsView() {
    $langcode = LANGUAGE_NONE;
    $this
      ->drupalLogin($this->answersUser);
    $this
      ->drupalGet('node/add/answers-question');
    $question = array();
    $question['title'] = 'Woodchucks';
    $question["body[{$langcode}][0][value]"] = "How much wood could a woodchuck chuck?";
    $this
      ->drupalPost('node/add/answers-question', $question, 'Save');
    $answer = array();
    $answer["body[{$langcode}][0][value]"] = "Exactly 42 cords of wood.";
    $this
      ->drupalPost('node/1', $answer, 'Save');
    $this
      ->clickLink('Best');
    $this
      ->drupalGet('node/add/answers-question');
    $question = array();
    $question['title'] = 'Is it true?';
    $question["body[{$langcode}][0][value]"] = "Is what they say about Woodchuck true?";
    $this
      ->drupalPost('node/add/answers-question', $question, 'Save');
    $answer = array();
    $answer["body[{$langcode}][0][value]"] = "Woodchuck do not chuck wood. If that is what they say, then yes it is true.";
    $this
      ->drupalPost('node/3', $answer, 'Save');
    $this
      ->drupalGet('questions');
    $this
      ->assertLink('Is it true?');
    $this
      ->assertLink('Woodchucks');
    $this
      ->drupalGet('questions/unanswered');
    $this
      ->assertLink('Is it true?');
    $this
      ->assertNoText('Woodchucks');
    $this
      ->drupalGet('questions/answered');
    $this
      ->assertNoText('Is it true?');
    $this
      ->assertLink('Woodchucks');
    $this
      ->drupalGet('questions/all');
    $this
      ->assertLink('Is it true?');
    $this
      ->assertLink('Woodchucks');
  }

}

Classes

Namesort descending Description
AnswersBestTestCase Tests the functionality of the answers_userpoints module admin settings.
AnswersBestViewTestCase Tests the functionality of the answers_userpoints module admin settings.