function VotingAPITestCase::testAddVote in Voting API 7.3
Same name and namespace in other branches
- 6.2 tests/votingapi.test \VotingAPITestCase::testAddVote()
- 7.2 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 = new VotingApi_Vote(array(
'entity_id' => $nid,
'value' => $value,
'entity_type' => 'node',
));
try {
$result = VotingApi_Vote::saveMultiple($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_Vote::saveMultiple threw an error.');
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,
));
}