我正在尝试为 cakephp 进行单元测试,我想知道是否有人可以提供一些关于如何为特定控制器方法编写测试的输入:
public function paymentmethod() {
$this->layout='dashboard';
$billingaddressInfo = $this->Dashboard->find('all',array('fields' => array('Address_book_id','first_name','last_name'),'conditions' => array('Dashboard.customer_id' => $this->Session->read('customer_id'),'address_type'=>'1')));
$billingaddress = array();
if(is_array($billingaddressInfo) && count($billingaddressInfo) > 0) {
foreach($billingaddressInfo as $key=>$value) {
$billingaddress[$value['Dashboard']['Address_book_id']] = $value['Dashboard']['first_name'].' '.$value['Dashboard']['last_name'];
}
}
$this->set('billingaddress',$billingaddress);
$fullbillingaddress = $this->Dashboard->find('all',array('fields' => array('Address_book_id','customer_id','first_name','last_name','address_line_1','address_line_2','city','state','country','zipcode'),
'conditions' => array('Dashboard.customer_id' =>$this->Session->read('customer_id'))));
$this->set('fullbillingaddress',$fullbillingaddress);
$shippingaddress = $this->Dashboard->find('list',array('fields' => array('first_name'),'conditions' => array('Dashboard.customer_id' => $this->Session->read('customer_id'),'address_type'=>'2')));
$this->set('shippingaddress',$shippingaddress);
$this->loadModel('Paymentmethod');
if(!empty ($this->request->data)) {
$getpaymentform = $this->request->data['Paymentmethod'];
$getpaymentform['card_number'] = $this->encryptCard($getpaymentform['card_number']);
if($this->request->data['Paymentmethod']['is_default']==1) {
$this->Paymentmethod->updateAll(array('is_default'=>'0'),array('Paymentmethod.customer_id' =>$this->Session->read('customer_id')));
}
$this->Paymentmethod->save($getpaymentform);
}
$paymentdata = $this->Paymentmethod->find('all',array('conditions' => array('Paymentmethod.customer_id' =>$this->Session->read('customer_id'))));
$this->set('paymentdata',$paymentdata);
$this->render();
if(!empty ($this->request->data)) {
$this->redirect(array('action'=>'paymentmethod'));
}
}
我真的在寻找关于测试方法的哪些部分以及断言什么的建议,我不是在寻找任何人来编写代码,而只是对你将如何处理这个问题进行有经验的评估。我对它很陌生,非常感谢一些输入。