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,6 +49,8 @@ class Application {
if($hResult = query_parameters($sQuery, $iAppId)) if($hResult = query_parameters($sQuery, $iAppId))
{ {
$oRow = mysql_fetch_object($hResult); $oRow = mysql_fetch_object($hResult);
if($oRow)
{
$this->iAppId = $iAppId; $this->iAppId = $iAppId;
$this->iVendorId = $oRow->vendorId; $this->iVendorId = $oRow->vendorId;
$this->iCatId = $oRow->catId; $this->iCatId = $oRow->catId;
@@ -61,6 +63,7 @@ class Application {
$this->sWebpage = $oRow->webPage; $this->sWebpage = $oRow->webPage;
$this->sQueued = $oRow->queued; $this->sQueued = $oRow->queued;
} }
}
/* fetch versions of this application, if there are any */ /* fetch versions of this application, if there are any */
$this->aVersionsIds = array(); $this->aVersionsIds = array();
@@ -404,7 +407,10 @@ class Application {
{ {
$aClean = array(); //array of filtered user input $aClean = array(); //array of filtered user input
if(isset($_REQUEST['sReplyText']))
$aClean['sReplyText'] = makeSafe($_REQUEST['sReplyText']); $aClean['sReplyText'] = makeSafe($_REQUEST['sReplyText']);
else
$aClean['sReplyText'] = "";
switch($sAction) switch($sAction)
{ {

View File

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

View File

@@ -32,6 +32,8 @@ class distribution{
if($hResult = query_parameters($sQuery, $iDistributionId)) if($hResult = query_parameters($sQuery, $iDistributionId))
{ {
$oRow = mysql_fetch_object($hResult); $oRow = mysql_fetch_object($hResult);
if($oRow)
{
$this->iDistributionId = $iDistributionId; $this->iDistributionId = $iDistributionId;
$this->sName = $oRow->name; $this->sName = $oRow->name;
$this->sDescription = $oRow->description; $this->sDescription = $oRow->description;
@@ -41,6 +43,7 @@ class distribution{
$this->sQueued = $oRow->queued; $this->sQueued = $oRow->queued;
} }
} }
}
/* /*
* We fetch Test Result Ids. * We fetch Test Result Ids.

View File

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

View File

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

View File

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

View File

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

View File

@@ -24,6 +24,8 @@ class maintainer
if($hResult) if($hResult)
{ {
$oRow = mysql_fetch_object($hResult); $oRow = mysql_fetch_object($hResult);
if($oRow)
{
$this->iMaintainerId = $oRow->maintainerId; $this->iMaintainerId = $oRow->maintainerId;
$this->iAppId = $oRow->appId; $this->iAppId = $oRow->appId;
$this->iVersionId = $oRow->versionId; $this->iVersionId = $oRow->versionId;
@@ -34,6 +36,7 @@ class maintainer
$this->bQueued = $oRow->queued; $this->bQueued = $oRow->queued;
} }
} }
}
function create() function create()
{ {
@@ -73,8 +76,8 @@ class maintainer
{ {
$sStatusMessage = "<p>The maintainer was successfully added into the database</p>\n"; $sStatusMessage = "<p>The maintainer was successfully added into the database</p>\n";
$oApp = new Application($iAppId); $oApp = new Application($this->iAppId);
$oVersion = new Version($iVersionId); $oVersion = new Version($this->iVersionId);
//Send Status Email //Send Status Email
$sEmail = $oUser->sEmail; $sEmail = $oUser->sEmail;
if ($sEmail) if ($sEmail)

View File

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

View File

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

View File

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

View File

@@ -40,6 +40,8 @@ class Screenshot {
if($hResult) if($hResult)
{ {
$oRow = mysql_fetch_object($hResult); $oRow = mysql_fetch_object($hResult);
if($oRow)
{
$this->iScreenshotId = $iScreenshotId; $this->iScreenshotId = $iScreenshotId;
$this->sDescription = $oRow->description; $this->sDescription = $oRow->description;
$this->iAppId = $oRow->appId; $this->iAppId = $oRow->appId;
@@ -51,6 +53,7 @@ class Screenshot {
} }
} }
} }
}
/** /**

View File

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

View File

@@ -38,6 +38,8 @@ class testData{
if($hResult = query_parameters($sQuery, $iTestingId)) if($hResult = query_parameters($sQuery, $iTestingId))
{ {
$oRow = mysql_fetch_object($hResult); $oRow = mysql_fetch_object($hResult);
if($oRow)
{
$this->iTestingId = $oRow->testingId; $this->iTestingId = $oRow->testingId;
$this->iVersionId = $oRow->versionId; $this->iVersionId = $oRow->versionId;
$this->sWhatWorks = $oRow->whatWorks; $this->sWhatWorks = $oRow->whatWorks;
@@ -57,6 +59,7 @@ class testData{
} }
} }
} }
}
// Creates a new Test Results. // Creates a new Test Results.
function create() function create()

View File

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

View File

@@ -45,23 +45,23 @@ class Version {
if($hResult = query_parameters($sQuery, $iVersionId)) if($hResult = query_parameters($sQuery, $iVersionId))
{ {
$oRow = mysql_fetch_object($hResult); $oRow = mysql_fetch_object($hResult);
if($oRow)
{
$this->iVersionId = $iVersionId; $this->iVersionId = $iVersionId;
$this->iAppId = $oRow->appId; $this->iAppId = $oRow->appId;
$this->iCatId = $oRow->catId;
$this->iSubmitterId = $oRow->submitterId; $this->iSubmitterId = $oRow->submitterId;
$this->sSubmitTime = $oRow->submitTime; $this->sSubmitTime = $oRow->submitTime;
$this->sDate = $oRow->submitTime; $this->sDate = $oRow->submitTime;
$this->sName = $oRow->versionName; $this->sName = $oRow->versionName;
$this->sKeywords = $oRow->keywords;
$this->sDescription = $oRow->description; $this->sDescription = $oRow->description;
$this->sTestedRelease = $oRow->maintainer_release; $this->sTestedRelease = $oRow->maintainer_release;
$this->sTestedRating = $oRow->maintainer_rating; $this->sTestedRating = $oRow->maintainer_rating;
$this->sWebpage = $oRow->webPage;
$this->sQueued = $oRow->queued; $this->sQueued = $oRow->queued;
} }
} }
} }
} }
}
/** /**
@@ -394,7 +394,12 @@ class Version {
function mailSubmitter($sAction="add") function mailSubmitter($sAction="add")
{ {
$aClean = array(); //array of filtered user input $aClean = array(); //array of filtered user input
// use 'sReplyText' if it is defined, otherwise define the value as an empty string
if(isset($_REQUEST['sReplyText']))
$aClean['sReplyText'] = makeSafe($_REQUEST['sReplyText']); $aClean['sReplyText'] = makeSafe($_REQUEST['sReplyText']);
else
$aClean['sReplyText'] = "";
if($this->iSubmitterId) if($this->iSubmitterId)
{ {
@@ -432,7 +437,12 @@ class Version {
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
// use 'sReplyText' if it is defined, otherwise define the value as an empty string
if(isset($_REQUEST['sReplyText']))
$aClean['sReplyText'] = makeSafe($_REQUEST['sReplyText']); $aClean['sReplyText'] = makeSafe($_REQUEST['sReplyText']);
else
$aClean['sReplyText'] = "";
$oApp = new Application($this->iAppId); $oApp = new Application($this->iAppId);
switch($sAction) switch($sAction)

View File

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

View File

@@ -249,13 +249,13 @@ function create_and_login_user()
if(!test_application_delete()) if(!test_application_delete())
echo "test_application_delete() failed!\n"; echo "test_application_delete() failed!\n";
else else
echo "test_application_delete() passed!\n"; echo "test_application_delete() passed\n";
if(!test_application_getWithRating()) if(!test_application_getWithRating())
echo "test_application_getWithRating() failed!\n"; echo "test_application_getWithRating() failed!\n";
else 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("path.php");
require_once("test_common.php"); require_once("test_common.php");
DEFINE(TEST_IMAGE_FILENAME, "/images/appdb_montage.jpg"); DEFINE("TEST_IMAGE_FILENAME", "/images/appdb_montage.jpg");
DEFINE(TEST_IMAGE_OUTPUT_FILENAME, "/tmp/tmpfile.png"); DEFINE("TEST_IMAGE_OUTPUT_FILENAME", "/tmp/tmpfile.png");
DEFINE(TEST_IMAGE_WIDTH, 391); DEFINE("TEST_IMAGE_WIDTH", 391);
DEFINE(TEST_IMAGE_HEIGHT, 266); DEFINE("TEST_IMAGE_HEIGHT", 266);
DEFINE(TEST_IMAGE_WATERMARK, "/images/watermark.png"); DEFINE("TEST_IMAGE_WATERMARK", "/images/watermark.png");
function test_image_constructor() function test_image_constructor()
{ {
@@ -73,7 +73,7 @@ function test_image_make_thumbnail()
from the ratio of the height from the ratio of the height
to width of the original image */ to width of the original image */
$iBorderWidth = 20; $iBorderWidth = 20;
$oImage->make_thumb($iWidth, $iHeight, $iBorderWidthm, "#0000FF"); $oImage->make_thumb($iWidth, $iHeight, $iBorderWidth, "#0000FF");
/* did we get the correct size? */ /* did we get the correct size? */
$iActualWidth = $oImage->get_width(); $iActualWidth = $oImage->get_width();

View File

@@ -121,7 +121,7 @@ function test_query_parameters()
if(!test_query_parameters()) if(!test_query_parameters())
echo "test_query_parameters() failed!\n"; echo "test_query_parameters() failed!\n";
else 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->delete();
$oUser = new User(); $oUser = new User();
} else
{
echo "User doesn't already exist\n";
} }
/* create the user */ /* 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 != SUCCESS)
{ {
if($retval == USER_CREATE_EXISTS) 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 */ /* 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) if($retval != USER_CREATE_EXISTS)
{ {
echo "Got '".$retval."' instead of USER_CREATE_EXISTS(".USER_CREATE_EXISTS.")\n"; 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); $retval = $oUser->login($test_email, $test_password);
if($retval != SUCCESS) if($retval != SUCCESS)
{ {
echo "Test that correct information results in a correct login FAILED\n";
echo "Got '".$retval."' instead of SUCCESS(".SUCCESS.")\n"; echo "Got '".$retval."' instead of SUCCESS(".SUCCESS.")\n";
return false; return false;
} }
/* test that incorrect user results in a login failed */ /* test that incorrect user results in a login failed */
$oUser = new User(); $oUser = new User();
$retval = $oUser->login("some nutty username", $testpassword); $retval = $oUser->login("some nutty username", $test_password);
if($retval != USER_LOGIN_FAILED) 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"; echo "Got '".$retval."' instead of SUCCESS(".SUCCESS.")\n";
return false; return false;
} }
@@ -86,6 +91,7 @@ function test_user_login()
$retval = $oUser->login($test_email, "some password"); $retval = $oUser->login($test_email, "some password");
if($retval != USER_LOGIN_FAILED) 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"; echo "Got '".$retval."' instead of SUCCESS(".SUCCESS.")\n";
return false; return false;
} }