function VotingAPITestCase::validateVoteCounts in Voting API 7.2
Same name and namespace in other branches
- 6.2 tests/votingapi.test \VotingAPITestCase::validateVoteCounts()
- 7.3 tests/votingapi.test \VotingAPITestCase::validateVoteCounts()
2 calls to VotingAPITestCase::validateVoteCounts()
- VotingAPITestCase::testAddMultipleVotes in tests/
votingapi.test - Add multiple votes and ensure that the vote calculations are working.
- VotingAPITestCase::testAddVote in tests/
votingapi.test - Add a vote and ensure that the vote was stored properly.
File
- tests/
votingapi.test, line 144 - Test file for VotingAPI module.
Class
- VotingAPITestCase
- @file Test file for VotingAPI module.
Code
function validateVoteCounts($prefix, $votes, $entity_id, $values, $entity_type = 'node', $value_type = 'percent', $tag = 'vote') {
$count_summary = 0;
$average_summary = 1;
$count = 0.0;
$sum = 0.0;
foreach ($values as $value) {
$sum += $value;
$count++;
}
$average = $sum / $count;
$prefix_array = array(
'@prefix' => $prefix,
);
foreach ($votes as $summary) {
if ($summary['function'] == 'count') {
$summary_desc = 'count summary';
$prefix_array['@summary_desc'] = $summary_desc;
$this
->assertTrue($summary['value'] == $count, t('@prefix: (@summary_desc) value should match the number of values.', $prefix_array));
}
elseif ($summary['function'] == 'average') {
$summary_desc = 'average summary';
$prefix_array['@summary_desc'] = $summary_desc;
$this
->assertTrue($summary['value'] == $average, t('@prefix: (@summary_desc) value should match the average of values', $prefix_array));
}
else {
$prefix_array['@summary'] = $summary['function'];
$prefix_array['@summary_desc'] = $summary['function'] . ' summary';
$this
->assertFalse(TRUE, t('@prefix: Unknown summary type @summary.', $prefix_array));
}
$this
->assertTrue($summary['entity_type'] == $entity_type, t('@prefix: (@summary_desc) entity_type should match, default = "node"', $prefix_array));
$this
->assertTrue($summary['entity_id'] == $entity_id, t('@prefix: (@summary_desc) entity_id should match', $prefix_array));
$this
->assertTrue($summary['value_type'] == $value_type, t('@prefix: (@summary_desc) value_type should match.', $prefix_array));
$this
->assertTrue($summary['tag'] == $tag, t('@prefix: (@summary_desc) tag should match', $prefix_array));
}
}