public function testPost_handlerFails() { $_POST = array('action1' => 1, 'numericfield1' => '10', 'textfield1' => 'text-value'); $handler = new DualActionHandler(false); Form::setupForm($this->smarty, $handler); $html = $this->smarty->fetch(__DIR__ . '/exampleform.tpl'); $xml = new SimpleXmlElement('<xml>' . $html . '</xml>'); // if the handler fails we expece the form to contain the user data, and generic error message to be there $this->assertEquals('text-value', $xml->form[0]->div[0]->input['value']); $this->assertEquals('mf_formstatus', $xml->form[0]->p['class']); }
public function testRender() { Form::setupForm($this->smarty, new DualActionHandler()); $html = $this->smarty->fetch(__DIR__ . '/exampleform.tpl'); $xml = new SimpleXmlElement('<xml>' . $html . '</xml>'); // assert the form exists $this->assertNodeExist($xml->form[0]); // assert the first label/input exists $this->assertNodeExist($xml->form->div[0]->label); $this->assertNodeExist($xml->form->div[0]->input); // assert the second label/input exists $this->assertNodeExist($xml->form->div[1]->label); $this->assertNodeExist($xml->form->div[1]->input); // assert the buttons exist $this->assertNodeExist($xml->form->input[0]); $this->assertNodeExist($xml->form->button[0]); }
/** * Add a form to the view, and use the given handler to * * @param Handler $handler The name of the handler */ protected function handleForm($handler) { $this->initializeView(); \MistyForms\Form::setupForm($this->view, $handler); }