2006-06-27 16:39:40 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/* common functions used in appdb unit tests */
|
|
|
|
|
|
|
|
|
|
function test_start($sFunctionName)
|
|
|
|
|
{
|
|
|
|
|
echo $sFunctionName."() starting\n";
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-20 22:24:37 +00:00
|
|
|
// create an application and a version of that application
|
|
|
|
|
// return the iVersionId of the created version
|
2007-07-26 03:47:34 +00:00
|
|
|
function create_version_and_parent_app($sId = "")
|
2007-07-20 22:24:37 +00:00
|
|
|
{
|
|
|
|
|
$oApp = new application();
|
2007-07-26 03:47:34 +00:00
|
|
|
$oApp->sName = "OM App ".$sId;
|
2007-08-04 04:50:14 +00:00
|
|
|
if(!$oApp->create())
|
|
|
|
|
{
|
|
|
|
|
error("oApp->create() failed\n");
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-20 22:24:37 +00:00
|
|
|
$oVersion = new version();
|
2007-07-26 03:47:34 +00:00
|
|
|
$oVersion->sName = "OM version ".$sId;
|
2007-07-20 22:24:37 +00:00
|
|
|
$oVersion->iAppId = $oApp->iAppId;
|
2007-08-04 04:50:14 +00:00
|
|
|
if(!$oVersion->create())
|
|
|
|
|
{
|
|
|
|
|
error("oVersion->create() failed");
|
|
|
|
|
}
|
2007-07-20 22:24:37 +00:00
|
|
|
return $oVersion->iVersionId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// delete a version based on the $iVersionId parameter
|
|
|
|
|
// and delete its parent application
|
2007-07-26 03:47:34 +00:00
|
|
|
// NOTE: we enable admin permissions here to ensure that
|
|
|
|
|
// the application and version are deleted
|
2007-07-20 22:24:37 +00:00
|
|
|
function delete_version_and_parent_app($iVersionId)
|
|
|
|
|
{
|
2007-07-26 03:47:34 +00:00
|
|
|
$bWasAdmin = $_SESSION['current']->hasPriv("admin");
|
|
|
|
|
|
|
|
|
|
$_SESSION['current']->addPriv("admin");
|
|
|
|
|
|
2007-07-20 22:24:37 +00:00
|
|
|
$oVersion = new version($iVersionId);
|
|
|
|
|
$oApp = new application($oVersion->iAppId);
|
2007-12-12 22:43:22 +01:00
|
|
|
if(!$oApp->purge())
|
2007-07-26 03:47:34 +00:00
|
|
|
{
|
2007-12-12 22:43:22 +01:00
|
|
|
echo __FUNCTION__."() oApp->purge() failed, returned false!\n";
|
2007-07-26 03:47:34 +00:00
|
|
|
}
|
|
|
|
|
|
2008-06-26 12:07:29 -04:00
|
|
|
// remove the admin privileges only if the user didn't
|
2007-07-26 03:47:34 +00:00
|
|
|
// have them to begin with
|
|
|
|
|
if(!$bWasAdmin)
|
|
|
|
|
$_SESSION['current']->delPriv("admin");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function create_and_login_user($sTestEmail, $sTestPassword)
|
|
|
|
|
{
|
|
|
|
|
$oUser = new User();
|
|
|
|
|
|
|
|
|
|
/* delete the user if they already exist */
|
|
|
|
|
if($oUser->login($sTestEmail, $sTestPassword) == SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
$oUser->delete();
|
|
|
|
|
$oUser = new User();
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-26 14:30:32 +00:00
|
|
|
// create the user
|
|
|
|
|
// NOTE: user::create() will call user::login() to login the user
|
|
|
|
|
// if the user creation is successful
|
2007-07-26 03:47:34 +00:00
|
|
|
$retval = $oUser->create($sTestEmail, $sTestPassword, "Test user", "20051020");
|
|
|
|
|
if($retval != SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
if($retval == USER_CREATE_EXISTS)
|
|
|
|
|
error("The user already exists!");
|
|
|
|
|
else if($retval == USER_LOGIN_FAILED)
|
|
|
|
|
error("User login failed!");
|
|
|
|
|
else
|
|
|
|
|
error("ERROR: UNKNOWN ERROR!!");
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $oUser;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function error($sMsg)
|
|
|
|
|
{
|
|
|
|
|
$aBT = debug_backtrace();
|
|
|
|
|
|
|
|
|
|
// get class, function called by caller of caller of caller
|
|
|
|
|
if(isset($aBT[1]['class']))
|
|
|
|
|
$sClass = $aBT[1]['class'];
|
|
|
|
|
else
|
|
|
|
|
$sClass = "";
|
|
|
|
|
$sFunction = $aBT[1]['function'];
|
|
|
|
|
|
|
|
|
|
// get file, line where call to caller of caller was made
|
|
|
|
|
$sFile = $aBT[0]['file'];
|
|
|
|
|
$sLine = $aBT[0]['line'];
|
|
|
|
|
|
|
|
|
|
// build & return the message
|
|
|
|
|
echo "$sClass::$sFunction:$sFile:$sLine $sMsg\n";
|
2007-07-20 22:24:37 +00:00
|
|
|
}
|
|
|
|
|
|
2007-10-09 21:10:29 +02:00
|
|
|
function run_test($sTestName)
|
|
|
|
|
{
|
|
|
|
|
if(!$sTestName())
|
|
|
|
|
{
|
|
|
|
|
global $bTestSuccess;
|
|
|
|
|
echo "$sTestName() failed!\n";
|
|
|
|
|
$bTestSuccess = false;
|
|
|
|
|
} else
|
|
|
|
|
{
|
|
|
|
|
echo "$sTestName() passed.\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-20 22:24:37 +00:00
|
|
|
?>
|