ChangeSet ID: 26082 CVSROOT: /opt/cvs-commit Module name: appdb Changes by: wineowner@winehq.org 2006/06/27 14:07:52
Modified files: unit_test : test_user.php
Log message: Chris Morgan cmorgan@alum.wpi.edu Unit tests for user::update_password() and user::getMaintainerCount()
Patch: http://cvs.winehq.org/patch.py?id=26082
Old revision New revision Changes Path 1.2 1.3 +129 -0 appdb/unit_test/test_user.php
Index: appdb/unit_test/test_user.php diff -u -p appdb/unit_test/test_user.php:1.2 appdb/unit_test/test_user.php:1.3 --- appdb/unit_test/test_user.php:1.2 27 Jun 2006 19: 7:52 -0000 +++ appdb/unit_test/test_user.php 27 Jun 2006 19: 7:52 -0000 @@ -6,6 +6,7 @@ require_once("path.php"); require_once("test_common.php"); require_once(BASE."include/incl.php"); require_once(BASE."include/user.php"); +require_once(BASE."include/application.php");
/* TODO: check permissions functions */
@@ -234,6 +235,124 @@ function test_user_getpref_setpref() return true; }
+function test_user_update_password() +{ + 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; + } + + /* change the users password to something new */ + $sNewPassword = $test_password.$test_password; + if(!$oUser->update_password($sNewPassword)) + { + echo "user::update_password() failed to update password to '".$sNewPassword."'\n"; + return false; + } + + /* log the user in again, using the new password this time */ + $oUser = new User(); + $retval = $oUser->login($test_email, $sNewPassword); + if($retval != SUCCESS) + { + echo "Failed to login with new password, got '".$retval."' instead of SUCCESS(".SUCCESS.")\n"; + return false; + } + + /* change the password back to the original one */ + if(!$oUser->update_password($test_password)) + { + echo "user::update_password() failed, unable to restore password to .".$test_password."'\n"; + return false; + } + + return true; +} + +function test_user_getMaintainerCount() +{ + 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; + $iQueueId = 655300; + $statusMessage = $oUser->addAsMaintainer($iAppId, $iVersionId, TRUE, $iQueueId); + + /* 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 = $oUser->getMaintainerCount(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 = $oUser->getMaintainerCount(FALSE); + if($iMaintainerCount != $iExpected) + { + echo "Got maintainer count of '".$iMaintainerCount."' instead of '".$iExpected."'\n"; + return false; + } + + /* remove maintainership for this user */ + $oUser->deleteMaintainer($iAppId); + + + + + /** + * make the user a maintainer + */ + $statusMessage = $oUser->addAsMaintainer($iAppId, $iVersionId, FALSE, $iQueueId); + + /* see that the user is a super maintainer of no applications */ + $iExpected = 0; /* we expect 1 super maintainer for this user */ + $iSuperMaintainerCount = $oUser->getMaintainerCount(TRUE); + if($iSuperMaintainerCount != $iExpected) + { + echo "Got super maintainer count of '".$iSuperMaintainerCount."' instead of '".$iExpected."'\n"; + return false; + } + + /* maintainer count should be one */ + $iExpected = 1; + $iMaintainerCount = $oUser->getMaintainerCount(FALSE); + if($iMaintainerCount != $iExpected) + { + echo "Got maintainer count of '".$iMaintainerCount."' instead of '".$iExpected."'\n"; + return false; + } + + /* remove maintainership for this user */ + $oUser->deleteMaintainer($iAppId, $iVersionId); + + return true; +} +
/*************************/ /* Main testing routines */ @@ -263,6 +382,16 @@ if(!test_user_getpref_setpref()) else echo "test_user_getpref_setpref() passed\n";
+if(!test_user_update_password()) + echo "test_user_update_password() failed!\n"; +else + echo "test_user_update_password() passed\n"; + +if(!test_user_getMaintainerCount()) + echo "test_user_getMaintainerCount() failed!\n"; +else + echo "test_user_getMaintainerCount() passed\n"; + /* TODO: the rest of the user member functions we don't currently test */