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('/]*?disabled="disabled"/', $html, $html);
$html = $this->helper->formSelect(
'baz',
'foo',
array(
'disable' => array('bar')
),
array(
'foo' => 'Foo',
'bar' => 'Bar'
)
);
$this->assertNotRegexp('/]*?disabled/', $html, $html);
$this->assertRegexp('/]*?disabled="disabled"/', $html, $html);
}
/**
* ZF-2513
*/
public function testCanDisableMultipleSelectOptions()
{
$html = $this->helper->formSelect(array(
'name' => 'baz',
'options' => array(
'foo' => 'Foo',
'bar' => 'Bar',
'baz' => 'Baz,'
),
'attribs' => array(
'disable' => array('foo', 'baz')
),
));
$this->assertNotRegexp('/]*?disabled/', $html, $html);
$this->assertRegexp('/]*?disabled="disabled"/', $html, $html);
$this->assertRegexp('/ ]*?disabled="disabled"/', $html, $html);
}
/**
* ZF-2513
*/
public function testCanDisableOptGroups()
{
$html = $this->helper->formSelect(array(
'name' => 'baz',
'options' => array(
'foo' => 'Foo',
'bar' => array(
'1' => 'one',
'2' => 'two'
),
'baz' => 'Baz,'
),
'attribs' => array(
'disable' => array('bar')
),
));
$this->assertNotRegexp('/]*?disabled/', $html, $html);
$this->assertRegexp('/]*?disabled="disabled"[^>]*?"bar"[^>]*?/', $html, $html);
$this->assertNotRegexp('/]*?disabled="disabled"/', $html, $html);
$this->assertNotRegexp('/ ]*?disabled="disabled"/', $html, $html);
}
/**
* ZF-2513
*/
public function testCanDisableOptGroupOptions()
{
$html = $this->helper->formSelect(array(
'name' => 'baz',
'options' => array(
'foo' => 'Foo',
'bar' => array(
'1' => 'one',
'2' => 'two'
),
'baz' => 'Baz,'
),
'attribs' => array(
'disable' => array('2')
),
));
$this->assertNotRegexp('/]*?disabled/', $html, $html);
$this->assertNotRegexp('/]*?disabled="disabled"[^>]*?"bar"[^>]*?/', $html, $html);
$this->assertNotRegexp('/]*?disabled="disabled"/', $html, $html);
$this->assertRegexp('/ ]*?disabled="disabled"/', $html, $html);
}
public function testCanSpecifySelectMultipleThroughAttribute()
{
$html = $this->helper->formSelect(array(
'name' => 'baz',
'options' => array(
'foo' => 'Foo',
'bar' => 'Bar',
'baz' => 'Baz,'
),
'attribs' => array(
'multiple' => true
),
));
$this->assertRegexp('/]*?(multiple="multiple")/', $html, $html);
}
public function testSpecifyingSelectMultipleThroughAttributeAppendsNameWithBrackets()
{
$html = $this->helper->formSelect(array(
'name' => 'baz',
'options' => array(
'foo' => 'Foo',
'bar' => 'Bar',
'baz' => 'Baz,'
),
'attribs' => array(
'multiple' => true
),
));
$this->assertRegexp('/]*?(name="baz\[\]")/', $html, $html);
}
public function testCanSpecifySelectMultipleThroughName()
{
$html = $this->helper->formSelect(array(
'name' => 'baz[]',
'options' => array(
'foo' => 'Foo',
'bar' => 'Bar',
'baz' => 'Baz,'
),
));
$this->assertRegexp('/]*?(multiple="multiple")/', $html, $html);
}
/**
* ZF-1639
*/
public function testNameCanContainBracketsButNotBeMultiple()
{
$html = $this->helper->formSelect(array(
'name' => 'baz[]',
'options' => array(
'foo' => 'Foo',
'bar' => 'Bar',
'baz' => 'Baz,'
),
'attribs' => array(
'multiple' => false
),
));
$this->assertRegexp('/]*?(name="baz\[\]")/', $html, $html);
$this->assertNotRegexp('/]*?(multiple="multiple")/', $html, $html);
}
}
// Call Zend_View_Helper_FormSelectTest::main() if this source file is executed directly.
if (PHPUnit_MAIN_METHOD == "Zend_View_Helper_FormSelectTest::main") {
Zend_View_Helper_FormSelectTest::main();
}