Changeset 8695
- Timestamp:
- 04/30/08 18:21:59 (6 months ago)
- Files:
-
- branches/1.0/lib/util/sfFillInForm.class.php (modified) (1 diff)
- branches/1.0/test/unit/util/sfFillInFormTest.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.0/lib/util/sfFillInForm.class.php
r4883 r8695 126 126 // checkbox and radio 127 127 $element->removeAttribute('checked'); 128 if ($this->hasValue($values, $name) && ($this->getValue($values, $name) == $value || !$element->hasAttribute('value'))) 128 if (is_array($this->getValue($values, $name)) && ($this->hasValue($values, $name) || !$element->hasAttribute('value'))) 129 { 130 if (in_array($value, $this->getValue($values, $name))) 131 { 132 $element->setAttribute('checked', 'checked'); 133 } 134 } 135 else if ($this->hasValue($values, $name) && ($this->getValue($values, $name) == $value || !$element->hasAttribute('value'))) 129 136 { 130 137 $element->setAttribute('checked', 'checked'); branches/1.0/test/unit/util/sfFillInFormTest.php
r4883 r8695 12 12 require_once($_test_dir.'/../lib/util/sfFillInForm.class.php'); 13 13 14 $t = new lime_test(5 0, new lime_output_color());14 $t = new lime_test(53, new lime_output_color()); 15 15 16 16 $html = <<<EOF … … 23 23 <input type="checkbox" name="input_checkbox" value="1" checked="checked" /> 24 24 <input type="checkbox" name="input_checkbox_not_checked" value="1" /> 25 <input type="checkbox" name="input_checkbox_multiple[]" value="1" checked="checked" /> 26 <input type="checkbox" name="input_checkbox_multiple[]" value="2" /> 27 <input type="radio" name="input_radio" value="1" checked="checked" /> 25 28 <input type="password" name="password" value="" /> 26 29 <textarea name="textarea">content</textarea> … … 71 74 $t->is(get_input_value($xml, 'input_checkbox', 'checked'), 'checked', '->fillInDom() preserves default values for checkbox'); 72 75 $t->is(get_input_value($xml, 'input_checkbox_not_checked', 'checked'), '', '->fillInDom() preserves default values for checkbox'); 76 $t->is(get_input_value($xml, 'input_radio', 'checked'), 'checked', '->fillInDom() preserves default values for radio'); 77 $t->is(get_input_value($xml, 'input_checkbox_multiple[]', 'checked'), array('checked', null), '->fillInDom() preserves default values for multiple checkboxes'); 73 78 $t->is($xml->xpath('//form[@name="form1"]/textarea'), array('content'), '->fillInDom() preserves default values for textarea'); 74 79 $t->is($xml->xpath('//form[@name="form1"]/select[@name="select"]/option[@selected="selected"]'), array('selected'), '->fillInDom() preserves default values for select'); … … 123 128 'input_checkbox' => false, 124 129 'input_checkbox_not_checked' => true, 130 'input_checkbox_multiple[]' => array(2), 125 131 'password' => 'mypassword', 126 132 'select' => 'first', … … 139 145 $t->is(get_input_value($xml, 'input_checkbox', 'checked'), '', '->fillInDom() fills in values for checkbox'); 140 146 $t->is(get_input_value($xml, 'input_checkbox_not_checked', 'checked'), 'checked', '->fillInDom() fills in values for checkbox'); 147 $t->is(get_input_value($xml, 'input_checkbox_multiple[]', 'checked'), array(null, 'checked'), '->fillInDom() fills in values for multiple checkboxes'); 141 148 $t->is($xml->xpath('//form[@name="form1"]/textarea'), array('my content'), '->fillInDom() fills in values for textarea'); 142 149 $t->is($xml->xpath('//form[@name="form1"]/select[@name="select"]/option[@selected="selected"]'), array('first'), '->fillInDom() fills in values for select'); … … 183 190 function get_input_value($xml, $name, $attribute = 'value', $form = null) 184 191 { 192 $value = ""; 193 185 194 $xpath = ($form ? '//form[@name="'.$form.'"]' : '//form').sprintf('/input[@name="%s"]', $name); 186 195 187 196 $values = $xml->xpath($xpath); 188 197 189 return (string) $values[0][$attribute]; 198 if (count($values) > 1) 199 { 200 foreach($values as $val) 201 { 202 $value[] = $val[$attribute]; 203 } 204 } 205 else 206 { 207 $value = (string) $values[0][$attribute]; 208 } 209 210 return $value; 190 211 } 191 212