Unit tests should run with E_ALL so we can detect all errors. Fix dozens of errors that popped up after enabling all errors.

This commit is contained in:
WineHQ
2006-11-25 17:24:44 +00:00
parent e1333dd7fc
commit b858e2ba53
21 changed files with 193 additions and 131 deletions

View File

@@ -49,17 +49,20 @@ class Application {
if($hResult = query_parameters($sQuery, $iAppId))
{
$oRow = mysql_fetch_object($hResult);
$this->iAppId = $iAppId;
$this->iVendorId = $oRow->vendorId;
$this->iCatId = $oRow->catId;
$this->iSubmitterId = $oRow->submitterId;
$this->sSubmitTime = $oRow->submitTime;
$this->sDate = $oRow->submitTime;
$this->sName = $oRow->appName;
$this->sKeywords = $oRow->keywords;
$this->sDescription = $oRow->description;
$this->sWebpage = $oRow->webPage;
$this->sQueued = $oRow->queued;
if($oRow)
{
$this->iAppId = $iAppId;
$this->iVendorId = $oRow->vendorId;
$this->iCatId = $oRow->catId;
$this->iSubmitterId = $oRow->submitterId;
$this->sSubmitTime = $oRow->submitTime;
$this->sDate = $oRow->submitTime;
$this->sName = $oRow->appName;
$this->sKeywords = $oRow->keywords;
$this->sDescription = $oRow->description;
$this->sWebpage = $oRow->webPage;
$this->sQueued = $oRow->queued;
}
}
/* fetch versions of this application, if there are any */
@@ -404,7 +407,10 @@ class Application {
{
$aClean = array(); //array of filtered user input
$aClean['sReplyText'] = makeSafe($_REQUEST['sReplyText']);
if(isset($_REQUEST['sReplyText']))
$aClean['sReplyText'] = makeSafe($_REQUEST['sReplyText']);
else
$aClean['sReplyText'] = "";
switch($sAction)
{

View File

@@ -32,11 +32,13 @@ class Category {
if($hResult = query_parameters($sQuery, $iCatId))
{
$oRow = mysql_fetch_object($hResult);
$this->iCatId = $iCatId;
$this->iParentId = $oRow->catParent;
$this->sName = $oRow->catName;
$this->sDescription = $oRow->catDescription;
if($oRow)
{
$this->iCatId = $iCatId;
$this->iParentId = $oRow->catParent;
$this->sName = $oRow->catName;
$this->sDescription = $oRow->catDescription;
}
}
/*

View File

@@ -32,13 +32,16 @@ class distribution{
if($hResult = query_parameters($sQuery, $iDistributionId))
{
$oRow = mysql_fetch_object($hResult);
$this->iDistributionId = $iDistributionId;
$this->sName = $oRow->name;
$this->sDescription = $oRow->description;
$this->sUrl = $oRow->url;
$this->sSubmitTime = $oRow->submitTime;
$this->iSubmitterId = $oRow->submitterId;
$this->sQueued = $oRow->queued;
if($oRow)
{
$this->iDistributionId = $iDistributionId;
$this->sName = $oRow->name;
$this->sDescription = $oRow->description;
$this->sUrl = $oRow->url;
$this->sSubmitTime = $oRow->submitTime;
$this->iSubmitterId = $oRow->submitterId;
$this->sQueued = $oRow->queued;
}
}
}

View File

@@ -1,7 +1,7 @@
<?php
define(ERROR_SQL, "sql_error");
define(ERROR_GENERAL, "general_error");
define("ERROR_SQL", "sql_error");
define("ERROR_GENERAL", "general_error");
class error_log
{

View File

@@ -57,7 +57,7 @@ class Image {
$this->iHeight = $oInfo[1];
$this->iType = $oInfo[2];
$this->set_debuglog("New image class created with as $sFile as"
$this->set_debuglog("New image class created with as $this->sFile as"
." file and {$oInfo[2]} as type. Dimensions"
." {$oInfo[0]}x{$oInfo[1]}");
}
@@ -214,7 +214,7 @@ class Image {
$iNewWidth,$iNewHeight,$this->iWidth,$this->iHeight);
}
$this->set_debuglog("imagecopyresized($new,$this->oImage,0,0,0,0,$iNewWidth,"
$this->set_debuglog("imagecopyresized($oNewImage,$this->oImage,0,0,0,0,$iNewWidth,"
."$iNewHeight,$this->iWidth,$this->iHeight);");
imagedestroy($this->oImage);
$this->oImage = $oNewImage;
@@ -231,7 +231,6 @@ class Image {
*/
function resize_image_border($sBorderColor, $iBorderWidth, $iNewHeight, $iNewWidth)
{
$r = hexdec(substr($sBorderColor, 1, 2));
$g = hexdec(substr($sBorderColor, 3, 2));
$b = hexdec(substr($sBorderColor, 5, 2));

View File

@@ -5,7 +5,7 @@
// get modules
ini_set("memory_limit","64M");
require(BASE."include/config.php");
require_once(BASE."include/config.php");
require(BASE."include/util.php");
require(BASE."include/user.php");
require(BASE."include/session.php");

View File

@@ -1,4 +1,6 @@
<?php
require_once(BASE."include/config.php");
function mail_appdb($sEmailList,$sSubject,$sMsg)
{
$sHeaders = "MIME-Version: 1.0\r\n";

View File

@@ -24,14 +24,17 @@ class maintainer
if($hResult)
{
$oRow = mysql_fetch_object($hResult);
$this->iMaintainerId = $oRow->maintainerId;
$this->iAppId = $oRow->appId;
$this->iVersionId = $oRow->versionId;
$this->iUserId = $oRow->userId;
$this->sMaintainReason = $oRow->maintainReason;
$this->bSuperMaintainer = $oRow->superMaintainer;
$this->aSubmitTime = $oRow->submitTime;
$this->bQueued = $oRow->queued;
if($oRow)
{
$this->iMaintainerId = $oRow->maintainerId;
$this->iAppId = $oRow->appId;
$this->iVersionId = $oRow->versionId;
$this->iUserId = $oRow->userId;
$this->sMaintainReason = $oRow->maintainReason;
$this->bSuperMaintainer = $oRow->superMaintainer;
$this->aSubmitTime = $oRow->submitTime;
$this->bQueued = $oRow->queued;
}
}
}
@@ -73,8 +76,8 @@ class maintainer
{
$sStatusMessage = "<p>The maintainer was successfully added into the database</p>\n";
$oApp = new Application($iAppId);
$oVersion = new Version($iVersionId);
$oApp = new Application($this->iAppId);
$oVersion = new Version($this->iVersionId);
//Send Status Email
$sEmail = $oUser->sEmail;
if ($sEmail)

View File

@@ -26,11 +26,13 @@ class Monitor {
WHERE monitorId = '".$iMonitorId."'";
$hResult = query_appdb($sQuery);
$oRow = mysql_fetch_object($hResult);
$this->iMonitorId = $oRow->monitorId;
$this->iAppId = $oRow->appId;
$this->iVersionId = $oRow->versionId;
$this->iUserId = $oRow->userId;
if($oRow)
{
$this->iMonitorId = $oRow->monitorId;
$this->iAppId = $oRow->appId;
$this->iVersionId = $oRow->versionId;
$this->iUserId = $oRow->userId;
}
}
}

View File

@@ -3,7 +3,10 @@ require_once(BASE."include/util.php");
require_once(BASE."include/version.php");
$aClean = array(); //array of filtered user input
$aClean['sReplyText'] = makeSafe( $_REQUEST['sReplyText'] );
if(isset($_REQUEST['sReplyText']))
$aClean['sReplyText'] = makeSafe( $_REQUEST['sReplyText'] );
else
$aClean['sReplyText'] = "";
/************************************/
/* note class and related functions */
@@ -34,11 +37,14 @@ class Note {
AND noteId = '?'";
$hResult = query_parameters($sQuery, $iNoteId);
$oRow = mysql_fetch_object($hResult);
$this->iNoteId = $oRow->noteId;
$this->iAppId = $oRow->appId;
$this->iVersionId = $oRow->versionId;
$this->sTitle = $oRow->noteTitle;
$this->sDescription = $oRow->noteDesc;
if($oRow)
{
$this->iNoteId = $oRow->noteId;
$this->iAppId = $oRow->appId;
$this->iVersionId = $oRow->versionId;
$this->sTitle = $oRow->noteTitle;
$this->sDescription = $oRow->noteDesc;
}
}
}

View File

@@ -2,7 +2,7 @@
$hAppdbLink = null;
$hBugzillaLink = null;
define(MYSQL_DEADLOCK_ERRNO, 1213);
define("MYSQL_DEADLOCK_ERRNO", 1213);
function query_appdb($sQuery,$sComment="")
{

View File

@@ -40,14 +40,17 @@ class Screenshot {
if($hResult)
{
$oRow = mysql_fetch_object($hResult);
$this->iScreenshotId = $iScreenshotId;
$this->sDescription = $oRow->description;
$this->iAppId = $oRow->appId;
$this->iVersionId = $oRow->versionId;
$this->sUrl = $oRow->url;
$this->bQueued = ($oRow->queued=="true")?true:false;
$this->sSubmitTime = $oRow->submitTime;
$this->iSubmitterId = $oRow->submitterId;
if($oRow)
{
$this->iScreenshotId = $iScreenshotId;
$this->sDescription = $oRow->description;
$this->iAppId = $oRow->appId;
$this->iVersionId = $oRow->versionId;
$this->sUrl = $oRow->url;
$this->bQueued = ($oRow->queued=="true")?true:false;
$this->sSubmitTime = $oRow->submitTime;
$this->iSubmitterId = $oRow->submitterId;
}
}
}
}

View File

@@ -6,7 +6,7 @@
*/
/* the number of days a session cookie is flaged to last */
define(SESSION_DAYS_TO_EXPIRE, 2);
define("SESSION_DAYS_TO_EXPIRE", 2);
class session
{
@@ -73,7 +73,10 @@ class session
$result = query_parameters("SELECT data FROM session_list WHERE session_id = '?'", $key);
if (!$result) { return null; }
$oRow = mysql_fetch_object($result);
return $oRow->data;
if($oRow)
return $oRow->data;
else
return NULL;
}
// write session to DB

View File

@@ -38,21 +38,24 @@ class testData{
if($hResult = query_parameters($sQuery, $iTestingId))
{
$oRow = mysql_fetch_object($hResult);
$this->iTestingId = $oRow->testingId;
$this->iVersionId = $oRow->versionId;
$this->sWhatWorks = $oRow->whatWorks;
$this->sWhatDoesnt = $oRow->whatDoesnt;
$this->sWhatNotTested = $oRow->whatNotTested;
$this->sTestedDate = $oRow->testedDate;
$this->iDistributionId = $oRow->distributionId;
$this->sTestedRelease = $oRow->testedRelease;
$this->sInstalls = $oRow->installs;
$this->sRuns = $oRow->runs;
$this->sTestedRating = $oRow->testedRating;
$this->sComments = $oRow->comments;
$this->sSubmitTime = $oRow->submitTime;
$this->iSubmitterId = $oRow->submitterId;
$this->sQueued = $oRow->queued;
if($oRow)
{
$this->iTestingId = $oRow->testingId;
$this->iVersionId = $oRow->versionId;
$this->sWhatWorks = $oRow->whatWorks;
$this->sWhatDoesnt = $oRow->whatDoesnt;
$this->sWhatNotTested = $oRow->whatNotTested;
$this->sTestedDate = $oRow->testedDate;
$this->iDistributionId = $oRow->distributionId;
$this->sTestedRelease = $oRow->testedRelease;
$this->sInstalls = $oRow->installs;
$this->sRuns = $oRow->runs;
$this->sTestedRating = $oRow->testedRating;
$this->sComments = $oRow->comments;
$this->sSubmitTime = $oRow->submitTime;
$this->iSubmitterId = $oRow->submitterId;
$this->sQueued = $oRow->queued;
}
}
}
}

View File

@@ -7,13 +7,13 @@ require_once(BASE."include/version.php");
require_once(BASE."include/maintainer.php");
require_once(BASE."include/util.php");
define(SUCCESS, 0);
define(USER_CREATE_EXISTS, 1);
define(USER_CREATE_FAILED, 2);
define(USER_LOGIN_FAILED, 3);
define(USER_UPDATE_FAILED, 4);
define(USER_UPDATE_FAILED_EMAIL_EXISTS, 5); /* user updating to an email address that is already in use */
define(USER_UPDATE_FAILED_NOT_LOGGED_IN, 6); /* user::update() called but user not logged in */
define("SUCCESS", 0);
define("USER_CREATE_EXISTS", 1);
define("USER_CREATE_FAILED", 2);
define("USER_LOGIN_FAILED", 3);
define("USER_UPDATE_FAILED", 4);
define("USER_UPDATE_FAILED_EMAIL_EXISTS", 5); /* user updating to an email address that is already in use */
define("USER_UPDATE_FAILED_NOT_LOGGED_IN", 6); /* user::update() called but user not logged in */
/**
* User class for handling users
@@ -41,13 +41,16 @@ class User {
WHERE userId = '?'";
$hResult = query_parameters($sQuery, $iUserId);
$oRow = mysql_fetch_object($hResult);
$this->iUserId = $oRow->userid;
$this->sEmail = $oRow->email;
$this->sRealname = $oRow->realname;
$this->sStamp = $oRow->stamp;
$this->sDateCreated = $oRow->created;
$this->sWineRelease = $oRow->CVSrelease;
$this->bInactivityWarned = $oRow->inactivity_warned;
if($oRow)
{
$this->iUserId = $oRow->userid;
$this->sEmail = $oRow->email;
$this->sRealname = $oRow->realname;
$this->sStamp = $oRow->stamp;
$this->sDateCreated = $oRow->created;
$this->sWineRelease = $oRow->CVSrelease;
$this->bInactivityWarned = $oRow->inactivity_warned;
}
}
return $this->isLoggedIn();
}
@@ -65,12 +68,16 @@ class User {
$hResult = query_parameters($sQuery, $sEmail, $sPassword);
$oRow = mysql_fetch_object($hResult);
$this->iUserId = $oRow->userid;
$this->sEmail = $oRow->email;
$this->sRealname = $oRow->realname;
$this->sStamp = $oRow->stamp;
$this->sDateCreated = $oRow->created;
$this->sWineRelease = $oRow->CVSrelease;
if($oRow)
{
$this->iUserId = $oRow->userid;
$this->sEmail = $oRow->email;
$this->sRealname = $oRow->realname;
$this->sStamp = $oRow->stamp;
$this->sDateCreated = $oRow->created;
$this->sWineRelease = $oRow->CVSrelease;
}
if($this->isLoggedIn())
{
// Update timestamp and clear the inactivity flag if it was set
@@ -740,13 +747,19 @@ class User {
while($oRow = mysql_fetch_object($hResult))
{
$i = array_search($oRow->userid, $aUserId);
if ($aUserId[$i] != array($oRow->userid))
// if we didn't find this entry in the $aUserId
// array then we should add it
if($i === false)
{
$aUserId[$c] = array($oRow->userid);
$c++;
}
}
}
// go through the email entries and only add the emails for the users
// that want to receive it
if ($c > 0)
{
while(list($index, list($userIdValue)) = each($aUserId))
@@ -756,6 +769,7 @@ class User {
$retval .= $oUser->sEmail." ";
}
}
return $retval;
}

View File

@@ -45,19 +45,19 @@ class Version {
if($hResult = query_parameters($sQuery, $iVersionId))
{
$oRow = mysql_fetch_object($hResult);
$this->iVersionId = $iVersionId;
$this->iAppId = $oRow->appId;
$this->iCatId = $oRow->catId;
$this->iSubmitterId = $oRow->submitterId;
$this->sSubmitTime = $oRow->submitTime;
$this->sDate = $oRow->submitTime;
$this->sName = $oRow->versionName;
$this->sKeywords = $oRow->keywords;
$this->sDescription = $oRow->description;
$this->sTestedRelease = $oRow->maintainer_release;
$this->sTestedRating = $oRow->maintainer_rating;
$this->sWebpage = $oRow->webPage;
$this->sQueued = $oRow->queued;
if($oRow)
{
$this->iVersionId = $iVersionId;
$this->iAppId = $oRow->appId;
$this->iSubmitterId = $oRow->submitterId;
$this->sSubmitTime = $oRow->submitTime;
$this->sDate = $oRow->submitTime;
$this->sName = $oRow->versionName;
$this->sDescription = $oRow->description;
$this->sTestedRelease = $oRow->maintainer_release;
$this->sTestedRating = $oRow->maintainer_rating;
$this->sQueued = $oRow->queued;
}
}
}
}
@@ -394,7 +394,12 @@ class Version {
function mailSubmitter($sAction="add")
{
$aClean = array(); //array of filtered user input
$aClean['sReplyText'] = makeSafe($_REQUEST['sReplyText']);
// use 'sReplyText' if it is defined, otherwise define the value as an empty string
if(isset($_REQUEST['sReplyText']))
$aClean['sReplyText'] = makeSafe($_REQUEST['sReplyText']);
else
$aClean['sReplyText'] = "";
if($this->iSubmitterId)
{
@@ -403,12 +408,12 @@ class Version {
switch($sAction)
{
case "add":
$sSubject = "Submitted version accepted";
$sSubject = "Submitted version accepted";
$sMsg = "The version you submitted (".$oApp->sName." ".$this->sName.") has been accepted by ".$_SESSION['current']->sRealname.".";
$sMsg .= "Administrators Responce:\n";
break;
case "reject":
$sSubject = "Submitted version rejected";
$sSubject = "Submitted version rejected";
$sMsg = "The version you submitted (".$oApp->sName." ".$this->sName.") has been rejected by ".$_SESSION['current']->sRealname.".";
$sMsg .= "Clicking on the link in this email will allow you to modify and resubmit the version. ";
$sMsg .= "A link to your queue of applications and versions will also show up on the left hand side of the Appdb site once you have logged in. ";
@@ -416,7 +421,7 @@ class Version {
$sMsg .= "Reason given:\n";
break;
case "delete":
$sSubject = "Submitted version deleted";
$sSubject = "Submitted version deleted";
$sMsg = "The version you submitted (".$oApp->sName." ".$this->sName.") has been deleted by ".$_SESSION['current']->sRealname.".";
$sMsg .= "Reason given:\n";
break;
@@ -432,7 +437,12 @@ class Version {
function SendNotificationMail($sAction="add",$sMsg=null)
{
$aClean = array(); //array of filtered user input
$aClean['sReplyText'] = makeSafe($_REQUEST['sReplyText']);
// use 'sReplyText' if it is defined, otherwise define the value as an empty string
if(isset($_REQUEST['sReplyText']))
$aClean['sReplyText'] = makeSafe($_REQUEST['sReplyText']);
else
$aClean['sReplyText'] = "";
$oApp = new Application($this->iAppId);
switch($sAction)

View File

@@ -5,7 +5,7 @@
/* TODO: test the rest of the classes we have */
error_reporting(E_ALL ^ E_NOTICE);
error_reporting(E_ALL);
include_once("test_user.php");
echo "\n";

View File

@@ -135,7 +135,7 @@ function test_application_getWithRating()
$iItemsPerPage = 50;
$iOffset = 0;
$sRating = 'Bronze';
$aApps=Application::getWithRating($sRating, $iOffset, $iItemsPerPage);
$aApps = Application::getWithRating($sRating, $iOffset, $iItemsPerPage);
$aTest = array();//array to test the uniqueness our query results
while(list($i, $iId) = each($aApps)) //cycle through results returned by getWithRating
{
@@ -249,13 +249,13 @@ function create_and_login_user()
if(!test_application_delete())
echo "test_application_delete() failed!\n";
else
echo "test_application_delete() passed!\n";
echo "test_application_delete() passed\n";
if(!test_application_getWithRating())
echo "test_application_getWithRating() failed!\n";
else
echo "test_application_getWithRating() passed!\n";
echo "test_application_getWithRating() passed\n";
?>

View File

@@ -5,11 +5,11 @@
require_once("path.php");
require_once("test_common.php");
DEFINE(TEST_IMAGE_FILENAME, "/images/appdb_montage.jpg");
DEFINE(TEST_IMAGE_OUTPUT_FILENAME, "/tmp/tmpfile.png");
DEFINE(TEST_IMAGE_WIDTH, 391);
DEFINE(TEST_IMAGE_HEIGHT, 266);
DEFINE(TEST_IMAGE_WATERMARK, "/images/watermark.png");
DEFINE("TEST_IMAGE_FILENAME", "/images/appdb_montage.jpg");
DEFINE("TEST_IMAGE_OUTPUT_FILENAME", "/tmp/tmpfile.png");
DEFINE("TEST_IMAGE_WIDTH", 391);
DEFINE("TEST_IMAGE_HEIGHT", 266);
DEFINE("TEST_IMAGE_WATERMARK", "/images/watermark.png");
function test_image_constructor()
{
@@ -73,7 +73,7 @@ function test_image_make_thumbnail()
from the ratio of the height
to width of the original image */
$iBorderWidth = 20;
$oImage->make_thumb($iWidth, $iHeight, $iBorderWidthm, "#0000FF");
$oImage->make_thumb($iWidth, $iHeight, $iBorderWidth, "#0000FF");
/* did we get the correct size? */
$iActualWidth = $oImage->get_width();

View File

@@ -121,7 +121,7 @@ function test_query_parameters()
if(!test_query_parameters())
echo "test_query_parameters() failed!\n";
else
echo "test_query_parameters() passed!\n";
echo "test_query_parameters() passed\n";
?>
?>

View File

@@ -28,10 +28,13 @@ function test_user_create()
{
$oUser->delete();
$oUser = new User();
} else
{
echo "User doesn't already exist\n";
}
/* create the user */
$retval = $oUser->create("testemail@somesite.com", "password", "Test user", "20051020");
$retval = $oUser->create($test_email, $test_password, "Test user", "20051020");
if($retval != SUCCESS)
{
if($retval == USER_CREATE_EXISTS)
@@ -45,7 +48,7 @@ function test_user_create()
}
/* try creating the user again, see that we get USER_CREATE_EXISTS */
$retval = $oUser->create("testemail@somesite.com", "password", "Test user", "20051020");
$retval = $oUser->create($test_email, $test_password, "Test user", "20051020");
if($retval != USER_CREATE_EXISTS)
{
echo "Got '".$retval."' instead of USER_CREATE_EXISTS(".USER_CREATE_EXISTS.")\n";
@@ -68,15 +71,17 @@ function test_user_login()
$retval = $oUser->login($test_email, $test_password);
if($retval != SUCCESS)
{
echo "Test that correct information results in a correct login FAILED\n";
echo "Got '".$retval."' instead of SUCCESS(".SUCCESS.")\n";
return false;
}
/* test that incorrect user results in a login failed */
$oUser = new User();
$retval = $oUser->login("some nutty username", $testpassword);
$retval = $oUser->login("some nutty username", $test_password);
if($retval != USER_LOGIN_FAILED)
{
echo "Test that incorrect user results in a failed login FAILED\n";
echo "Got '".$retval."' instead of SUCCESS(".SUCCESS.")\n";
return false;
}
@@ -86,6 +91,7 @@ function test_user_login()
$retval = $oUser->login($test_email, "some password");
if($retval != USER_LOGIN_FAILED)
{
echo "Test that incorrect passowrd results in a login failed FAILED\n";
echo "Got '".$retval."' instead of SUCCESS(".SUCCESS.")\n";
return false;
}