Index: votingapi.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/votingapi/votingapi.module,v retrieving revision 1.46.2.9 diff -u -p -r1.46.2.9 votingapi.module --- votingapi.module 10 Jun 2008 19:43:45 -0000 1.46.2.9 +++ votingapi.module 20 Aug 2008 05:47:27 -0000 @@ -582,3 +582,20 @@ function _votingapi_query_builder($name, } } } + +/** + * Implementation of hook_ranking(). + * + * Provides a ranking factor based on average vote score. + * + */ +function votingapi_ranking() { + $ranking = array( + 'votingapi_average_score' => array( + 'title' => t('Voting: Average Score'), + 'score' => '(votingapi_cache.value / 100)', + 'join' => "LEFT JOIN {votingapi_cache} votingapi_cache ON (votingapi_cache.content_id = i.sid AND votingapi_cache.function = 'average' AND votingapi_cache.content_type = 'node' AND votingapi_cache.tag = 'vote') ", + ) + ); + return $ranking; +} Index: tests/votingapi_search_ranking.test =================================================================== RCS file: tests/votingapi_search_ranking.test diff -N tests/votingapi_search_ranking.test --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ tests/votingapi_search_ranking.test 20 Aug 2008 05:47:27 -0000 @@ -0,0 +1,52 @@ + t('Search Ranking: VotingAPI'), + 'description' => t('Tests to ensure content that has a higher vote average rank higher in search results.'), + 'group' => t('Search'), + ); + } + + /** + * Implementation of setUp(). + */ + function setUp() { + parent::setUp('votingapi', 'fivestar'); + } + + /** + * Promoted nodes should rank higher now. + */ + function testVotingAPI() { + $ranking = 'Search Ranking: VotingAPI'; + variable_set('node_rank_votingapi_average_score', 0); + + // Build an array of nodes to test. + for ($i=1; $i < 6; $i++) { + $nodes[$i] = $this->nodes[$i]; + $votes = array( + 'content_type' => 'node', + 'content_id' => $nodes[$i]->nid, + 'value' => 100 / $i + ); + // Test nodes to be modified are not currently #1. + $this->assertNotFirst($ranking, $nodes[$i]->nid, $this->keys); + votingapi_set_votes($votes); + } + variable_set('node_rank_votingapi_average_score', 5); + $this->assertRanking($ranking, $nodes, $this->keys); + variable_set('node_rank_votingapi_average_score', 0); + } +}