Authors: "EA Durbin" <ead1234@hotmail.com>, Chris Morgan <cmorgan@alum.wpi.edu>
Application::delete() should retrieve the applications versions immediately prior to deleting to ensure that an application object created prior to its child versions doesn't leave orphaned versions. Add unit test for Application::delete() to test for the offending behavior.
This commit is contained in:
@@ -9,7 +9,6 @@ require_once(BASE."include/category.php");
|
|||||||
require_once(BASE."include/url.php");
|
require_once(BASE."include/url.php");
|
||||||
require_once(BASE."include/util.php");
|
require_once(BASE."include/util.php");
|
||||||
require_once(BASE."include/mail.php");
|
require_once(BASE."include/mail.php");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Application class for handling applications.
|
* Application class for handling applications.
|
||||||
*/
|
*/
|
||||||
@@ -62,15 +61,12 @@ class Application {
|
|||||||
//FIXME: it would be nice to move this permission into the user class as well as keep it generic
|
//FIXME: it would be nice to move this permission into the user class as well as keep it generic
|
||||||
if($_SESSION['current']->hasPriv("admin"))
|
if($_SESSION['current']->hasPriv("admin"))
|
||||||
{
|
{
|
||||||
$sQuery = "SELECT versionId FROM appVersion WHERE
|
$hResult = $this->_internal_retrieve_all_versions();
|
||||||
appId = '?'";
|
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
$sQuery = "SELECT versionId FROM appVersion WHERE
|
$hResult = $this->_internal_retrieve_unqueued_versions();
|
||||||
queued = 'false' AND
|
|
||||||
appId = '?'";
|
|
||||||
}
|
}
|
||||||
if($hResult = query_parameters($sQuery, $this->iAppId))
|
if($hResult)
|
||||||
{
|
{
|
||||||
while($oRow = mysql_fetch_object($hResult))
|
while($oRow = mysql_fetch_object($hResult))
|
||||||
{
|
{
|
||||||
@@ -80,6 +76,22 @@ class Application {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _internal_retrieve_all_versions()
|
||||||
|
{
|
||||||
|
$sQuery = "SELECT versionId FROM appVersion WHERE
|
||||||
|
appId = '?'";
|
||||||
|
$hResult = query_parameters($sQuery, $this->iAppId);
|
||||||
|
return $hResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
function _internal_retrieve_unqueued_versions()
|
||||||
|
{
|
||||||
|
$sQuery = "SELECT versionId FROM appVersion WHERE
|
||||||
|
queued = 'false' AND
|
||||||
|
appId = '?'";
|
||||||
|
$hResult = query_parameters($sQuery, $this->iAppId);
|
||||||
|
return $hResult;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new application.
|
* Creates a new application.
|
||||||
@@ -196,8 +208,15 @@ class Application {
|
|||||||
if(!$_SESSION['current']->canDeleteApplication($this))
|
if(!$_SESSION['current']->canDeleteApplication($this))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
foreach($this->aVersionsIds as $iVersionId)
|
/* we have to retrieve the versions again here because */
|
||||||
|
/* new ones could have been added since this application */
|
||||||
|
/* object was created */
|
||||||
|
//FIXME: how to deal with concurrency issues such as
|
||||||
|
// if a new version was added during this deletion?
|
||||||
|
$hResult = $this->_internal_retrieve_all_versions();
|
||||||
|
while($oRow = mysql_fetch_object($hResult))
|
||||||
{
|
{
|
||||||
|
$iVersionId = $oRow->versionId;
|
||||||
$oVersion = new Version($iVersionId);
|
$oVersion = new Version($iVersionId);
|
||||||
$oVersion->delete($bSilent);
|
$oVersion->delete($bSilent);
|
||||||
}
|
}
|
||||||
@@ -339,7 +358,6 @@ class Application {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function SendNotificationMail($sAction="add",$sMsg=null)
|
function SendNotificationMail($sAction="add",$sMsg=null)
|
||||||
{
|
{
|
||||||
$aClean = array(); //array of filtered user input
|
$aClean = array(); //array of filtered user input
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ include_once("test_query.php");
|
|||||||
echo "\n";
|
echo "\n";
|
||||||
include_once("test_image.php");
|
include_once("test_image.php");
|
||||||
echo "\n";
|
echo "\n";
|
||||||
|
include_once("test_application.php");
|
||||||
|
echo "\n";
|
||||||
include_once("test_error_log.php");
|
include_once("test_error_log.php");
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
122
unit_test/test_application.php
Normal file
122
unit_test/test_application.php
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
<?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');
|
||||||
|
|
||||||
|
$test_email = "testemail@somesite.com";
|
||||||
|
$test_password = "password";
|
||||||
|
|
||||||
|
/* test that Application::delete() properly deletes data dependent on */
|
||||||
|
/* 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__);
|
||||||
|
|
||||||
|
global $test_email, $test_password;
|
||||||
|
|
||||||
|
$oUser = new User();
|
||||||
|
|
||||||
|
/* delete the user if they already exist */
|
||||||
|
if($oUser->login($test_email, $test_password) == SUCCESS)
|
||||||
|
{
|
||||||
|
$oUser->delete();
|
||||||
|
$oUser = new User();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* create the user */
|
||||||
|
$retval = $oUser->create("testemail@somesite.com", "password", "Test user", "20051020");
|
||||||
|
if($retval != SUCCESS)
|
||||||
|
{
|
||||||
|
if($retval == USER_CREATE_EXISTS)
|
||||||
|
echo "The user already exists!\n";
|
||||||
|
else if($retval == USER_LOGIN_FAILED)
|
||||||
|
echo "User login failed!\n";
|
||||||
|
else
|
||||||
|
echo "ERROR: UNKNOWN ERROR!!\n";
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* login the 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");
|
||||||
|
|
||||||
|
$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 */
|
||||||
|
echo "Failed to create application!\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$iAppId = $oApp->iAppId; /* use the iAppId of the application we just created */
|
||||||
|
|
||||||
|
$iVersionIdBase = 400000;
|
||||||
|
for($iVersionIdIndex = 0; $iVersionIdIndex < 10; $iVersionIdIndex++)
|
||||||
|
{
|
||||||
|
$iVersionId = $iVersionIdBase + $iVersionIdIndex;
|
||||||
|
|
||||||
|
$oVersion = new Version();
|
||||||
|
$oVersion->versionName = "Some Version".$iVersionId;
|
||||||
|
$oVersion->description = "Some Version description".$iVersionId;
|
||||||
|
$oVersion->iAppId = $oApp->iAppId;
|
||||||
|
$oVersion->iVersionId = $iVersionId;
|
||||||
|
|
||||||
|
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))
|
||||||
|
{
|
||||||
|
$iRows = mysql_num_rows($hResult);
|
||||||
|
if($iRows > 0)
|
||||||
|
{
|
||||||
|
echo "Found '".$iRows."' versions for this application left over!";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function delete_app_and_user($oApp, $oUser)
|
||||||
|
{
|
||||||
|
$oApp->delete();
|
||||||
|
$oUser->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!test_application_delete())
|
||||||
|
echo "test_application_delete() failed!\n";
|
||||||
|
else
|
||||||
|
echo "test_application_delete() passed!\n";
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
Reference in New Issue
Block a user