public function testAddOptionToOptgroup() { $sel = new HTML_QuickForm2_Element_Select(); $optgroup = $sel->addOptgroup('Label'); $optgroup->addOption('Text', 'Value'); $this->assertRegExp('!^<select[^>]*>\\s*<optgroup[^>]+label="Label"[^>]*>\\s*' . '<option[^>]+value="Value"[^>]*>Text</option>\\s*</optgroup>\\s*</select>!', $sel->__toString()); $sel2 = new HTML_QuickForm2_Element_Select(); $optgroup2 = $sel2->addOptgroup('Label'); $optgroup2->addOption('Text', 'Value', array('class' => 'bar')); $this->assertRegExp('!<optgroup[^>]+label="Label"[^>]*>\\s*<option[^>]+class="bar"[^>]*>Text</option>\\s*</optgroup>!', $sel2->__toString()); $sel3 = new HTML_QuickForm2_Element_Select(); $optgroup3 = $sel3->addOptgroup('Label'); $optgroup3->addOption('Text', 'Value', array('selected')); $this->assertEquals('Value', $sel3->getValue()); $this->assertRegExp('!<optgroup[^>]+label="Label"[^>]*>\\s*<option[^>]+selected="selected"[^>]*>Text</option>\\s*</optgroup>!', $sel3->__toString()); }
function getValue() { $value = parent::getValue(); return $value == null ? array() : $value; }
/** * Disable possibleValues checks in getValue() * * For lazy people who add options to selects on client side and do not * want to add the same stuff server-side * * @link http://pear.php.net/bugs/bug.php?id=13088 * @link http://pear.php.net/bugs/bug.php?id=16974 */ public function testDisableIntrinsicValidation() { $selectSingle = new HTML_QuickForm2_Element_Select('foo', null, array('intrinsic_validation' => false)); $selectSingle->setValue('foo'); $this->assertEquals('foo', $selectSingle->getValue()); $selectSingle->loadOptions(array('one' => 'First', 'two' => 'Second')); $selectSingle->setValue('three'); $this->assertEquals('three', $selectSingle->getValue()); $selectMultiple = new HTML_QuickForm2_Element_Select('bar', array('multiple'), array('intrinsic_validation' => false)); $selectMultiple->loadOptions(array('one' => 'First', 'two' => 'Second')); $selectMultiple->setValue(array('two', 'three')); $this->assertEquals(array('two', 'three'), $selectMultiple->getValue()); }
public function testSelectMultipleNonRecursive() { $s = new HTML_QuickForm2_Element_Select('foo', array('multiple' => 'multiple'), array('intrinsic_validation' => false)); $s->setValue(array('foo', 'bar')); $s->addFilter('count'); $this->assertEquals(2, $s->getValue()); }