Thursday, February 11, 2010

Zend PHPUnit posting to controller

Sending data to the controller to check what you get back can be tricky. Especially if you have subforms or file uploads.

Here is how if you have subforms (in this case a select and a multiselect in separate subforms):
public function testPostMissingFilledFields() {
$this ->request ->setMethod('POST')
//Selected element with value '2'
'firstLayerSubform1' =>
array('secondLayerSubform1' =>
array('thirdLayerSubform1' =>
array('select' => array('2')))),
//Selected elements with values 1159 and 1161
'firstLayerSubform2' =>
array('secondLayerSubform2' =>
array('thirdLayerSubform2' =>
array('multiselect' => array('1159', '1161')))),

Useful functions to see what you submit look like are:
In Test file:
In controller:

If you find a way to check for uploaded files please tell me. :)

No comments:

Post a Comment