public function testBug11138() { $options = array('2' => 'TwoWithoutZero', '02' => 'TwoWithZero'); $sel = new HTML_QuickForm2_Element_Select('bug11138'); $sel->loadOptions($options); $sel->setValue('02'); $selHtml = $sel->__toString(); $this->assertRegExp('!selected="selected"[^>]*>TwoWithZero!', $selHtml); $this->assertNotRegExp('!selected="selected"[^>]*>TwoWithoutZero!', $selHtml); $sel->toggleFrozen(true); $selFrozen = $sel->__toString(); $this->assertContains('TwoWithZero', $selFrozen); $this->assertContains('value="02"', $selFrozen); $this->assertNotContains('TwoWithoutZero', $selFrozen); $this->assertNotContains('value="2"', $selFrozen); }
/** * 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()); }
function setValue($value) { parent::setValue($value); $options = $this->optionContainer->getOptions(); $before = $options; foreach ($options as $k => $val) { if (($key = array_search($val['attr']['value'], $this->values)) !== false) { $options[$k]['attr']['data-sort_order'] = 1000 - $key; } else { $options[$k]['attr']['data-sort_order'] = 0; } } $this->optionContainer = new HTML_QuickForm2_Element_Select_OptionContainer($this->values, $this->possibleValues); //reset options foreach ($options as $k => $val) { $this->optionContainer->addOption($val['text'], $val['attr']['value'], $val['attr']); } $this->setAttribute('data-value', json_encode($this->values)); return $this; }
/** * @see http://pear.php.net/bugs/bug.php?id=12610 */ function testValidateSelectMultiple() { $options = array('1' => 'Option 1', '2' => 'Option 2'); $multiSelect = new HTML_QuickForm2_Element_Select('mult', array('multiple'), array('options' => $options)); $nonEmpty = new HTML_QuickForm2_Rule_Nonempty($multiSelect, 'an error'); $this->assertFalse($nonEmpty->validate()); $multiSelect->setValue(array(1)); $this->assertTrue($nonEmpty->validate()); $nonEmpty->setConfig(2); $this->assertFalse($nonEmpty->validate()); }