You are here

public function AnswersVotingTestCase::testConfig in Answers 7.4

Test Answers config.

File

answers_voting/answers_voting.test, line 41
Tests for answers_best_answer.module.

Class

AnswersVotingTestCase
Tests the functionality of the answers_userpoints module admin settings.

Code

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.');
}