Exemple #1
0
 public function select($name, $choices, $options = array(), $html_attributes = array())
 {
     $value = strval($this->get_model_data($name));
     $option_tags = $this->add_default_select_options(FormTagHelper::options_for_select($choices, $value), $options, $value);
     return FormTagHelper::select_tag($this->get_field_name($name), $option_tags, $html_attributes);
 }
 public function test_select_tag()
 {
     $actual = FormTagHelper::select_tag('foo');
     $matcher = array('tag' => 'select', 'attributes' => array('name' => 'foo'), 'content' => null);
     $this->assertTag($matcher, $actual, 'Default attributes');
     $actual = FormTagHelper::select_tag('foo', '<option>Bar</option>');
     $matcher = array('tag' => 'select', 'attributes' => array('id' => 'foo', 'name' => 'foo'), 'descendant' => array('tag' => 'option', 'content' => 'Bar'));
     $this->assertTag($matcher, $actual, 'with options');
     $actual = FormTagHelper::select_tag('foo', null, array('multiple' => true));
     $this->assertRegexp('/name="foo\\[\\]"/', $actual, "Multiple select");
     $actual = FormTagHelper::select_tag('foo[]', null, array('multiple' => true));
     $this->assertRegexp('/name="foo\\[\\]"/', $actual, "Multiple select with brackets already in name");
     $actual = FormTagHelper::select_tag('foo', null, array('class' => 'blah'));
     $this->assertRegexp('/class="blah"/', $actual, "Additional attributes");
 }