public function test_checkbox_tag() { $actual = FormTagHelper::checkbox_tag('passed'); $matcher = array('tag' => 'input', 'attributes' => array('type' => 'checkbox', 'name' => 'passed', 'id' => 'passed', 'value' => '1', 'checked' => null)); $this->assertTag($matcher, $actual, 'Default attributes'); $actual = FormTagHelper::checkbox_tag('passed', 1, true); $this->assertRegexp('/checked="checked"/', $actual, "Checked box"); $actual = FormTagHelper::checkbox_tag('foo', 1, false, array('class' => 'blah')); $this->assertRegexp('/class="blah"/', $actual, "Additional attributes"); }
public function grouped_checkbox($name, $tag_value, $html_attributes = array()) { $values = $this->get_model_data($name); $name = substr($name, -2, 2) == '[]' ? $name : $name . '[]'; $checked = is_array($values) ? in_array($tag_value, $values) : $tag_value == $values; $id = FormTagHelper::sanitize_id($name) . '_' . FormTagHelper::sanitize_id($tag_value); $html_attributes = array_merge(array('id' => $id), $html_attributes); return FormTagHelper::checkbox_tag($this->get_field_name($name), $tag_value, $checked, $html_attributes); }