appdb/ include/maintainer.php unit_test/test_m ...

WineHQ wineowner at wine.codeweavers.com
Sun Dec 3 10:26:38 CST 2006


ChangeSet ID:	30241
CVSROOT:	/opt/cvs-commit
Module name:	appdb
Changes by:	wineowner at winehq.org	2006/12/03 10:26:38

Modified files:
	include        : maintainer.php 
	unit_test      : test_maintainer.php 

Log message:
	Alexander Nicolaysen Sørnes <alex at thehandofagony.com>
	Chris Morgan <cmorgan at alum.wpi.edu>
	Make sure that a maintainer entry is not deleted incorrectly in Maintainer::unQueue().  If
	a request has already been accepted, it is not a duplicate. Add a unit test to test the behavior of Maintainer::unQueue() on
	an already unqueued maintainer.

Patch: http://cvs.winehq.org/patch.py?id=30241

Old revision  New revision  Changes     Path
 1.18          1.19          +2 -3       appdb/include/maintainer.php
 1.1           1.2           +73 -1      appdb/unit_test/test_maintainer.php

Index: appdb/include/maintainer.php
diff -u -p appdb/include/maintainer.php:1.18 appdb/include/maintainer.php:1.19
--- appdb/include/maintainer.php:1.18	3 Dec 2006 16:26:38 -0000
+++ appdb/include/maintainer.php	3 Dec 2006 16:26:38 -0000
@@ -92,9 +92,8 @@ class maintainer
             }
         } else
         {
-            //delete the item from the queue
-            query_parameters("DELETE from appMaintainers WHERE userId = '?' AND maintainerId = '?'",
-                             $this->iUserId, $this->iMaintainerId);
+            /* Delete entry, but only if queued */
+            query_parameters("DELETE from appMaintainers WHERE userId = '?' AND maintainerId = '?' AND queued = 'true'", $this->iUserId, $this->iMaintainerId);
 
             if($oUser->isSuperMaintainer($this->iAppId) && !$this->bSuperMaintainer)
                 $sStatusMessage = "<p>User is already a super maintainer of this application</p>\n";
Index: appdb/unit_test/test_maintainer.php
diff -u -p appdb/unit_test/test_maintainer.php:1.1 appdb/unit_test/test_maintainer.php:1.2
--- appdb/unit_test/test_maintainer.php:1.1	3 Dec 2006 16:26:38 -0000
+++ appdb/unit_test/test_maintainer.php	3 Dec 2006 16:26:38 -0000
@@ -5,6 +5,9 @@ require_once(BASE.'include/maintainer.ph
 
 /* unit tests for maintainer class */
 
+// test that the maintainer count for a given user is accurate for both
+//   maintainers and super maintainers when the user is either a maintainer
+//   or a super maintainer
 function test_maintainer_getMaintainerCountForUser()
 {
     test_start(__FUNCTION__);
@@ -99,6 +102,8 @@ function test_maintainer_getMaintainerCo
     return true;
 }
 
+// test that applications a user maintains are accurately reported by
+//  maintainer::GetAppsMaintained()
 function test_maintainer_getAppsMaintained()
 {
     test_start(__FUNCTION__);
@@ -190,6 +195,67 @@ function test_maintainer_getAppsMaintain
     return true;
 }
 
+// test that unQueueing a queued maintainer request twice is ignored
+function test_maintainer_unQueue()
+{
+    test_start(__FUNCTION__);
+
+    global $test_email, $test_password;
+
+    /* login the user */
+    $oUser = new User();
+    $retval = $oUser->login($test_email, $test_password);
+    if($retval != SUCCESS)
+    {
+        echo "Got '".$retval."' instead of SUCCESS(".SUCCESS.")\n";
+        return false;
+    }
+
+    /**
+      * make the user a super maintatiner
+      */
+    $iAppId = 655000;
+    $iVersionId = 655200;
+
+    /* queue up this maintainer */
+    $oMaintainer = new Maintainer();
+    $oMaintainer->iAppId = $iAppId;
+    $oMaintainer->iVersionId = $iVersionId;
+    $oMaintainer->iUserId = $_SESSION['current']->iUserId;
+    $oMaintainer->sMaintainReason = "Some crazy reason";
+    $oMaintainer->bSuperMaintainer = TRUE;
+    $oMaintainer->create();
+
+    /* and unqueue it to accept the user as a maintainer */
+    $oMaintainer->unQueue("Some reply text");
+
+    /* unqueue it again to ensure that unQueueing a maintainer request twice works properly */
+    $oMaintainer->unQueue("Some other reply text");
+
+
+    /* see that the user is a super maintainer of the one application we added them to be */
+    $iExpected = 1; /* we expect 1 super maintainer for this user */
+    $iSuperMaintainerCount = Maintainer::getMaintainerCountForUser($oUser, TRUE);
+    if($iSuperMaintainerCount != $iExpected)
+    {
+        echo "Got super maintainer count of '".$iSuperMaintainerCount."' instead of '".$iExpected."'\n";
+        return false;
+    }
+
+    /* maintainer count should be zero */
+    $iExpected = 0;
+    $iMaintainerCount = Maintainer::getMaintainerCountForUser($oUser, FALSE);
+    if($iMaintainerCount != $iExpected)
+    {
+        echo "Got maintainer count of '".$iMaintainerCount."' instead of '".$iExpected."'\n";
+        return false;
+    }
+
+    /* remove maintainership for this user */
+    Maintainer::deleteMaintainer($oUser, $iAppId);
+
+    return true;
+}
 
 
 if(!test_maintainer_getMaintainerCountForUser())
@@ -203,4 +269,10 @@ if(!test_maintainer_getAppsMaintained())
 else
     echo "test_maintainer_getAppsMaintained() passed\n";
 
-?>
\ No newline at end of file
+
+if(!test_maintainer_unQueue())
+    echo "test_maintainer_unQueue() failed!\n";
+else
+    echo "test_maintainer_unQueue() passed\n";
+
+?>



More information about the wine-cvs mailing list