Module: appdb Branch: master Commit: 8d9cefe7b69a9cc7c87e51ad17408986e5304874 URL: http://source.winehq.org/git/appdb.git/?a=commit;h=8d9cefe7b69a9cc7c87e51ad1...
Author: Alexander Nicolaysen Sørnes alex@thehandofagony.com Date: Tue Oct 9 21:15:10 2007 +0200
vote: Add support for deleting votes
---
include/vote.php | 38 +++++++++++++++++++++++++++++++++++++- unit_test/test_voting.php | 21 +++++++++++++++++---- 2 files changed, 54 insertions(+), 5 deletions(-)
diff --git a/include/vote.php b/include/vote.php index 32303da..e636571 100644 --- a/include/vote.php +++ b/include/vote.php @@ -55,6 +55,21 @@ class vote
return TRUE; } + + public function delete() + { + /* A vote needs to have a versionId, so if it doesn't that means it is not in the + database or it was not selected in the vote editor */ + if(!$this->iVersionId) + return TRUE; + + $hResult = query_parameters("DELETE FROM appVotes WHERE id = '?'", $this->iVoteId); + + if(!$hResult) + return FALSE; + + return TRUE; + } }
class voteManager @@ -82,7 +97,7 @@ class voteManager
public function outputEditor($aClean = null) { - echo "The following shows your current votes. Check the boxes next to the apps you wish to replace with a vote for ".version::fullNameLink($aClean['iVersionId'])."."; + echo "The following shows your current votes. Check the boxes next to the apps you wish to replace with a vote for ".version::fullNameLink($aClean['iVersionId'])." or delete.";
$oTable = new table(); $this->aVotes = $this->getVotes(); @@ -107,6 +122,11 @@ class voteManager return FALSE; }
+ function objectGetMail($sAction, $bMailSubmitter, $bParentAction) + { + return array(null, null, null); /* No mail */ + } + public function mustBeQueued() { return FALSE; @@ -127,6 +147,22 @@ class voteManager return TRUE; }
+ public function delete() + { + $bSuccess = TRUE; + + if(!is_array($this->aVotes)) + $this->aVotes = $this->getVotes(); + + foreach($this->aVotes as $oVote) + { + if(!$oVote->delete()) + $bSuccess = FALSE; + } + + return $bSuccess; + } + public function update() { foreach($this->aVotes as $oVote) diff --git a/unit_test/test_voting.php b/unit_test/test_voting.php index 9b882b3..efbc64e 100644 --- a/unit_test/test_voting.php +++ b/unit_test/test_voting.php @@ -23,7 +23,7 @@ function test_voteManager_getVotes()
/* Tests that the votes are saved to the database and that we cannot create more than MAX_VOTES. Note that a user always has MAX_VOTES even though they're not in the DB, so we use update instead of create */ -function test_vote_update() +function test_vote_update_delete() { $iUserId = 655000;
@@ -60,13 +60,26 @@ function test_vote_update() return FALSE; }
- /* We don't normally delete votes, so we have to do it manually */ - query_parameters("DELETE FROM appVotes WHERE userId = '?'", $iUserId); + /* Now the entries should be gone again */ + $oVoteManager->delete(); + $iExpected = 0; + $iReceived = 0; /* Incremented below */ + foreach($oVoteManager->getVotes() as $oVote) + { + if($oVote->iVoteId) + $iReceived++; + } + + if($iExpected != $iReceived) + { + echo "Expected $iExpected votes after deletion, got $iReceived\n"; + return FALSE; + }
return TRUE; }
run_test("test_voteManager_getVotes"); -run_test("test_vote_update"); +run_test("test_vote_update_delete");
?> \ No newline at end of file