在下面的代码中,反馈表单需要输入 3 个字段,例如姓名、电子邮件 ID 和评论。所以验证需要使用 phpunit test 进行测试。请帮忙。我完全是 php 语法的新手。如何断言和检查验证以在 phunit 测试中提供报告。
if($_POST){
//echo $sRc;
//print "<pre>";print_r($_POST);exit;
require_once(CLASSPATH."/utility.class.php");
$oUtility = new utility();
$sRc = base64_decode($_COOKIE['Rc_cf']);
$sEmail = trim($_POST['emailid']);
$scomment = trim($_POST['comment']);
$syour_name = trim($_POST['your_name']);
$sOthereSubject = trim($_POST['subject']);
$sName = trim(strip_tags($oUtility->nonxmlcharreplace($_REQUEST['your_name'])));
$sEmail = trim(strip_tags($oUtility->nonxmlcharreplace($_REQUEST['emailid'])));
$sComments = trim(strip_tags($oUtility->nonxmlcharreplace($_REQUEST['comment'])));
$iError=0;
$sErrorMsg="";
if(strlen($sName)==0){
$sErrorMsg="Your name cannot be blank.";
$iError=1;
} else if(strlen($sEmail)==0){
$sErrorMsg="Email address cannot be blank.";
$iError=1;
}else if(strlen($sEmail)>0){
$iValid = $oUtility->isValidEmail($sEmail);
if($iValid!=1){
$sErrorMsg="Please enter valid email address.";
$iError=1;
}
}
if(empty($sComments) && strlen($sErrorMsg)==0){
$sErrorMsg="Comment cannot be blank.";
$iError=1;
}
if(strlen($sErrorMsg)==0){
require_once(CLASSPATH."feedback.class.php");
$oFeedback = new feedback();
if($iError==0){
$aParameters=Array('name'=>$sName,'email'=>$sEmail,'comments'=>$sComments,'cdate'=>'now()', 'is_active'=>1,'cdate'=>'now()','udate'=>'now()');
$iRes = $oFeedback->addUpdFeedback($aParameters);
$sInserMsg = 1;
$sEmail = $sName = $scomment='';
}
}