Thursday, February 11, 2010

Zend PHPUnit check elements set by controller

When testing output from controllers in Zend using the Zend PHPUnit one might want to check the elements set by the controller, if they have the right values or exist at all.

Anything below top level form ($this->view->form = $form; in controller) one needs to use the getElement() function like one would in the controller. getSubForm() is also valid if there are subforms:

public function testRegisterViewObjectContainsProperties() {
$controller = new RegistrationController(
$this->request,
$this->response,
$this->request->getParams()
);
$controller->registerAction();

$this->assertTrue(isset($controller->view->form));

$this->assertTrue(isset($controller->view));
$this->assertTrue(isset($controller->view->form));
$username = $controller->view->form->getSubForm('userpass')->getElement('username');


http://www.contentwithstyle.co.uk/content/unit-testing-controllers-with-zend-framework seems to be useful.

No comments:

Post a Comment