view = new Zend_View(); $this->helper = new Zend_View_Helper_FormSelect(); $this->helper->setView($this->view); } /** * Tears down the fixture, for example, close a network connection. * This method is called after a test is executed. * * @return void */ public function tearDown() { unset($this->helper, $this->view); } public function testFormSelectWithNameOnlyCreatesEmptySelect() { $html = $this->helper->formSelect('foo'); $this->assertRegExp('#]+name="foo"#', $html); $this->assertContains('', $html); $this->assertNotContains('helper->formSelect('foo', null, null, array('foo' => 'Foobar', 'baz' => 'Bazbat')); $this->assertRegExp('#]+name="foo"#', $html); $this->assertContains('', $html); $this->assertRegExp('#]+value="foo".*?>Foobar#', $html); $this->assertRegExp('#]+value="baz".*?>Bazbat#', $html); $this->assertEquals(2, substr_count($html, 'helper->formSelect('foo', 'baz', null, array('foo' => 'Foobar', 'baz' => 'Bazbat')); $this->assertRegExp('#]+value="baz"[^>]*selected.*?>Bazbat#', $html); } public function testFormSelectWithMultipleAttributeCreatesMultiSelect() { $html = $this->helper->formSelect('foo', null, array('multiple' => true), array('foo' => 'Foobar', 'baz' => 'Bazbat')); $this->assertRegExp('#]+name="foo\[\]"#', $html); $this->assertRegExp('#]+multiple="multiple"#', $html); } public function testFormSelectWithMultipleAttributeAndValuesCreatesMultiSelectWithSelectedValues() { $html = $this->helper->formSelect('foo', array('foo', 'baz'), array('multiple' => true), array('foo' => 'Foobar', 'baz' => 'Bazbat')); $this->assertRegExp('#]+value="foo"[^>]*selected.*?>Foobar#', $html); $this->assertRegExp('#]+value="baz"[^>]*selected.*?>Bazbat#', $html); } /** * ZF-1930 * @return void */ public function testFormSelectWithZeroValueSelectsValue() { $html = $this->helper->formSelect('foo', 0, null, array('foo' => 'Foobar', 0 => 'Bazbat')); $this->assertRegExp('#]+value="0"[^>]*selected.*?>Bazbat#', $html); } /** * ZF-2513 */ public function testCanDisableEntireSelect() { $html = $this->helper->formSelect(array( 'name' => 'baz', 'options' => array( 'foo' => 'Foo', 'bar' => 'Bar' ), 'attribs' => array( 'disable' => true ), )); $this->assertRegexp('/]*?disabled/', $html, $html); $this->assertNotRegexp('/]*?disabled="disabled"/', $html, $html); } /** * ZF-2513 */ public function testCanDisableIndividualSelectOptionsOnly() { $html = $this->helper->formSelect(array( 'name' => 'baz', 'options' => array( 'foo' => 'Foo', 'bar' => 'Bar' ), 'attribs' => array( 'disable' => array('bar') ), )); $this->assertNotRegexp('/]*?disabled/', $html, $html); $this->assertRegexp('/