You are here

function VotingAPITestCase::testAddVote in Voting API 7.2

Same name and namespace in other branches
  1. 6.2 tests/votingapi.test \VotingAPITestCase::testAddVote()
  2. 7.3 tests/votingapi.test \VotingAPITestCase::testAddVote()

Add a vote and ensure that the vote was stored properly.

File

tests/votingapi.test, line 70
Test file for VotingAPI module.

Class

VotingAPITestCase
@file Test file for VotingAPI module.

Code

function testAddVote() {
  global $user;
  $value = '7';
  $nid = variable_get('votingapi_nid1', NULL);
  $vote = array(
    'entity_id' => $nid,
    'value' => $value,
    'entity_type' => 'node',
  );
  try {
    $result = votingapi_add_votes($vote);

    // Test that the result has its fields set appropriately.
    $this
      ->validateVote("testAddVote()", $result, $nid, $value, 'node', $user->uid);
    $this
      ->assertTrue(REQUEST_TIME - $result[0]['timestamp'] < 2, t('The timestamp should be less than 2 seconds ago.'));
  } catch (Exception $e) {
    $this
      ->fail('The votingapi_add_votes threw an error during the "votingapi_add_votes" call.');
    return;
  }

  // Load the vote back in and verify it matches.
  $vote_results = votingapi_recalculate_results('node', $nid);
  $this
    ->validateVoteCounts('testAddVote()', $vote_results, $nid, array(
    $value,
  ));
}