Start to move maintainer related functions into maintainer class and separate maintainer related queries and logic from
display code. Also move maintainer related code from the user class. Fix up unit tests to work with the new maintainer class.
This commit is contained in:
@@ -277,200 +277,6 @@ function test_user_update_password()
|
||||
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;
|
||||
|
||||
//FIXME: when we clean up maintainers we'll want to clean this code up as well
|
||||
/* queue up the maintainership */
|
||||
// add to queue
|
||||
$hResult = query_parameters("INSERT INTO appMaintainers (appId, versionId, ".
|
||||
"userId, maintainReason, superMaintainer, submitTime, queued) ".
|
||||
"VALUES ('?', '?', '?', '?', '?', ?, '?')",
|
||||
$iAppId, $iVersionId,
|
||||
$_SESSION['current']->iUserId, "Some crazy reason",
|
||||
TRUE ? "1" : "0", "NOW()", 'true');
|
||||
|
||||
$iMaintainerId = mysql_insert_id();
|
||||
|
||||
$statusMessage = $oUser->addAsMaintainer($iAppId, $iVersionId, TRUE, $iMaintainerId);
|
||||
|
||||
/* 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
|
||||
*/
|
||||
//FIXME: when we clean up maintainers we'll want to clean this code up as well
|
||||
/* queue up the maintainership */
|
||||
// add to queue
|
||||
$hResult = query_parameters("INSERT INTO appMaintainers (appId, versionId, ".
|
||||
"userId, maintainReason, superMaintainer, submitTime, queued) ".
|
||||
"VALUES ('?', '?', '?', '?', '?', ?, '?')",
|
||||
$iAppId, $iVersionId,
|
||||
$_SESSION['current']->iUserId, "Some crazy reason",
|
||||
FALSE ? "1" : "0", "NOW()", 'true');
|
||||
|
||||
$iMaintainerId = mysql_insert_id();
|
||||
|
||||
$statusMessage = $oUser->addAsMaintainer($iAppId, $iVersionId, FALSE, $iMaintainerId);
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
function test_user_getAppsMaintained()
|
||||
{
|
||||
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 this user an admin so we can create applications without having them queued */
|
||||
$hResult = query_parameters("INSERT into user_privs values ('?', '?')",
|
||||
$oUser->iUserId, "admin");
|
||||
|
||||
/* create a application so we have a valid appFamily for the call to user::getAppsMaintained() */
|
||||
$oApp = new Application();
|
||||
$oApp->sName = "Some application";
|
||||
$oApp->sDescription = "some description";
|
||||
$oApp->submitterId = $oUser->iUserId;
|
||||
if(!$oApp->create())
|
||||
{
|
||||
echo "Failed to create application!\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* make the user a super maintatiner
|
||||
*/
|
||||
$iAppId = $oApp->iAppId; /* use the iAppId of the application we just created */
|
||||
$iVersionId = 655200;
|
||||
$bSuperMaintainer = TRUE;
|
||||
|
||||
//FIXME: when we clean up maintainers we'll want to clean this code up as well
|
||||
/* queue up the maintainership */
|
||||
// add to queue
|
||||
$hResult = query_parameters("INSERT INTO appMaintainers (appId, versionId, ".
|
||||
"userId, maintainReason, superMaintainer, submitTime, queued) ".
|
||||
"VALUES ('?', '?', '?', '?', '?', ?, '?')",
|
||||
$iAppId, $iVersionId,
|
||||
$_SESSION['current']->iUserId, "Some crazy reason",
|
||||
$bSuperMaintainer ? "1" : "0", "NOW()", 'true');
|
||||
|
||||
$iMaintainerId = mysql_insert_id();
|
||||
|
||||
$statusMessage = $oUser->addAsMaintainer($iAppId, $iVersionId, $bSuperMaintainer, $iMaintainerId);
|
||||
|
||||
/* get an array of the apps maintained */
|
||||
$aAppsMaintained = $oUser->getAppsMaintained();
|
||||
|
||||
if(!$aAppsMaintained)
|
||||
{
|
||||
echo "aAppsMaintained is null, we expected a non-null return value!\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
/* get only the first entry from the array of applications maintained */
|
||||
/* we only added the user as a maintainer of a single application */
|
||||
list($iAppId1, $iVersionId1, $bSuperMaintainer1) = $aAppsMaintained[0];
|
||||
|
||||
/* make sure all parameters match what we added as maintainer information */
|
||||
if($iAppId1 != $iAppId)
|
||||
{
|
||||
echo "Expected iAppid of ".$iAppId." but got ".$iAppId1."\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
if($iVersionId1 != $iVersionId)
|
||||
{
|
||||
echo "Expected iVersionId of ".$iVersionId." but got ".$iVersionId1."\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
if($bSuperMaintainer1 != $bSuperMaintainer)
|
||||
{
|
||||
echo "Expected bSuperMaintainer of ".$bSuperMaintainer." but got ".$bSuperMaintainer1."\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
/* remove maintainership for this user */
|
||||
$oUser->deleteMaintainer($iAppId);
|
||||
|
||||
/* remove this application */
|
||||
$oApp = new Application($iAppId);
|
||||
$oApp->delete();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*************************/
|
||||
/* Main testing routines */
|
||||
|
||||
@@ -504,20 +310,13 @@ if(!test_user_update_password())
|
||||
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";
|
||||
|
||||
if(!test_user_getAppsMaintained())
|
||||
echo "test_user_getAppsMaintained() failed!\n";
|
||||
else
|
||||
echo "test_user_getAppsMaintained() passed\n";
|
||||
/* Perform the maintainer tests here because they require that a user we can log into */
|
||||
/* and we want to save on having to clean up the user by duplicating the cleanup code below */
|
||||
include_once("test_maintainer.php");
|
||||
|
||||
/* TODO: the rest of the user member functions we don't currently test */
|
||||
|
||||
|
||||
|
||||
/* clean up the user we created during testing */
|
||||
/* so the unit test leaves no trace that it ran */
|
||||
$oUser = new User();
|
||||
|
||||
Reference in New Issue
Block a user