view = new Zend_View(); $this->helper = new Zend_View_Helper_Form(); $this->helper->setView($this->view); } /** * Tears down the fixture, for example, close a network connection. * This method is called after a test is executed. * * @access protected */ protected function tearDown() { } public function testFormWithSaneInput() { $form = $this->helper->form('foo', array('action' => '/foo', 'method' => 'get')); $this->assertRegexp('/]*(id="foo")/', $form); $this->assertRegexp('/]*(action="\/foo")/', $form); $this->assertRegexp('/]*(method="get")/', $form); } public function testFormWithInputNeedingEscapesUsesViewEscaping() { $form = $this->helper->form('<&foo'); $this->assertContains($this->view->escape('<&foo'), $form); } /** * @group ZF-3832 */ public function testEmptyIdShouldNotRenderIdAttribute() { $form = $this->helper->form('', array('action' => '/foo', 'method' => 'get')); $this->assertNotRegexp('/]*(id="")/', $form); $form = $this->helper->form('', array('action' => '/foo', 'method' => 'get', 'id' => null)); $this->assertNotRegexp('/]*(id="")/', $form); } /** * @group ZF-10791 */ public function testPassingNameAsAttributeShouldOverrideFormName() { $form = $this->helper->form('OrigName', array('action' => '/foo', 'method' => 'get', 'name' => 'SomeNameAttr')); $this->assertNotRegexp('/]*(name="OrigName")/', $form); $this->assertRegexp('/]*(name="SomeNameAttr")/', $form); } /** * @group ZF-10791 */ public function testNotSpecifyingFormNameShouldNotRenderNameAttrib() { $form = $this->helper->form('', array('action' => '/foo', 'method' => 'get')); $this->assertNotRegexp('/]*(name=".*")/', $form); } /** * @group ZF-10791 */ public function testSpecifyingFormNameShouldRenderNameAttrib() { $form = $this->helper->form('FormName', array('action' => '/foo', 'method' => 'get')); $this->assertRegexp('/]*(name="FormName")/', $form); } /** * @group ZF-10791 */ public function testPassingEmptyNameAttributeToUnnamedFormShouldNotRenderNameAttrib() { $form = $this->helper->form('', array('action' => '/foo', 'method' => 'get', 'name' => NULL)); $this->assertNotRegexp('/]*(name=".*")/', $form); } /** * @group ZF-10791 */ public function testPassingEmptyNameAttributeToNamedFormShouldNotOverrideNameAttrib() { $form = $this->helper->form('RealName', array('action' => '/foo', 'method' => 'get', 'name' => NULL)); $this->assertRegexp('/]*(name="RealName")/', $form); } /** * @group ZF-10791 */ public function testNameAttributeShouldBeOmittedWhenUsingXhtml1Strict() { $this->view->doctype('XHTML1_STRICT'); $form = $this->helper->form('FormName', array('action' => '/foo', 'method' => 'get')); $this->assertNotRegexp('/]*(name="FormName")/', $form); } /** * @group ZF-10791 */ public function testNameAttributeShouldBeOmittedWhenUsingXhtml11() { $this->view->doctype('XHTML11'); $form = $this->helper->form('FormName', array('action' => '/foo', 'method' => 'get')); $this->assertNotRegexp('/]*(name="FormName")/', $form); } } // Call Zend_View_Helper_FormTest::main() if this source file is executed directly. if (PHPUnit_MAIN_METHOD == "Zend_View_Helper_FormTest::main") { Zend_View_Helper_FormTest::main(); }