t('VotingAPI voting - delete vote'), 'desc' => t('Unit testing of votingapi_change_vote and related functions.'), 'group' => 'Voting API', ); } /** * Implementation of tearDown(). */ function tearDown() { parent::tearDown(); // Clean up all remaining votes set by the test. if (count($this->_cleanupVotes)) { $content_types = array_unique($this->_cleanupVotes); $placeholder = implode(', ', array_fill(0, count($content_types), "'%s'")); db_query("DELETE FROM {votingapi_vote} WHERE content_type IN ($placeholder)", $content_types); db_query("DELETE FROM {votingapi_cache} WHERE content_type IN ($placeholder)", $content_types); } } /** * Implementation of setUp(). */ function setUp() { parent::setUp(); $this->drupalModuleEnable('votingapi'); } /** * VADV-01A: Delete a vote with a full vote object. */ function testVotingAPIDeleteVoteFull() { global $user; $this->assertTrue(TRUE, t('VADV-01A: Delete a vote with a full vote object.')); $content_type = $this->randomName(12, 'VTest_'); $this->_cleanupVotes[] = $content_type; $content_id = mt_rand(0, 0xffff); $value = mt_rand(-0xfffe, 0xffff); $vobj = votingapi_add_vote($content_type, $content_id, $value); votingapi_delete_vote($vobj); $this->assertVotingAPIVoteDeleted($vobj); } /** * VADV-01B: Delete a vote. */ function testVotingAPIDeleteVoteMinimal() { global $user; $this->assertTrue(TRUE, t('VADV-01B: Delete a vote with a minimal vote object.')); $content_type = $this->randomName(12, 'VTest_'); $this->_cleanupVotes[] = $content_type; $content_id = mt_rand(0, 0xffff); $value = mt_rand(-0xfffe, 0xffff); $vobj = votingapi_add_vote($content_type, $content_id, $value); $vote = new stdClass(); $vote->vote_id = $vobj->vote_id; votingapi_delete_vote($vote); $this->assertVotingAPIVoteDeleted($vobj); } /** * VADV-02: Delete multiple votes. */ function testVotingAPIDeleteVotes() { global $user; $this->assertTrue(TRUE, t('VADV-02: Delete multiple votes.')); $content_type = $this->randomName(12, 'VTest_'); $this->_cleanupVotes[] = $content_type; $votes = array(); $num_votes = mt_rand(2, 20); for ($i = 0; $i < $num_votes; $i++) { $content_id = mt_rand(0, 0xffff); $value = mt_rand(-0xfffe, 0xffff); $vobj = votingapi_add_vote($content_type, $content_id, $value); $votes[] = $vobj; } votingapi_delete_votes($votes); foreach ($votes as $vobj) { $this->assertVotingAPIVoteDeleted($vobj); } } /** * VADV-03: Delete multiple votes on a content. */ function testVotingAPIDeleteContentVotes() { global $user; $this->assertTrue(TRUE, t('VADV-03: Delete multiple votes on a content.')); $content_type = $this->randomName(12, 'VTest_'); $this->_cleanupVotes[] = $content_type; $content_id = mt_rand(0, 0xffff); $votes = array(); $num_votes = mt_rand(2, 20); for ($i = 0; $i < $num_votes; $i++) { $value = mt_rand(-0xfffe, 0xffff); $tag = $this->randomName(12, 'VTest_'); $vobj = votingapi_add_vote($content_type, $content_id, $value); $votes[] = $vobj; } votingapi_unset_vote($content_type, $content_id); foreach ($votes as $vobj) { $this->assertVotingAPIVoteDeleted($vobj); } } function assertVotingAPIVoteDeleted($vobj) { $this->assertTrue(is_object($vobj), t('Vote is an object.')); $this->assertTrue(TRUE, t('Fetching previous vote with the same settings as set by the vote.')); $vote = votingapi_get_vote($vobj->content_type, $vobj->content_id, $vobj->value_type, $vobj->tag, $vobj->uid); $this->assertTrue(empty($vote), t('Result is empty.')); $this->assertTrue(TRUE, t('Fetching previous vote using vote id.')); $vote = votingapi_get_vote_by_id($vobj->vote_id); $this->assertTrue(empty($vote), t('Result is empty.')); } }