2006-09-26 02:05:55 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
require_once("path.php");
|
|
|
|
|
require_once(BASE.'include/maintainer.php');
|
|
|
|
|
require_once(BASE.'include/user.php');
|
|
|
|
|
require_once(BASE.'include/version.php');
|
|
|
|
|
require_once(BASE.'include/application.php');
|
2007-07-26 03:47:34 +00:00
|
|
|
require_once("test_common.php");
|
2006-09-26 02:05:55 +00:00
|
|
|
|
2007-12-12 22:43:22 +01:00
|
|
|
/* test that Application::purge() properly deletes data dependent on */
|
2006-09-26 02:05:55 +00:00
|
|
|
/* having an application */
|
|
|
|
|
//TODO: need to test that we delete all urls, maintainers and other things
|
|
|
|
|
// tested under an application
|
|
|
|
|
function test_application_delete()
|
|
|
|
|
{
|
|
|
|
|
test_start(__FUNCTION__);
|
|
|
|
|
|
2007-07-26 03:47:34 +00:00
|
|
|
$sTestEmail = "test_application_delete@somesite.com";
|
|
|
|
|
$sTestPassword = "password";
|
|
|
|
|
|
|
|
|
|
if(!$oUser = create_and_login_user($sTestEmail, $sTestPassword))
|
2006-09-26 02:05:55 +00:00
|
|
|
return false;
|
2006-09-27 02:44:16 +00:00
|
|
|
|
2006-09-26 02:05:55 +00:00
|
|
|
/* 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");
|
|
|
|
|
|
|
|
|
|
$oApp = new Application();
|
|
|
|
|
$oApp->sName = "Some application";
|
|
|
|
|
$oApp->sDescription = "some description";
|
|
|
|
|
$oApp->submitterId = $oUser->iUserId;
|
|
|
|
|
if(!$oApp->create())
|
|
|
|
|
{
|
|
|
|
|
$oUser->delete(); /* clean up the user we created prior to exiting */
|
2007-07-26 03:47:34 +00:00
|
|
|
error("Failed to create application!");
|
2006-09-26 02:05:55 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$iAppId = $oApp->iAppId; /* use the iAppId of the application we just created */
|
|
|
|
|
|
|
|
|
|
for($iVersionIdIndex = 0; $iVersionIdIndex < 10; $iVersionIdIndex++)
|
|
|
|
|
{
|
|
|
|
|
$oVersion = new Version();
|
2006-09-27 02:44:16 +00:00
|
|
|
$oVersion->versionName = "Some Version".$iVersionIdIndex;
|
|
|
|
|
$oVersion->description = "Some Version description".$iVersionIdIndex;
|
2006-09-26 02:05:55 +00:00
|
|
|
$oVersion->iAppId = $oApp->iAppId;
|
|
|
|
|
|
|
|
|
|
if(!$oVersion->create())
|
|
|
|
|
{
|
|
|
|
|
delete_app_and_user($oApp, $oUser);
|
|
|
|
|
echo "Failed to create version!\n";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
delete_app_and_user($oApp, $oUser);
|
|
|
|
|
|
|
|
|
|
$sQuery = "SELECT appId
|
|
|
|
|
FROM appVersion
|
|
|
|
|
WHERE appId = '?'";
|
|
|
|
|
|
|
|
|
|
if($hResult = query_parameters($sQuery, $iAppId))
|
|
|
|
|
{
|
2007-08-03 23:27:25 +00:00
|
|
|
$iRows = query_num_rows($hResult);
|
2006-09-26 02:05:55 +00:00
|
|
|
if($iRows > 0)
|
|
|
|
|
{
|
|
|
|
|
echo "Found '".$iRows."' versions for this application left over!";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-27 02:44:16 +00:00
|
|
|
|
|
|
|
|
function test_application_getWithRating()
|
|
|
|
|
{
|
|
|
|
|
test_start(__FUNCTION__);
|
|
|
|
|
|
2007-07-26 03:47:34 +00:00
|
|
|
$sTestEmail = "test_application_getwithrating@somesite.com";
|
|
|
|
|
$sTestPassword = "password";
|
|
|
|
|
|
|
|
|
|
if(!$oUser = create_and_login_user($sTestEmail, $sTestPassword))
|
2006-09-27 02:44:16 +00:00
|
|
|
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");
|
|
|
|
|
|
|
|
|
|
$oApp = new Application();
|
|
|
|
|
$oApp->sName = "Some application";
|
|
|
|
|
$oApp->sDescription = "some description";
|
|
|
|
|
$oApp->submitterId = $oUser->iUserId;
|
|
|
|
|
if(!$oApp->create())
|
|
|
|
|
{
|
|
|
|
|
$oUser->delete();
|
2007-07-26 03:47:34 +00:00
|
|
|
error("Failed to create application!");
|
2006-09-27 02:44:16 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$iAppId = $oApp->iAppId; /* use the iAppId of the application we just created */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Create several versions of the new application to test uniqueness of getWithRating() results */
|
|
|
|
|
|
|
|
|
|
for($iVersionIdIndex = 0; $iVersionIdIndex < 10; $iVersionIdIndex++)
|
|
|
|
|
{
|
|
|
|
|
$oVersion = new Version();
|
|
|
|
|
$oVersion->versionName = "Some Version".$iVersionIdIndex;
|
|
|
|
|
$oVersion->description = "Some Version description".$iVersionIdIndex;
|
|
|
|
|
$oVersion->iAppId = $oApp->iAppId;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Create Several Ratings, some duplicate */
|
|
|
|
|
if ($iVersionIdIndex < 4)
|
|
|
|
|
{
|
|
|
|
|
$oVersion->sTestedRating = "Platinum";
|
|
|
|
|
}
|
|
|
|
|
elseif ($iVersionIdIndex < 8)
|
|
|
|
|
{
|
|
|
|
|
$oVersion->sTestedRating = "Gold";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$oVersion->sTestedRating = "Bronze";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!$oVersion->create())
|
|
|
|
|
{
|
|
|
|
|
delete_app_and_user($oApp, $oUser);
|
2007-07-26 03:47:34 +00:00
|
|
|
error("Failed to create version!");
|
2006-09-27 02:44:16 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$iItemsPerPage = 50;
|
|
|
|
|
$iOffset = 0;
|
|
|
|
|
$sRating = 'Bronze';
|
2006-11-25 17:24:44 +00:00
|
|
|
$aApps = Application::getWithRating($sRating, $iOffset, $iItemsPerPage);
|
2006-09-27 02:44:16 +00:00
|
|
|
$aTest = array();//array to test the uniqueness our query results
|
|
|
|
|
while(list($i, $iId) = each($aApps)) //cycle through results returned by getWithRating
|
|
|
|
|
{
|
|
|
|
|
if ( in_array($iId, $aTest) ) //if the appId is already in our test results fail unique test
|
|
|
|
|
{
|
|
|
|
|
delete_app_and_user($oApp, $oUser);
|
2007-07-26 03:47:34 +00:00
|
|
|
error("getWithRating failed to return a unique result set");
|
2006-09-27 02:44:16 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
array_push($aTest, $iId); //push the appId on to our test array
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
delete_app_and_user($oApp, $oUser);
|
|
|
|
|
|
2006-09-30 01:31:04 +00:00
|
|
|
|
|
|
|
|
//test to ensure getWithRating doesn't return applications that are queued
|
|
|
|
|
|
2007-07-26 03:47:34 +00:00
|
|
|
//create user without admin priveliges
|
|
|
|
|
if(!$oUser = create_and_login_user($sTestEmail, $sTestPassword))
|
|
|
|
|
return false;
|
2006-09-30 01:31:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
$oApp = new Application();
|
|
|
|
|
$oApp->sName = "Some application";
|
|
|
|
|
$oApp->sDescription = "some description";
|
|
|
|
|
$oApp->submitterId = $oUser->iUserId;
|
|
|
|
|
if(!$oApp->create())
|
|
|
|
|
{
|
|
|
|
|
$oUser->delete(); /* clean up the user we created prior to exiting */
|
2007-07-26 03:47:34 +00:00
|
|
|
error("Failed to create application!");
|
2006-09-30 01:31:04 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$iAppId = $oApp->iAppId; /* use the iAppId of the application we just created */
|
|
|
|
|
|
|
|
|
|
$oVersion = new Version();
|
|
|
|
|
$oVersion->versionName = "Some Version".$iVersionIdIndex;
|
|
|
|
|
$oVersion->description = "Some Version description".$iVersionIdIndex;
|
|
|
|
|
$oVersion->iAppId = $oApp->iAppId;
|
|
|
|
|
$oVersion->sTestedRating = "Bronze";
|
2007-12-12 20:56:04 +01:00
|
|
|
$oVersion->objectSetState('queued');
|
2006-09-30 01:31:04 +00:00
|
|
|
|
|
|
|
|
if(!$oVersion->create())
|
|
|
|
|
{
|
|
|
|
|
delete_app_and_user($oApp, $oUser);
|
2007-07-26 03:47:34 +00:00
|
|
|
error("Failed to create version!");
|
2006-09-30 01:31:04 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$aApps=Application::getWithRating($sRating, $iOffset, $iItemsPerPage);
|
|
|
|
|
|
|
|
|
|
if ( in_array($iAppId, $aApps )) //if the appId is in our test results fail queued test
|
|
|
|
|
{
|
|
|
|
|
delete_app_and_user($oApp, $oUser);
|
2007-07-26 03:47:34 +00:00
|
|
|
error("getWithRating failed to return a unique result set");
|
2006-09-30 01:31:04 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2007-01-27 22:58:58 +00:00
|
|
|
delete_app_and_user($oApp, $oUser);
|
|
|
|
|
|
2006-09-27 02:44:16 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-26 02:05:55 +00:00
|
|
|
function delete_app_and_user($oApp, $oUser)
|
|
|
|
|
{
|
2007-07-26 03:47:34 +00:00
|
|
|
$bSuccess = true;
|
2007-12-12 22:43:22 +01:00
|
|
|
if(!$oApp->purge())
|
2006-09-27 02:44:16 +00:00
|
|
|
{
|
2007-12-12 22:43:22 +01:00
|
|
|
echo __FUNCTION__."() oApp->purge() failed\n";
|
2007-07-26 03:47:34 +00:00
|
|
|
$bSuccess = false;
|
2006-09-27 02:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
2007-07-26 03:47:34 +00:00
|
|
|
if(!$oUser->delete())
|
2006-09-27 02:44:16 +00:00
|
|
|
{
|
2007-07-26 03:47:34 +00:00
|
|
|
echo __FUNCTION__."() oUser->delete() failed\n";
|
|
|
|
|
$bSuccess = false;
|
2006-09-27 02:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
2007-07-26 03:47:34 +00:00
|
|
|
return $bSuccess;
|
2006-09-27 02:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
2006-09-26 02:05:55 +00:00
|
|
|
if(!test_application_delete())
|
2007-03-31 17:12:55 +00:00
|
|
|
{
|
2006-09-26 02:05:55 +00:00
|
|
|
echo "test_application_delete() failed!\n";
|
2007-03-31 17:12:55 +00:00
|
|
|
$bTestSuccess = false;
|
|
|
|
|
} else
|
|
|
|
|
{
|
2006-11-25 17:24:44 +00:00
|
|
|
echo "test_application_delete() passed\n";
|
2007-03-31 17:12:55 +00:00
|
|
|
}
|
2006-09-26 02:05:55 +00:00
|
|
|
|
2006-09-27 02:44:16 +00:00
|
|
|
|
|
|
|
|
if(!test_application_getWithRating())
|
2007-03-31 17:12:55 +00:00
|
|
|
{
|
2006-09-27 02:44:16 +00:00
|
|
|
echo "test_application_getWithRating() failed!\n";
|
2007-03-31 17:12:55 +00:00
|
|
|
$bTestSuccess = false;
|
|
|
|
|
} else
|
|
|
|
|
{
|
2006-11-25 17:24:44 +00:00
|
|
|
echo "test_application_getWithRating() passed\n";
|
2007-03-31 17:12:55 +00:00
|
|
|
}
|
2006-09-27 02:44:16 +00:00
|
|
|
|
2006-09-26 02:05:55 +00:00
|
|
|
?>
|
|
|
|
|
|