You are here

answers_voting.test in Answers 7.4

File

answers_voting/answers_voting.test
View source
<?php

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

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

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

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

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

  /**
   * Test Answers config.
   */
  public function testConfig() {
    $langcode = LANGUAGE_NONE;
    $widget_id = array_search('answers_up_down', variable_get('rate_widgets', array()));
    $voting_user = $this
      ->drupalCreateUser();
    $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
      ->drupalLogout();
    $this
      ->drupalLogin($voting_user);
    $this
      ->drupalGet('node/1');
    $this
      ->assertLink('1', 0, 'Up Vote Question exists.');
    $this
      ->assertLink('-1', 0, 'Down Vote Question exists.');
    $this
      ->assertLink('1', 1, 'Up Vote Answer exists.');
    $this
      ->assertLink('-1', 1, 'Up Vote Answer exists.');

    // Up vote Question.
    $this
      ->clickLink('1', 0);
    $votes = rate_get_results('node', 1, $widget_id);
    $this
      ->assertTrue($votes['count'] == 1 && $votes['rating'] == 1 && $votes['up'] == 1, 'Question was Up voted.');

    // Cancel Up vote Question.
    $this
      ->clickLink('1', 0);
    $votes = rate_get_results('node', 1, $widget_id);
    $this
      ->assertTrue($votes['count'] == 0 && $votes['rating'] == 0, 'Up voted was canceled on Question.');

    // Down vote Question.
    $this
      ->clickLink('-1', 0);
    $votes = rate_get_results('node', 1, $widget_id);
    $this
      ->assertTrue($votes['count'] == 1 && $votes['rating'] == -1 && $votes['down'] == 1, 'Question was Down voted.');

    // Cancel down vote Question.
    $this
      ->clickLink('-1', 0);
    $votes = rate_get_results('node', 1, $widget_id);
    $this
      ->assertTrue($votes['count'] == 0 && $votes['rating'] == 0, 'Down voted was canceled on Question.');

    // Up vote Answer.
    $this
      ->clickLink('1', 1);
    $votes = rate_get_results('node', 2, $widget_id);
    $this
      ->assertTrue($votes['count'] == 1 && $votes['rating'] == 1 && $votes['up'] == 1, 'Answer was Up voted.');

    // Cancel Up vote Answer.
    $this
      ->clickLink('1', 1);
    $votes = rate_get_results('node', 2, $widget_id);
    $this
      ->assertTrue($votes['count'] == 0 && $votes['rating'] == 0, 'Up voted was canceled on Answer.');

    // Down vote Answer.
    $this
      ->clickLink('-1', 1);
    $votes = rate_get_results('node', 2, $widget_id);
    $this
      ->assertTrue($votes['count'] == 1 && $votes['rating'] == -1 && $votes['down'] == 1, 'Answer was Down voted.');

    // Cancel down vote Answer.
    $this
      ->clickLink('-1', 1);
    $votes = rate_get_results('node', 2, $widget_id);
    $this
      ->assertTrue($votes['count'] == 0 && $votes['rating'] == 0, 'Down voted was canceled on Answer.');
  }

}

Classes

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