/** * TODO: $attr не используется * @return \SQRT\Tag\Checkbox|CheckboxListing */ public function render($attr = null) { if ($this->getOptions()) { $tag = new CheckboxListing($this->getInputName(), $this->getOptions(), $this->getValue()); if ($this->getIgnoreOptionsKeys()) { $tag->setIgnoreOptionsKeys(true); } } else { $tag = new \SQRT\Tag\Checkbox($this->getInputName(), $this->getInputValue(), null, $this->getValue() == $this->getInputValue()); } return $tag; }
function testCheckboxListing() { $t = new Tag\CheckboxListing('age', array(10 => '10 лет', 20 => '20 лет', 30 => '30 лет'), 20); $exp = '<label><input name="age[]" type="checkbox" value="10" /> 10 лет</label>' . "\n" . '<label><input checked="checked" name="age[]" type="checkbox" value="20" /> 20 лет</label>' . "\n" . '<label><input name="age[]" type="checkbox" value="30" /> 30 лет</label>' . "\n"; $this->assertEquals($exp, $t->toHTML(), 'Выбрана одна опция'); $t->setSelected(array(10, 20)); $exp = '<label><input checked="checked" name="age[]" type="checkbox" value="10" /> 10 лет</label>' . "\n" . '<label><input checked="checked" name="age[]" type="checkbox" value="20" /> 20 лет</label>' . "\n" . '<label><input name="age[]" type="checkbox" value="30" /> 30 лет</label>' . "\n"; $this->assertEquals($exp, $t->toHTML(), 'Выбрано несколько опций'); }