Unit test cleanups. Fixes tests so they don't leave left over entries in the database. Add a

check to ensure that row counts in most tables are unchanged from the start and end of the
tests. Refactor some code.
This commit is contained in:
Chris Morgan
2007-07-26 03:47:34 +00:00
committed by WineHQ
parent 0b979fee68
commit 19f6cbc156
16 changed files with 505 additions and 244 deletions

View File

@@ -165,7 +165,7 @@ function cmd_send_passwd()
$oUser = new User($iUserId); $oUser = new User($iUserId);
if ($iUserId) if ($iUserId)
{ {
if ($oUser->update_password($sPasswd)) if ($oUser->update_password($sPasswd))
{ {
$sSubject = "Application DB Lost Password"; $sSubject = "Application DB Lost Password";
$sMsg = "We have received a request that you lost your password.\r\n"; $sMsg = "We have received a request that you lost your password.\r\n";

View File

@@ -231,6 +231,8 @@ class Application {
*/ */
function delete($bSilent=false) function delete($bSilent=false)
{ {
$bSuccess = true;
/* make sure the current user has the appropriate permission to delete /* make sure the current user has the appropriate permission to delete
this application */ this application */
if(!$_SESSION['current']->canDeleteApplication($this)) if(!$_SESSION['current']->canDeleteApplication($this))
@@ -246,10 +248,10 @@ class Application {
{ {
$iVersionId = $oRow->versionId; $iVersionId = $oRow->versionId;
$oVersion = new Version($iVersionId); $oVersion = new Version($iVersionId);
$oVersion->delete($bSilent); if(!$oVersion->delete($bSilent))
$bSuccess = false; // return false, deleting the version failed
} }
/* fetch urlsIds */ /* fetch urlsIds */
$aUrlsIds = array(); $aUrlsIds = array();
$sQuery = "SELECT id $sQuery = "SELECT id
@@ -289,7 +291,7 @@ class Application {
if(!$bSilent) if(!$bSilent)
$this->SendNotificationMail("delete"); $this->SendNotificationMail("delete");
return true; return $bSuccess;
} }

View File

@@ -229,10 +229,9 @@ class downloadurl
function canEdit($iVersionId = NULL) function canEdit($iVersionId = NULL)
{ {
$oUser = new User($_SESSION['current']->iUserId); if($_SESSION['current']->hasPriv("admin") ||
($iVersionId &&
if($oUser->hasPriv("admin") || ($iVersionId && maintainer::isUserMaintainer($_SESSION['current'], $iVersionId)))
maintainer::isUserMaintainer($oUser, $iVersionId)))
{ {
return TRUE; return TRUE;
} else } else

View File

@@ -128,6 +128,8 @@ class screenshot
/** /**
* Deletes the screenshot from the database. * Deletes the screenshot from the database.
* and request its deletion from the filesystem (including the thumbnail). * and request its deletion from the filesystem (including the thumbnail).
*
* Returns: true if deletion was success, false if otherwise
*/ */
function delete($bSilent=false) function delete($bSilent=false)
{ {
@@ -155,6 +157,8 @@ class screenshot
{ {
$this->mailSubmitter(true); $this->mailSubmitter(true);
} }
return true;
} }
function reject() function reject()

View File

@@ -5,6 +5,9 @@
/* TODO: test the rest of the classes we have */ /* TODO: test the rest of the classes we have */
require_once("path.php");
require_once(BASE.'include/incl.php');
error_reporting(E_ALL); error_reporting(E_ALL);
// disable emailing // disable emailing
@@ -14,6 +17,11 @@ if(!defined("DISABLE_EMAIL"))
// default to the tests being successful // default to the tests being successful
$bTestSuccess = true; $bTestSuccess = true;
// retrieve counts of each of the tables so we can check again
// at the end of the
$oStartingTableCounts = new table_counts();
include_once("test_user.php"); include_once("test_user.php");
echo "\n"; echo "\n";
@@ -35,6 +43,23 @@ include_once("test_appData.php");
echo "\n"; echo "\n";
include_once("test_testData.php"); include_once("test_testData.php");
// retrieve counts of each of the tables after our tests
$oEndingTableCounts = new table_counts();
// see if our table counts match
if(!$oEndingTableCounts->IsEqual($oStartingTableCounts))
{
$bTestSuccess = false;
echo "\n\nStarting and ending table counts do not match\n";
$oStartingTableCounts->OutputSideBySide($oEndingTableCounts,
"Starting",
"Ending");
} else
{
echo "\n\nTable counts match from the start and end of the test suite.\n";
}
if($bTestSuccess == true) if($bTestSuccess == true)
{ {
echo "\nAll tests were successful\n"; echo "\nAll tests were successful\n";
@@ -42,4 +67,107 @@ if($bTestSuccess == true)
{ {
echo "\nSome test(s) failed!\n"; echo "\nSome test(s) failed!\n";
} }
// keep track of the counts of various tables
class table_counts
{
// the tables we should count, set in the constructor
var $aTablesToCount;
// the counts of the tables
var $aTableCounts;
function table_counts()
{
$this->aTablesToCount = array('appBundle',
'appCategory',
'appComments',
'appData',
'appFamily',
'appMaintainers',
'appMonitors',
'appNotes',
'appVersion',
'appVotes',
'buglinks',
'distributions',
'prefs_list',
'testResults',
'user_list',
'user_privs',
'vendor');
$this->update_counts();
}
// update the count for each table
function update_counts()
{
$this->aTableCounts = array();
foreach($this->aTablesToCount as $sTable)
{
$sQuery = "select count(*) as cnt from ?;";
$hResult = query_parameters($sQuery, $sTable);
$oRow = mysql_fetch_object($hResult);
$this->aTableCounts[] = $oRow->cnt;
}
}
// returns 'true' if equal, 'false' if not
function IsEqual($oTableCounts)
{
$iIndex = 0;
for($iIndex = 0; $iIndex < count($this->aTableCounts); $iIndex++)
{
if($this->aTableCounts[$iIndex] != $oTableCounts->aTableCounts[$iIndex])
{
return false;
}
}
return true;
}
function OutputSideBySide($oTableCounts, $sFirstTableCountName,
$sSecondTableCountName)
{
$iIndex = 0;
// output the header
printf("%20s%20s%20s\n",
"Table name",
$sFirstTableCountName,
$sSecondTableCountName);
for($iIndex = 0; $iIndex < count($this->aTableCounts); $iIndex++)
{
printf("%20s%20s%20s",
$this->aTablesToCount[$iIndex],
$this->aTableCounts[$iIndex],
$oTableCounts->aTableCounts[$iIndex]);
if($this->aTableCounts[$iIndex] != $oTableCounts->aTableCounts[$iIndex])
{
echo " <-- Mismatch";
}
echo "\n";
}
}
function output()
{
$iIndex = 0;
for($iIndex = 0; $iIndex < count($this->aTableCounts); $iIndex++)
{
$sTableName = $this->aTablesToCount[$iIndex];
$iTableCount = $this->aTableCounts[$iIndex];
echo "$sTableName count of $iTableCount\n";
}
}
}
?> ?>

View File

@@ -7,12 +7,15 @@ require_once(BASE."include/downloadurl.php");
function test_appData_listSubmittedBy() function test_appData_listSubmittedBy()
{ {
$bSuccess = true;
test_start(__FUNCTION__); test_start(__FUNCTION__);
global $test_email, $test_password; $sTestEmail = __FUNCTION__."@localhost.com";
if(!$oUser = create_and_login_user()) $sTestPassword = "password";
if(!$oUser = create_and_login_user($sTestEmail, $sTestPassword))
{ {
echo "Failed to create and log in user\n"; error("Failed to create and log in user");
return FALSE; return FALSE;
} }
@@ -35,17 +38,20 @@ function test_appData_listSubmittedBy()
$iReceived = substr_count($shReturn, "</tr>"); $iReceived = substr_count($shReturn, "</tr>");
if($iExpected != $iReceived) if($iExpected != $iReceived)
{ {
echo "Got $iReceived rows instead of $iExpected.\n"; error("Got $iReceived rows instead of $iExpected.");
$oDownloadUrl->delete(); $bSuccess = false;
$oUser->delete();
return FALSE;
} }
/* Clean up */ /* Clean up */
$oDownloadUrl->delete(); if(!$oDownloadUrl->delete())
{
$bSuccess = false;
error("Failed to delete oDownloadUrl!");
}
$oUser->delete(); $oUser->delete();
return TRUE; return $bSuccess;
} }
if(!test_appData_listSubmittedBy()) if(!test_appData_listSubmittedBy())

View File

@@ -5,9 +5,7 @@ require_once(BASE.'include/maintainer.php');
require_once(BASE.'include/user.php'); require_once(BASE.'include/user.php');
require_once(BASE.'include/version.php'); require_once(BASE.'include/version.php');
require_once(BASE.'include/application.php'); require_once(BASE.'include/application.php');
require_once("test_common.php");
$test_email = "testemail@somesite.com";
$test_password = "password";
/* test that Application::delete() properly deletes data dependent on */ /* test that Application::delete() properly deletes data dependent on */
/* having an application */ /* having an application */
@@ -17,7 +15,10 @@ function test_application_delete()
{ {
test_start(__FUNCTION__); test_start(__FUNCTION__);
if(!$oUser = create_and_login_user()) $sTestEmail = "test_application_delete@somesite.com";
$sTestPassword = "password";
if(!$oUser = create_and_login_user($sTestEmail, $sTestPassword))
return false; return false;
/* make this user an admin so we can create applications without having them queued */ /* make this user an admin so we can create applications without having them queued */
@@ -31,7 +32,7 @@ function test_application_delete()
if(!$oApp->create()) if(!$oApp->create())
{ {
$oUser->delete(); /* clean up the user we created prior to exiting */ $oUser->delete(); /* clean up the user we created prior to exiting */
echo "Failed to create application!\n"; error("Failed to create application!");
return false; return false;
} }
@@ -78,7 +79,10 @@ function test_application_getWithRating()
{ {
test_start(__FUNCTION__); test_start(__FUNCTION__);
if(!$oUser = create_and_login_user()) $sTestEmail = "test_application_getwithrating@somesite.com";
$sTestPassword = "password";
if(!$oUser = create_and_login_user($sTestEmail, $sTestPassword))
return false; return false;
/* make this user an admin so we can create applications without having them queued */ /* make this user an admin so we can create applications without having them queued */
@@ -92,7 +96,7 @@ function test_application_getWithRating()
if(!$oApp->create()) if(!$oApp->create())
{ {
$oUser->delete(); $oUser->delete();
echo "Failed to create application!\n"; error("Failed to create application!");
return false; return false;
} }
@@ -126,7 +130,7 @@ function test_application_getWithRating()
if(!$oVersion->create()) if(!$oVersion->create())
{ {
delete_app_and_user($oApp, $oUser); delete_app_and_user($oApp, $oUser);
echo "Failed to create version!\n"; error("Failed to create version!");
return false; return false;
} }
} }
@@ -142,7 +146,7 @@ function test_application_getWithRating()
if ( in_array($iId, $aTest) ) //if the appId is already in our test results fail unique test if ( in_array($iId, $aTest) ) //if the appId is already in our test results fail unique test
{ {
delete_app_and_user($oApp, $oUser); delete_app_and_user($oApp, $oUser);
echo "getWithRating failed to return a unique result set\n"; error("getWithRating failed to return a unique result set");
return false; return false;
} }
@@ -156,8 +160,9 @@ function test_application_getWithRating()
//test to ensure getWithRating doesn't return applications that are queued //test to ensure getWithRating doesn't return applications that are queued
if(!$oUser = create_and_login_user()) //create user without admin priveliges //create user without admin priveliges
return false; if(!$oUser = create_and_login_user($sTestEmail, $sTestPassword))
return false;
$oApp = new Application(); $oApp = new Application();
@@ -167,7 +172,7 @@ function test_application_getWithRating()
if(!$oApp->create()) if(!$oApp->create())
{ {
$oUser->delete(); /* clean up the user we created prior to exiting */ $oUser->delete(); /* clean up the user we created prior to exiting */
echo "Failed to create application!\n"; error("Failed to create application!");
return false; return false;
} }
@@ -183,7 +188,7 @@ function test_application_getWithRating()
if(!$oVersion->create()) if(!$oVersion->create())
{ {
delete_app_and_user($oApp, $oUser); delete_app_and_user($oApp, $oUser);
echo "Failed to create version!\n"; error("Failed to create version!");
return false; return false;
} }
@@ -193,7 +198,7 @@ function test_application_getWithRating()
if ( in_array($iAppId, $aApps )) //if the appId is in our test results fail queued test if ( in_array($iAppId, $aApps )) //if the appId is in our test results fail queued test
{ {
delete_app_and_user($oApp, $oUser); delete_app_and_user($oApp, $oUser);
echo "getWithRating failed to return a unique result set\n"; error("getWithRating failed to return a unique result set");
return false; return false;
} }
@@ -202,50 +207,22 @@ function test_application_getWithRating()
return true; return true;
} }
function delete_app_and_user($oApp, $oUser) function delete_app_and_user($oApp, $oUser)
{ {
$oApp->delete(); $bSuccess = true;
$oUser->delete(); if(!$oApp->delete())
}
function create_and_login_user()
{
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(); echo __FUNCTION__."() oApp->delete() failed\n";
$oUser = new User(); $bSuccess = false;
} }
/* create the user */ if(!$oUser->delete())
$retval = $oUser->create("$test_email", "$test_password", "Test user", "20051020");
if($retval != SUCCESS)
{ {
if($retval == USER_CREATE_EXISTS) echo __FUNCTION__."() oUser->delete() failed\n";
echo "The user already exists!\n"; $bSuccess = false;
else if($retval == USER_LOGIN_FAILED)
echo "User login failed!\n";
else
echo "ERROR: UNKNOWN ERROR!!\n";
return false;
} }
/* login the user */ return $bSuccess;
$retval = $oUser->login($test_email, $test_password);
if($retval != SUCCESS)
{
echo "Got '".$retval."' instead of SUCCESS(".SUCCESS.")\n";
return false;
}
return $oUser;
} }
if(!test_application_delete()) if(!test_application_delete())

View File

@@ -9,13 +9,13 @@ function test_start($sFunctionName)
// create an application and a version of that application // create an application and a version of that application
// return the iVersionId of the created version // return the iVersionId of the created version
function create_version_and_parent_app() function create_version_and_parent_app($sId = "")
{ {
$oApp = new application(); $oApp = new application();
$oApp->sName = "OM App"; $oApp->sName = "OM App ".$sId;
$oApp->create(); $oApp->create();
$oVersion = new version(); $oVersion = new version();
$oVersion->sName = "OM version"; $oVersion->sName = "OM version ".$sId;
$oVersion->iAppId = $oApp->iAppId; $oVersion->iAppId = $oApp->iAppId;
$oVersion->create(); $oVersion->create();
return $oVersion->iVersionId; return $oVersion->iVersionId;
@@ -23,11 +23,80 @@ function create_version_and_parent_app()
// delete a version based on the $iVersionId parameter // delete a version based on the $iVersionId parameter
// and delete its parent application // and delete its parent application
// NOTE: we enable admin permissions here to ensure that
// the application and version are deleted
function delete_version_and_parent_app($iVersionId) function delete_version_and_parent_app($iVersionId)
{ {
$bWasAdmin = $_SESSION['current']->hasPriv("admin");
$_SESSION['current']->addPriv("admin");
$oVersion = new version($iVersionId); $oVersion = new version($iVersionId);
$oApp = new application($oVersion->iAppId); $oApp = new application($oVersion->iAppId);
$oApp->delete(); if(!$oApp->delete())
{
echo __FUNCTION__."() oApp->delete() failed, returned false!\n";
}
// remove the admin privleges only if the user didn't
// 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();
}
/* create the user */
$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;
}
/* login the user */
$retval = $oUser->login($sTestEmail, $sTestPassword);
if($retval != SUCCESS)
{
error("Got '".$retval."' instead of SUCCESS(".SUCCESS.")");
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";
} }
?> ?>

View File

@@ -26,7 +26,7 @@ function test_filter()
$sResult = filter_gpc(); $sResult = filter_gpc();
if(!$sResult) if(!$sResult)
{ {
echo "filter_gpc() succeeded when it should have failed due to invalid input!\n"; error("filter_gpc() succeeded when it should have failed due to invalid input!");
return false; return false;
} }
@@ -44,20 +44,20 @@ function test_filter()
$sResult = filter_gpc(); $sResult = filter_gpc();
if($sResult) if($sResult)
{ {
echo "sResult is '$sResult' but we expected success and no return value\n"; error("sResult is '$sResult' but we expected success and no return value");
return false; return false;
} }
// make sure the values match what we expect // make sure the values match what we expect
if($aClean['sString'] != $sString) if($aClean['sString'] != $sString)
{ {
echo "Expected aClean['sString'] to be '".$sString."' but instead it was '".$aClean['sString']."'\n"; error("Expected aClean['sString'] to be '".$sString."' but instead it was '".$aClean['sString']."'");
return false; return false;
} }
if($aClean['iInteger'] != $iInteger) if($aClean['iInteger'] != $iInteger)
{ {
echo "Expected aClean['iInteger'] to be '".$iInteger."' but instead it was '".$aClean['iInteger']."'\n"; error("Expected aClean['iInteger'] to be '".$iInteger."' but instead it was '".$aClean['iInteger']."'");
return false; return false;
} }
@@ -73,14 +73,14 @@ function test_filter()
$sResult = filter_gpc(); $sResult = filter_gpc();
if($sResult) if($sResult)
{ {
echo "sResult is '$sResult' but we expected success and no return value\n"; error("sResult is '$sResult' but we expected success and no return value");
return false; return false;
} }
// expect that the filtered value will be equal // expect that the filtered value will be equal
if($aClean['shHtml'] != $shHtml) if($aClean['shHtml'] != $shHtml)
{ {
echo "Expected aClean['shHtml'] to be '".$shHtml."' but instead it was '".$aClean['shHtml']."'\n"; error("Expected aClean['shHtml'] to be '".$shHtml."' but instead it was '".$aClean['shHtml']."'");
return false; return false;
} }
@@ -96,7 +96,7 @@ function test_filter()
$sResult = filter_gpc(); $sResult = filter_gpc();
if($sResult) if($sResult)
{ {
echo "sResult is '$sResult' but we expected success and no return value\n"; error("sResult is '$sResult' but we expected success and no return value");
return false; return false;
} }
@@ -104,18 +104,17 @@ function test_filter()
// shouldn't be equal unless something has failed // shouldn't be equal unless something has failed
if($aClean['sHtml'] == $sHtml) if($aClean['sHtml'] == $sHtml)
{ {
echo "Expected aClean['shHtml'] to be '".$sHtml."' but instead it was '".$aClean['sHtml']."'\n"; error("Expected aClean['shHtml'] to be '".$sHtml."' but instead it was '".$aClean['sHtml']."'");
return false; return false;
} }
// make sure all html has been stripped // make sure all html has been stripped
if(strip_tags($aClean['sHtml']) != $aClean['sHtml']) if(strip_tags($aClean['sHtml']) != $aClean['sHtml'])
{ {
echo "Expected all html to be stripped already but we were able to strip this '".$aClean['sHtml'] error("Expected all html to be stripped already but we were able to strip this '".$aClean['sHtml']
."' into '".strip_tags($aClean['sHtml'])."'\n"; ."' into '".strip_tags($aClean['sHtml'])."'");
return false; return false;
} }
return true; return true;
} }

View File

@@ -22,21 +22,21 @@ function test_image_constructor()
if(!$oImage->isLoaded()) if(!$oImage->isLoaded())
{ {
echo "Error, unable to load image filename of ".$sImageFilename."\n"; error("Error, unable to load image filename of ".$sImageFilename);
echo "Internal filename is: ".$oImage->sFile."\n"; error("Internal filename is: ".$oImage->sFile);
return false; return false;
} }
/* make sure the image size is correct */ /* make sure the image size is correct */
if($oImage->get_width() != TEST_IMAGE_WIDTH) if($oImage->get_width() != TEST_IMAGE_WIDTH)
{ {
echo "Expected width of ".TEST_IMAGE_WIDTH.", got ".$oImage->get_width()."\n"; error("Expected width of ".TEST_IMAGE_WIDTH.", got ".$oImage->get_width());
return false; return false;
} }
if($oImage->get_height() != TEST_IMAGE_HEIGHT) if($oImage->get_height() != TEST_IMAGE_HEIGHT)
{ {
echo "Expected width of ".TEST_IMAGE_HEIGHT.", got ".$oImage->get_height()."\n"; error("Expected width of ".TEST_IMAGE_HEIGHT.", got ".$oImage->get_height());
return false; return false;
} }
@@ -45,7 +45,7 @@ function test_image_constructor()
$oImage = new Image("somefilethatdoesntexist.png"); $oImage = new Image("somefilethatdoesntexist.png");
if($oImage->isLoaded()) if($oImage->isLoaded())
{ {
echo "Error, isLoaded() returned true for a image that doesn't exist, expected false!\n"; error("Error, isLoaded() returned true for a image that doesn't exist, expected false!");
return false; return false;
} }
@@ -63,8 +63,8 @@ function test_image_make_thumbnail()
if(!$oImage->isLoaded()) if(!$oImage->isLoaded())
{ {
echo "Error, unable to load image filename of ".$sImageFilename."\n"; error("Error, unable to load image filename of ".$sImageFilename);
echo "Internal filename is: ".$oImage->sFile."\n"; error("Internal filename is: ".$oImage->sFile);
return false; return false;
} }
@@ -79,16 +79,16 @@ function test_image_make_thumbnail()
$iActualWidth = $oImage->get_width(); $iActualWidth = $oImage->get_width();
if($iActualWidth != $iWidth) if($iActualWidth != $iWidth)
{ {
echo "Expected width of $iWidth, got ".$iActualWidth."\n"; error("Expected width of $iWidth, got ".$iActualWidth);
echo $oImage->get_debuglog(false); error($oImage->get_debuglog(false));
return false; return false;
} }
$iActualHeight = $oImage->get_height(); $iActualHeight = $oImage->get_height();
if($iActualHeight != $iHeight) if($iActualHeight != $iHeight)
{ {
echo "Expected height of $iHeight, got ".$iActualHeight."\n"; error("Expected height of $iHeight, got ".$iActualHeight);
echo $oImage->get_debuglog(false); error($oImage->get_debuglog(false));
return false; return false;
} }
@@ -106,8 +106,8 @@ function test_image_make_full()
if(!$oImage->isLoaded()) if(!$oImage->isLoaded())
{ {
echo "Error, unable to load image filename of ".$sImageFilename."\n"; error("Error, unable to load image filename of ".$sImageFilename);
echo "Internal filename is: ".$oImage->sFile."\n"; error("Internal filename is: ".$oImage->sFile);
return false; return false;
} }
@@ -123,16 +123,16 @@ function test_image_make_full()
$iActualWidth = $oImage->get_width(); $iActualWidth = $oImage->get_width();
if($iActualWidth != $iWidth) if($iActualWidth != $iWidth)
{ {
echo "Expected width of $iWidth, got ".$iActualWidth."\n"; error("Expected width of $iWidth, got ".$iActualWidth);
echo $oImage->get_debuglog(false); error($oImage->get_debuglog(false));
return false; return false;
} }
$iActualHeight = $oImage->get_height(); $iActualHeight = $oImage->get_height();
if($iActualHeight != $iHeight) if($iActualHeight != $iHeight)
{ {
echo "Expected height of $iHeight, got ".$iActualHeight."\n"; error("Expected height of $iHeight, got ".$iActualHeight);
echo $oImage->get_debuglog(false); error($oImage->get_debuglog(false));
return false; return false;
} }
@@ -150,15 +150,15 @@ function test_image_output_to_file()
if(!$oImage->isLoaded()) if(!$oImage->isLoaded())
{ {
echo "Error, unable to load image filename of ".$sImageFilename."\n"; error("Error, unable to load image filename of ".$sImageFilename);
echo "Internal filename is: ".$oImage->sFile."\n"; error("Internal filename is: ".$oImage->sFile);
return false; return false;
} }
/* write the file to disk */ /* write the file to disk */
if(!$oImage->output_to_file(TEST_IMAGE_OUTPUT_FILENAME)) if(!$oImage->output_to_file(TEST_IMAGE_OUTPUT_FILENAME))
{ {
echo "image::output_to_file failed to output to filename of ".TEST_IMAGE_OUTPUT_FILENAME."\n"; error("image::output_to_file failed to output to filename of ".TEST_IMAGE_OUTPUT_FILENAME);
return false; return false;
} }
@@ -166,8 +166,8 @@ function test_image_output_to_file()
$oImage2 = new Image(TEST_IMAGE_OUTPUT_FILENAME, true); $oImage2 = new Image(TEST_IMAGE_OUTPUT_FILENAME, true);
if(!$oImage2->isLoaded()) if(!$oImage2->isLoaded())
{ {
echo "Error, unable to load newly output image filename of ".TEST_IMAGE_OUTPUT_FILENAME."\n"; error("Error, unable to load newly output image filename of ".TEST_IMAGE_OUTPUT_FILENAME);
echo "Internal filename is: ".$oImage2->sFile."\n"; error("Internal filename is: ".$oImage2->sFile);
return false; return false;
} }
@@ -178,9 +178,9 @@ function test_image_output_to_file()
$oImage2 = new Image(TEST_IMAGE_OUTPUT_FILENAME, true); $oImage2 = new Image(TEST_IMAGE_OUTPUT_FILENAME, true);
if($oImage2->isLoaded()) if($oImage2->isLoaded())
{ {
echo "Error, unlinking filename of ".TEST_IMAGE_OUTPUT_FILENAME." failed, we are able to\n"; error("Error, unlinking filename of ".TEST_IMAGE_OUTPUT_FILENAME." failed, we are able to");
echo " open up a file that should have been deleted.\n"; error(" open up a file that should have been deleted.");
echo "Internal filename is: ".$oImage2->sFile."\n"; error("Internal filename is: ".$oImage2->sFile);
return false; return false;
} }
@@ -198,8 +198,8 @@ function test_image_add_watermark()
if(!$oImage->isLoaded()) if(!$oImage->isLoaded())
{ {
echo "Error, unable to load image filename of ".$sImageFilename."\n"; error("Error, unable to load image filename of ".$sImageFilename);
echo "Internal filename is: ".$oImage->sFile."\n"; error("Internal filename is: ".$oImage->sFile);
return false; return false;
} }
@@ -207,8 +207,8 @@ function test_image_add_watermark()
$oWatermark = new Image(TEST_IMAGE_WATERMARK); $oWatermark = new Image(TEST_IMAGE_WATERMARK);
if(!$oWatermark->isLoaded()) if(!$oWatermark->isLoaded())
{ {
echo "Error, unable to load image filename of ".TEST_IMAGE_WATERMARK."\n"; error("Error, unable to load image filename of ".TEST_IMAGE_WATERMARK);
echo "Internal filename is: ".$oWatermark->sFile."\n"; error("Internal filename is: ".$oWatermark->sFile);
return false; return false;
} }

View File

@@ -18,15 +18,12 @@ function test_maintainer_getMaintainerCountForUser()
{ {
test_start(__FUNCTION__); test_start(__FUNCTION__);
global $test_email, $test_password; $sTestEmail = __FUNCTION__."@localhost.com";
$sTestPassword = "password";
/* login the user */ if(!($oUser = create_and_login_user($sTestEmail, $sTestPassword)))
$oUser = new User();
$retval = $oUser->login($test_email, $test_password);
if($retval != SUCCESS)
{ {
echo "Got '".$retval."' instead of SUCCESS(".SUCCESS.")\n"; error("Failed to create and log in user!");
return false; return FALSE;
} }
/** /**
@@ -52,7 +49,8 @@ function test_maintainer_getMaintainerCountForUser()
$iSuperMaintainerCount = Maintainer::getMaintainerCountForUser($oUser, TRUE); $iSuperMaintainerCount = Maintainer::getMaintainerCountForUser($oUser, TRUE);
if($iSuperMaintainerCount != $iExpected) if($iSuperMaintainerCount != $iExpected)
{ {
echo "Got super maintainer count of '".$iSuperMaintainerCount."' instead of '".$iExpected."'\n"; error("Got super maintainer count of '".$iSuperMaintainerCount."' instead of '".$iExpected."'");
$oUser->delete();
return false; return false;
} }
@@ -61,7 +59,8 @@ function test_maintainer_getMaintainerCountForUser()
$iMaintainerCount = Maintainer::getMaintainerCountForUser($oUser, FALSE); $iMaintainerCount = Maintainer::getMaintainerCountForUser($oUser, FALSE);
if($iMaintainerCount != $iExpected) if($iMaintainerCount != $iExpected)
{ {
echo "Got maintainer count of '".$iMaintainerCount."' instead of '".$iExpected."'\n"; error("Got maintainer count of '".$iMaintainerCount."' instead of '".$iExpected."'");
$oUser->delete();
return false; return false;
} }
@@ -89,7 +88,8 @@ function test_maintainer_getMaintainerCountForUser()
$iSuperMaintainerCount = Maintainer::getMaintainerCountForUser($oUser, TRUE); $iSuperMaintainerCount = Maintainer::getMaintainerCountForUser($oUser, TRUE);
if($iSuperMaintainerCount != $iExpected) if($iSuperMaintainerCount != $iExpected)
{ {
echo "Got super maintainer count of '".$iSuperMaintainerCount."' instead of '".$iExpected."'\n"; error("Got super maintainer count of '".$iSuperMaintainerCount."' instead of '".$iExpected."'");
$oUser->delete();
return false; return false;
} }
@@ -98,13 +98,15 @@ function test_maintainer_getMaintainerCountForUser()
$iMaintainerCount = Maintainer::getMaintainerCountForUser($oUser, FALSE); $iMaintainerCount = Maintainer::getMaintainerCountForUser($oUser, FALSE);
if($iMaintainerCount != $iExpected) if($iMaintainerCount != $iExpected)
{ {
echo "Got maintainer count of '".$iMaintainerCount."' instead of '".$iExpected."'\n"; error("Got maintainer count of '".$iMaintainerCount."' instead of '".$iExpected."'");
$oUser->delete();
return false; return false;
} }
/* remove maintainership for this user */ /* remove maintainership for this user */
Maintainer::deleteMaintainer($oUser, $iAppId, $iVersionId); Maintainer::deleteMaintainer($oUser, $iAppId, $iVersionId);
$oUser->delete();
return true; return true;
} }
@@ -114,15 +116,12 @@ function test_maintainer_getAppsMaintained()
{ {
test_start(__FUNCTION__); test_start(__FUNCTION__);
global $test_email, $test_password; $sTestEmail = __FUNCTION__."@localhost.com";
$sTestPassword = "password";
/* login the user */ if(!($oUser = create_and_login_user($sTestEmail, $sTestPassword)))
$oUser = new User();
$retval = $oUser->login($test_email, $test_password);
if($retval != SUCCESS)
{ {
echo "Got '".$retval."' instead of SUCCESS(".SUCCESS.")\n"; error("Failed to create and log in user!");
return false; return FALSE;
} }
/* make this user an admin so we can create applications without having them queued */ /* make this user an admin so we can create applications without having them queued */
@@ -136,7 +135,8 @@ function test_maintainer_getAppsMaintained()
$oApp->submitterId = $oUser->iUserId; $oApp->submitterId = $oUser->iUserId;
if(!$oApp->create()) if(!$oApp->create())
{ {
echo "Failed to create application!\n"; error("Failed to create application!");
$oUser->delete();
return false; return false;
} }
@@ -164,7 +164,8 @@ function test_maintainer_getAppsMaintained()
if(!$aAppsMaintained) if(!$aAppsMaintained)
{ {
echo "aAppsMaintained is null, we expected a non-null return value!\n"; error("aAppsMaintained is null, we expected a non-null return value!");
$oUser->delete();
return false; return false;
} }
@@ -175,19 +176,22 @@ function test_maintainer_getAppsMaintained()
/* make sure all parameters match what we added as maintainer information */ /* make sure all parameters match what we added as maintainer information */
if($iAppId1 != $iAppId) if($iAppId1 != $iAppId)
{ {
echo "Expected iAppid of ".$iAppId." but got ".$iAppId1."\n"; error("Expected iAppid of ".$iAppId." but got ".$iAppId1);
$oUser->delete();
return false; return false;
} }
if($iVersionId1 != $iVersionId) if($iVersionId1 != $iVersionId)
{ {
echo "Expected iVersionId of ".$iVersionId." but got ".$iVersionId1."\n"; error("Expected iVersionId of ".$iVersionId." but got ".$iVersionId1);
$oUser->delete();
return false; return false;
} }
if($bSuperMaintainer1 != $bSuperMaintainer) if($bSuperMaintainer1 != $bSuperMaintainer)
{ {
echo "Expected bSuperMaintainer of ".$bSuperMaintainer." but got ".$bSuperMaintainer1."\n"; error("Expected bSuperMaintainer of ".$bSuperMaintainer." but got ".$bSuperMaintainer1);
$oUser->delete();
return false; return false;
} }
@@ -198,6 +202,8 @@ function test_maintainer_getAppsMaintained()
$oApp = new Application($iAppId); $oApp = new Application($iAppId);
$oApp->delete(); $oApp->delete();
$oUser->delete();
return true; return true;
} }
@@ -206,17 +212,31 @@ function test_maintainer_unQueue()
{ {
test_start(__FUNCTION__); test_start(__FUNCTION__);
global $test_email, $test_password; $sTestEmail = __FUNCTION__."@localhost.com";
$sTestPassword = "password";
/* login the user */ if(!($oFirstUser = create_and_login_user($sTestEmail, $sTestPassword)))
$oFirstUser = new User();
$retval = $oFirstUser->login($test_email, $test_password);
if($retval != SUCCESS)
{ {
echo "Got '".$retval."' instead of SUCCESS(".SUCCESS.")\n"; error("Failed to create and log in first user!");
return false; return FALSE;
} }
// create a second user
$sTestEmail = __FUNCTION__."2nd@localhost.com";
$sTestPassword = "password";
if(!($oSecondUser = create_and_login_user($sTestEmail, $sTestPassword)))
{
error("Failed to create and log in second user!");
$oFirstUser->delete();
return FALSE;
}
// make the first user the current user
// because create_and_login_user() calls user::login()
// and this sets $_SESSION['current'] so we need
// to override the create_and_login_user() for the second user
$_SESSION['current'] = $oFirstUser;
$iAppId = 655000; $iAppId = 655000;
$iVersionId = 655200; $iVersionId = 655200;
@@ -224,8 +244,7 @@ function test_maintainer_unQueue()
$oVersion = new Version(); $oVersion = new Version();
$oApp->iAppId = $iAppId; $oApp->iAppId = $iAppId;
$oVersion->iVersionId = $iVersionId; $oVersion->iVersionId = $iVersionId;
$oSecondUser = new User();
$oSecondUser->iUserId = $_SESSION['current']->iUserId + 1;
/* Create a non-super maintainer for a different userId; it should not be affected /* Create a non-super maintainer for a different userId; it should not be affected
by the other user first becoming a maintainer and then a super maintainer of by the other user first becoming a maintainer and then a super maintainer of
the same application */ the same application */
@@ -235,7 +254,10 @@ function test_maintainer_unQueue()
$oSecondUserMaintainer->iUserId = $oSecondUser->iUserId; $oSecondUserMaintainer->iUserId = $oSecondUser->iUserId;
$oSecondUserMaintainer->sMaintainReason = "I need it"; $oSecondUserMaintainer->sMaintainReason = "I need it";
$oSecondUserMaintainer->bSuperMaintainer = FALSE; $oSecondUserMaintainer->bSuperMaintainer = FALSE;
$oSecondUserMaintainer->create(); if(!$oSecondUserMaintainer->create())
error("oSecondUserMaintainer->create() failed");
$oSecondUserMaintainer->unQueue();
/* Create a super maintainer for a different userId; it should not be affected /* Create a super maintainer for a different userId; it should not be affected
by the other user first becoming a maintainer and then a super maintainer of by the other user first becoming a maintainer and then a super maintainer of
@@ -247,10 +269,14 @@ function test_maintainer_unQueue()
$oSecondUserSuperMaintainer->sMaintainReason = "I need it"; $oSecondUserSuperMaintainer->sMaintainReason = "I need it";
$oSecondUserSuperMaintainer->bSuperMaintainer = TRUE; $oSecondUserSuperMaintainer->bSuperMaintainer = TRUE;
// disable admin permissions around the creation of the second maintainer
// so the maintainer object remains queued
$oFirstUser->delPriv("admin"); $oFirstUser->delPriv("admin");
$oSecondUserSuperMaintainer->create(); if(!$oSecondUserSuperMaintainer->create())
error("oSecondUserSuperMaintainer->create() failed");
$oFirstUser->addPriv("admin"); $oFirstUser->addPriv("admin");
/* Create a non-super maintainer /* Create a non-super maintainer
It should be removed later because a super maintainer entry for the same It should be removed later because a super maintainer entry for the same
application is added */ application is added */
@@ -260,18 +286,22 @@ function test_maintainer_unQueue()
$oFirstUserMaintainer->iUserId = $_SESSION['current']->iUserId; $oFirstUserMaintainer->iUserId = $_SESSION['current']->iUserId;
$oFirstUserMaintainer->sMaintainReason = "The most stupid reason"; $oFirstUserMaintainer->sMaintainReason = "The most stupid reason";
$oFirstUserMaintainer->bSuperMaintainer = FALSE; $oFirstUserMaintainer->bSuperMaintainer = FALSE;
$oFirstUserMaintainer->create(); if(!$oFirstUserMaintainer->create())
error("oFirstUserMaintainer->create() failed");
$oFirstUserMaintainer->unQueue(""); $sStatus = $oFirstUserMaintainer->unQueue("");
/* There should now be 1 maintainer and 0 super maintainers */ /* There should now be 1 maintainer and 0 super maintainers */
$iExpected = 1; $iExpected = 1;
$iReceived = maintainer::getMaintainerCountForUser($oFirstUser, FALSE); $iReceived = maintainer::getMaintainerCountForUser($oFirstUser, FALSE);
if($iExpected != $iReceived) if($iExpected != $iReceived)
{ {
echo "Got maintainer count of $iReceived instead of $iExpected\n"; error("Got maintainer count of $iReceived instead of $iExpected");
error("sStatus is $sStatus");
maintainer::deleteMaintainersForApplication($oApp); maintainer::deleteMaintainersForApplication($oApp);
maintainer::deleteMaintainersForVersion($oVersion); maintainer::deleteMaintainersForVersion($oVersion);
$oFirstUser->delete();
$oSecondUser->delete();
return FALSE; return FALSE;
} }
@@ -279,9 +309,11 @@ function test_maintainer_unQueue()
$iReceived = maintainer::getMaintainerCountForUser($oFirstUser, TRUE); $iReceived = maintainer::getMaintainerCountForUser($oFirstUser, TRUE);
if($iExpected != $iReceived) if($iExpected != $iReceived)
{ {
echo "Got super maintainer count of $iReceived instead of $iExpected\n"; error("Got super maintainer count of $iReceived instead of $iExpected");
maintainer::deleteMaintainersForApplication($oApp); maintainer::deleteMaintainersForApplication($oApp);
maintainer::deleteMaintainersForVersion($oVersion); maintainer::deleteMaintainersForVersion($oVersion);
$oFirstUser->delete();
$oSecondUser->delete();
return FALSE; return FALSE;
} }
@@ -295,7 +327,8 @@ function test_maintainer_unQueue()
$oFirstUserSuperMaintainer->iUserId = $_SESSION['current']->iUserId; $oFirstUserSuperMaintainer->iUserId = $_SESSION['current']->iUserId;
$oFirstUserSuperMaintainer->sMaintainReason = "Some crazy reason"; $oFirstUserSuperMaintainer->sMaintainReason = "Some crazy reason";
$oFirstUserSuperMaintainer->bSuperMaintainer = TRUE; $oFirstUserSuperMaintainer->bSuperMaintainer = TRUE;
$oFirstUserSuperMaintainer->create(); if(!$oFirstUserSuperMaintainer->create())
error("oFirstUserSuperMaintainer->create() failed");
/* and unqueue it to accept the user as a maintainer */ /* and unqueue it to accept the user as a maintainer */
$oFirstUserSuperMaintainer->unQueue("Some reply text"); $oFirstUserSuperMaintainer->unQueue("Some reply text");
@@ -309,9 +342,12 @@ function test_maintainer_unQueue()
$iSuperMaintainerCount = maintainer::getMaintainerCountForUser($oFirstUser, TRUE); $iSuperMaintainerCount = maintainer::getMaintainerCountForUser($oFirstUser, TRUE);
if($iSuperMaintainerCount != $iExpected) if($iSuperMaintainerCount != $iExpected)
{ {
echo "Got super maintainer count of '".$iSuperMaintainerCount."' instead of '".$iExpected."'\n"; error("Got super maintainer count of '".$iSuperMaintainerCount.
"' instead of '".$iExpected."'");
maintainer::deleteMaintainersForApplication($oApp); maintainer::deleteMaintainersForApplication($oApp);
maintainer::deleteMaintainersForVersion($oVersion); maintainer::deleteMaintainersForVersion($oVersion);
$oFirstUser->delete();
$oSecondUser->delete();
return false; return false;
} }
@@ -321,44 +357,53 @@ function test_maintainer_unQueue()
$iMaintainerCount = maintainer::getMaintainerCountForUser($oFirstUser, FALSE); $iMaintainerCount = maintainer::getMaintainerCountForUser($oFirstUser, FALSE);
if($iMaintainerCount != $iExpected) if($iMaintainerCount != $iExpected)
{ {
echo "Got maintainer count of '".$iMaintainerCount."' instead of '".$iExpected."'\n"; error("Got maintainer count of '".$iMaintainerCount.
"' instead of '".$iExpected."'");
maintainer::deleteMaintainersForApplication($oApp); maintainer::deleteMaintainersForApplication($oApp);
maintainer::deleteMaintainersForVersion($oVersion); maintainer::deleteMaintainersForVersion($oVersion);
$oFirstUser->delete();
$oSecondUser->delete();
return false; return false;
} }
/* Now the maintainer request for the other user should still be present */ /* Now the maintainer entry for the second user should still be present */
$iExpected = 1; $iExpected = 1;
$iReceived = maintainer::getmaintainerCountForUser($oSecondUser, FALSE); $iReceived = maintainer::getMaintainerCountForUser($oSecondUser, FALSE);
if($iExpected != $iReceived) if($iExpected != $iReceived)
{ {
echo "Got maintainer count of $iReceived instead of $iExpected\n"; error("Got maintainer count of $iReceived instead of $iExpected");
maintainer::deleteMaintainersForApplication($oApp); maintainer::deleteMaintainersForApplication($oApp);
maintainer::deleteMaintainersForVersion($oVersion); maintainer::deleteMaintainersForVersion($oVersion);
$oFirstUser->delete();
$oSecondUser->delete();
return FALSE; return FALSE;
} }
/* Now the super maintainer request for the other user should still be present */ // Now the super maintainer request for the second user should still be present
$oSecondUserSuperMaintainer->unQueue(); $oSecondUserSuperMaintainer->unQueue();
$iExpected = 1; $iExpected = 1;
$iReceived = maintainer::getmaintainerCountForUser($oSecondUser, TRUE); $iReceived = maintainer::getMaintainerCountForUser($oSecondUser, TRUE);
if($iExpected != $iReceived) if($iExpected != $iReceived)
{ {
echo "Got super maintainer count of $iReceived instead of $iExpected\n"; error("Got super maintainer count of $iReceived instead of $iExpected");
maintainer::deleteMaintainersForApplication($oApp); maintainer::deleteMaintainersForApplication($oApp);
maintainer::deleteMaintainersForVersion($oVersion); maintainer::deleteMaintainersForVersion($oVersion);
$oFirstUser->delete();
$oSecondUser->delete();
return FALSE; return FALSE;
} }
/* Now the maintainer request of the other user should be gone */ // Now that the super maintainer entry was unqueued the the maintainer
$oSecondUserMaintainer->unQueue(); // entry should have been deleted
$iExpected = 0; $iExpected = 0;
$iReceived = maintainer::getmaintainerCountForUser($oSecondUser, FALSE); $iReceived = maintainer::getMaintainerCountForUser($oSecondUser, FALSE);
if($iExpected != $iReceived) if($iExpected != $iReceived)
{ {
echo "Got maintainer count of $iReceived instead of $iExpected\n"; error("Got maintainer count of $iReceived instead of $iExpected");
maintainer::deleteMaintainersForApplication($oApp); maintainer::deleteMaintainersForApplication($oApp);
maintainer::deleteMaintainersForVersion($oVersion); maintainer::deleteMaintainersForVersion($oVersion);
$oFirstUser->delete();
$oSecondUser->delete();
return FALSE; return FALSE;
} }
@@ -366,6 +411,9 @@ function test_maintainer_unQueue()
maintainer::deleteMaintainersForApplication($oApp); maintainer::deleteMaintainersForApplication($oApp);
maintainer::deleteMaintainersForVersion($oVersion); maintainer::deleteMaintainersForVersion($oVersion);
$oFirstUser->delete();
$oSecondUser->delete();
return true; return true;
} }
@@ -374,13 +422,11 @@ function test_superMaintainerOnAppSubmit()
{ {
test_start(__FUNCTION__); test_start(__FUNCTION__);
global $test_email, $test_password; $sTestEmail = __FUNCTION__."@localhost.com";
$sTestPassword = "password";
/* Log in */ if(!($oUser = create_and_login_user($sTestEmail, $sTestPassword)))
$oUser = new User();
if($retval = $oUser->login($test_email, $test_password) != SUCCESS)
{ {
echo "Received '$retval' instead of SUCCESS('".SUCCESS."')."; error("Failed to create and log in user!");
return FALSE; return FALSE;
} }
@@ -408,13 +454,15 @@ function test_superMaintainerOnAppSubmit()
if($iGot != $iExpected) if($iGot != $iExpected)
{ {
echo "Got maintainer count of '$iGot' instead of '$iExpected'"; error("Got maintainer count of '$iGot' instead of '$iExpected'");
$oUser->delete();
return false; return false;
} }
Maintainer::deleteMaintainer($oUser, $iAppId); Maintainer::deleteMaintainer($oUser, $iAppId);
$oApp->delete(); $oApp->delete();
$oUser->delete();
return true; return true;
} }
@@ -425,10 +473,13 @@ function test_maintainer_deleteMaintainersForVersion()
{ {
test_start(__FUNCTION__); test_start(__FUNCTION__);
global $test_email, $test_password; $sTestEmail = __FUNCTION__."@localhost.com";
$sTestPassword = "password";
$oUser = new user(); if(!($oUser = create_and_login_user($sTestEmail, $sTestPassword)))
$oUser->login($test_email, $test_password); {
error("Failed to create and log in user!");
return FALSE;
}
$oMaintainer = new maintainer(); $oMaintainer = new maintainer();
$oMaintainer->iAppId = 655000; $oMaintainer->iAppId = 655000;
@@ -444,11 +495,13 @@ function test_maintainer_deleteMaintainersForVersion()
if(maintainer::deleteMaintainersForVersion($oVersion) !== FALSE) if(maintainer::deleteMaintainersForVersion($oVersion) !== FALSE)
{ {
echo "Got success, but this should fail.\n"; error("Got success, but this should fail.");
$oUser->delete();
return FALSE; return FALSE;
} }
$oMaintainer->delete(); $oMaintainer->delete();
$oUser->delete();
return TRUE; return TRUE;
} }
@@ -457,16 +510,19 @@ function test_maintainer_getMaintainersForAppIdVersionId()
{ {
test_start(__FUNCTION__); test_start(__FUNCTION__);
global $test_email, $test_password; $sTestEmail = __FUNCTION__."@localhost.com";
$oUser = new user(); $sTestPassword = "password";
if($oUser->login($test_email, $test_password) != SUCCESS) if(!($oUser = create_and_login_user($sTestEmail, $sTestPassword)))
{ {
echo "Failed to create and log in user!\n"; error("Failed to create and log in user!");
return FALSE; return FALSE;
} }
$oUser->addPriv("admin"); $oUser->addPriv("admin");
// assign the user with admin permissions as the current user
$_SESSION['current'] = $oUser;
$oSecondUser = new user(); $oSecondUser = new user();
$oSecondUser->iUserId = $oUser->iUserId + 1; $oSecondUser->iUserId = $oUser->iUserId + 1;
$oSecondUser->addPriv("admin"); $oSecondUser->addPriv("admin");
@@ -474,10 +530,12 @@ function test_maintainer_getMaintainersForAppIdVersionId()
$oApp = new application(); $oApp = new application();
$oApp->create(); $oApp->create();
$oFirstVersion = new version(); $oFirstVersion = new version();
$oFirstVersion->iAppId = $oApp->iAppId; $oFirstVersion->sName = __FUNCTION__." first version";
$oFirstVersion->iAppId = $oApp->iAppId; // $oApp is the parent
$oFirstVersion->create(); $oFirstVersion->create();
$oSecondVersion = new version(); $oSecondVersion = new version();
$oSecondVersion->iAppid = $oApp->iAppId; $oSecondVersion->sName = __FUNCTION__." first version";
$oSecondVersion->iAppId = $oApp->iAppId; // $oApp is the parent
$oSecondVersion->create(); $oSecondVersion->create();
$oSuperMaintainer = new maintainer(); $oSuperMaintainer = new maintainer();
@@ -489,7 +547,9 @@ function test_maintainer_getMaintainersForAppIdVersionId()
if(!$hResult = maintainer::getMaintainersForAppIdVersionId($oApp->iAppId)) if(!$hResult = maintainer::getMaintainersForAppIdVersionId($oApp->iAppId))
{ {
echo "Failed to get list of maintainers!\n"; error("Failed to get list of maintainers!");
$oUser->delete(); // delete the user
$oApp->delete(); // cleanup the application and its versions we created
return FALSE; return FALSE;
} }
@@ -498,14 +558,18 @@ function test_maintainer_getMaintainersForAppIdVersionId()
$iReceived = mysql_num_rows($hResult); $iReceived = mysql_num_rows($hResult);
if($iExpected != $iReceived) if($iExpected != $iReceived)
{ {
echo "Got super maintainer count of $iReceived instead of $iExpected!\n"; error("Got super maintainer count of $iReceived instead of $iExpected!");
$oUser->delete(); // delete the user
$oApp->delete(); // cleanup the application and its versions we created
return FALSE; return FALSE;
} }
if(!$hResult = maintainer::getMaintainersForAppIdVersionId(null, if(!$hResult = maintainer::getMaintainersForAppIdVersionId(null,
$oFirstVersion->iVersionId)) $oFirstVersion->iVersionId))
{ {
echo "Failed to get list of maintainers!\n"; error("Failed to get list of maintainers!");
$oUser->delete(); // delete the user
$oApp->delete(); // cleanup the application and its versions we created
return FALSE; return FALSE;
} }
@@ -514,11 +578,12 @@ function test_maintainer_getMaintainersForAppIdVersionId()
$iReceived = mysql_num_rows($hResult); $iReceived = mysql_num_rows($hResult);
if($iExpected != $iReceived) if($iExpected != $iReceived)
{ {
echo "Got maintainer count of $iReceived instead of $iExpected!\n"; error("Got maintainer count of $iReceived instead of $iExpected!");
$oUser->delete(); // delete the user
return FALSE; return FALSE;
} }
$oSuperMaintainer->delete(); $oSuperMaintainer->delete(); // cleanup the super maintainer we created
/* Become a maintainer for one of the versions only */ /* Become a maintainer for one of the versions only */
$oFirstVersionMaintainer = new maintainer(); $oFirstVersionMaintainer = new maintainer();
@@ -541,7 +606,9 @@ function test_maintainer_getMaintainersForAppIdVersionId()
if(!$hResult = maintainer::getMaintainersForAppIdVersionId(null, if(!$hResult = maintainer::getMaintainersForAppIdVersionId(null,
$oFirstVersion->iVersionId)) $oFirstVersion->iVersionId))
{ {
echo "Failed to get list of maintainers!\n"; error("Failed to get list of maintainers!");
$oUser->delete(); // delete the user
$oApp->delete(); // cleanup the application and its versions we created
return FALSE; return FALSE;
} }
@@ -550,14 +617,18 @@ function test_maintainer_getMaintainersForAppIdVersionId()
$iReceived = mysql_num_rows($hResult); $iReceived = mysql_num_rows($hResult);
if($iExpected != $iReceived) if($iExpected != $iReceived)
{ {
echo "Got maintainer count of $iReceived instead of $iExpected!\n"; error("Got maintainer count of $iReceived instead of $iExpected!");
$oUser->delete(); // delete the user
$oApp->delete(); // cleanup the application and its versions we created
return FALSE; return FALSE;
} }
if(!$hResult = maintainer::getMaintainersForAppIdVersionId(null, if(!$hResult = maintainer::getMaintainersForAppIdVersionId(null,
$oSecondVersion->iVersionId)) $oSecondVersion->iVersionId))
{ {
echo "Failed to get list of maintainers!\n"; error("Failed to get list of maintainers!");
$oUser->delete(); // delete the user
$oApp->delete(); // cleanup the application and its versions we created
return FALSE; return FALSE;
} }
@@ -566,12 +637,16 @@ function test_maintainer_getMaintainersForAppIdVersionId()
$iReceived = mysql_num_rows($hResult); $iReceived = mysql_num_rows($hResult);
if($iExpected != $iReceived) if($iExpected != $iReceived)
{ {
echo "Got maintainer count of $iReceived instead of $iExpected!\n"; error("Got maintainer count of $iReceived instead of $iExpected!");
$oUser->delete(); // clean up the user
$oApp->delete(); // cleanup the application and its versions we created
return FALSE; return FALSE;
} }
$oApp->delete(); if(!$oApp->delete())
$oUser->delete(); echo __FUNCTION__." oApp->delete() failed\n";
$oUser->delete(); // clean up the user
return TRUE; return TRUE;
} }

View File

@@ -55,7 +55,7 @@ class notifyContainer
$_SESSION['current'] = $this->oUser; $_SESSION['current'] = $this->oUser;
// create a fake version // create a fake version
$this->iVersionId = create_version_and_parent_app(); $this->iVersionId = create_version_and_parent_app("test_maintainer_notify");
// create a queued entry for the user we just created // create a queued entry for the user we just created
$this->oTestData = new testData(); $this->oTestData = new testData();
@@ -595,7 +595,7 @@ function _test_maintainer_notifyMaintainersOfQueuedData($bTestAsMaintainer)
{ {
$bSuccess = true; // default to success $bSuccess = true; // default to success
echo __FUNCTION__."\n"; test_start(__FUNCTION__);
$sFunction = "test_maintainer_notifyLevel_0_to_1"; $sFunction = "test_maintainer_notifyLevel_0_to_1";
if(!$sFunction($bTestAsMaintainer)) if(!$sFunction($bTestAsMaintainer))
@@ -678,7 +678,9 @@ function test_maintainer_notifyMaintainersOfQueuedData()
{ {
$bSuccess = true; $bSuccess = true;
echo "Testing as maintainer\n"; test_start(__FUNCTION__);
echo "\nTesting as maintainer\n";
if(!_test_maintainer_notifyMaintainersOfQueuedData(true)) if(!_test_maintainer_notifyMaintainersOfQueuedData(true))
{ {
echo "Maintainer test failed!\n"; echo "Maintainer test failed!\n";

View File

@@ -32,11 +32,16 @@ function test_class($sClassName, $aTestMethods)
return true; return true;
/* Set up test user */ /* Set up test user */
global $test_email, $test_password; $sTestEmail = __FUNCTION__."@localhost.com";
if(!$oUser = create_and_login_user()) $sTestPassword = "password";
if(!$oUser = create_and_login_user($sTestEmail, $sTestPassword))
{ {
echo "Failed to create and log in user.\n"; error("Failed to create and log in user.");
return FALSE; return FALSE;
} else
{
// assign the session variable that makes this user the current user
$_SESSION['current'] = $oUser;
} }
/* Test the class constructor */ /* Test the class constructor */
@@ -48,16 +53,16 @@ function test_class($sClassName, $aTestMethods)
if(!$hResult) if(!$hResult)
{ {
echo "Got '$hResult' instead of a valid MySQL handle\n"; error("Got '$hResult' instead of a valid MySQL handle");
echo "FAILED\t\t$sClassName::$sClassName\n"; error("FAILED\t\t$sClassName::$sClassName");
$oTestObject->delete(); $oTestObject->delete();
return FALSE; return FALSE;
} }
if(!($oRow = mysql_fetch_object($hResult))) if(!($oRow = mysql_fetch_object($hResult)))
{ {
echo "Failed to fetch MySQL object\n"; error("Failed to fetch MySQL object");
echo "FAILED\t\t$sClassName::$sClassName\n"; error("FAILED\t\t$sClassName::$sClassName");
$oTestObject->delete(); $oTestObject->delete();
return FALSE; return FALSE;
} }
@@ -102,16 +107,29 @@ function test_class($sClassName, $aTestMethods)
if(!$iReceived || !is_numeric($iReceived)) if(!$iReceived || !is_numeric($iReceived))
{ {
echo "Got '$iReceived' instead of a valid id\n"; error("Got '$iReceived' instead of a valid id");
echo "FAILED\t\t$sClassName::$sClassName()\n"; error("FAILED\t\t$sClassName::$sClassName()");
$oTestObject->delete(); $oTestObject->delete();
return FALSE; return FALSE;
} }
echo "PASSED\t\t$sClassName::$sClassName\n"; echo "PASSED\t\t$sClassName::$sClassName\n";
//////////////////////////
// cleanup after the test
cleanup($oTestObject); cleanup($oTestObject);
$oTestObject->delete();
if(!$oUser->addPriv("admin"))
error("oUser->addPriv('admin') failed");
if(!$oTestObject->delete())
{
error("sClassName of $sClassName oTestObject->delete() failed!");
$oUser->delete();
return false;
}
////////////////////////////////
/* Test the methods' functionality */ /* Test the methods' functionality */
foreach($aTestMethods as $sMethod) foreach($aTestMethods as $sMethod)
@@ -130,8 +148,8 @@ function test_class($sClassName, $aTestMethods)
$iReceived = mysql_num_rows($hResult); $iReceived = mysql_num_rows($hResult);
if($iExpected > $iReceived) if($iExpected > $iReceived)
{ {
echo "Got $iReceived instead of >= $iExpected\n"; error("Got $iReceived instead of >= $iExpected");
echo "FAILED\t\t$sClassName::$sMethod\n"; error("FAILED\t\t$sClassName::$sMethod");
$oTestObject->delete(); $oTestObject->delete();
return FALSE; return FALSE;
} }
@@ -224,7 +242,7 @@ function create_object($sClassName, $oUser)
{ {
if(!$oTestObject->create()) if(!$oTestObject->create())
{ {
echo "FAILED\t\t$sClassName::create()\n"; error("FAILED\t\t$sClassName::create()");
return FALSE; return FALSE;
} }
} else } else
@@ -236,7 +254,7 @@ function create_object($sClassName, $oUser)
$oUser->iUserId); $oUser->iUserId);
if(!$hResult) if(!$hResult)
{ {
echo "FAILED\t\t$sClassName to create screenshot entry"; error("FAILED\t\t$sClassName to create screenshot entry");
return FALSE; return FALSE;
} }
$oTestObject->iScreenshotId = mysql_insert_id(); $oTestObject->iScreenshotId = mysql_insert_id();

View File

@@ -6,8 +6,9 @@ require_once(BASE."include/version.php");
function test_testData_getNewestTestidFromVersionId() function test_testData_getNewestTestidFromVersionId()
{ {
test_start(__FUNCTION__); test_start(__FUNCTION__);
global $test_email, $test_password; $sTestEmail = __FUNCTION__."@localhost.com";
if(!$oUser = create_and_login_user()) $sTestPassword = "password";
if(!$oUser = create_and_login_user($sTestEmail, $sTestPassword))
{ {
echo "Failed to create and log in user\n"; echo "Failed to create and log in user\n";
return FALSE; return FALSE;
@@ -30,14 +31,16 @@ function test_testData_getNewestTestidFromVersionId()
$iReceived = testData::getNewestTestidFromVersionId($iVersionId); $iReceived = testData::getNewestTestidFromVersionId($iVersionId);
if($iExpected != $iReceived) if($iExpected != $iReceived)
{ {
echo "Got testData id of $iReceived instead of $iExpected!\n"; error("Got testData id of $iReceived instead of $iExpected!");
$oOldTestData->delete(); $oOldTestData->delete();
$oNewTestData->delete(); $oNewTestData->delete();
$oUser->delete();
return FALSE; return FALSE;
} }
$oOldTestData->delete(); $oOldTestData->delete();
$oNewTestData->delete(); $oNewTestData->delete();
$oUser->delete();
return TRUE; return TRUE;
} }

View File

@@ -9,14 +9,14 @@ function test_url_update()
{ {
test_start(__FUNCTION__); test_start(__FUNCTION__);
global $test_email, $test_password;
$bSuccess = true; // default to success until we detect failure $bSuccess = true; // default to success until we detect failure
/* Log in */ /* Log in */
if(!$oUser = create_and_login_user()) $sTestUser = __FUNCTION__."@localhost.com";
$sTestPassword = "password";
if(!$oUser = create_and_login_user($sTestUser, $sTestPassword))
{ {
echo "Received '$retval' instead of SUCCESS('".SUCCESS."')."; error("Received '$retval' instead of SUCCESS('".SUCCESS."').");
return FALSE; return FALSE;
} }
@@ -37,25 +37,25 @@ function test_url_update()
if($oUrl->sDescription != $sDescriptionNew) if($oUrl->sDescription != $sDescriptionNew)
{ {
echo "Description is '$oUrl->sDescription' instead of '$sDescriptionNew'\n"; error("Description is '$oUrl->sDescription' instead of '$sDescriptionNew'");
$bSuccess = false; $bSuccess = false;
} }
if($oUrl->sUrl != $sUrlNew) if($oUrl->sUrl != $sUrlNew)
{ {
echo "Url is '$oUrl->sUrl' instead of '$sUrlNew'\n"; error("Url is '$oUrl->sUrl' instead of '$sUrlNew'");
$bSuccess = false; $bSuccess = false;
} }
if($oUrl->iVersionId != $iVersionIdNew) if($oUrl->iVersionId != $iVersionIdNew)
{ {
echo "VersionId is '$oUrl->iVersionId' instead of '$iVersionIdNew'\n"; error("VersionId is '$oUrl->iVersionId' instead of '$iVersionIdNew'");
$bSuccess = false; $bSuccess = false;
} }
if($oUrl->iAppId != $iAppIdNew) if($oUrl->iAppId != $iAppIdNew)
{ {
echo "AppId is '$oUrl->iAppId' instead of '$iAppIdNew'\n"; error("AppId is '$oUrl->iAppId' instead of '$iAppIdNew'");
$bSuccess = false; $bSuccess = false;
} }

View File

@@ -21,29 +21,8 @@ function test_user_create()
global $test_email, $test_password; global $test_email, $test_password;
$oUser = new User(); if(!($oUser = create_and_login_user($test_email, $test_password)))
/* delete the user if they already exist */
if($oUser->login($test_email, $test_password) == SUCCESS)
{ {
$oUser->delete();
$oUser = new User();
} else
{
echo "User doesn't already exist\n";
}
/* create the user */
$retval = $oUser->create($test_email, $test_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; return false;
} }