Changeset 4883
- Timestamp:
- 08/20/07 16:15:13 (2 years ago)
- Files:
-
- branches/1.0/lib/util/sfFillInForm.class.php (modified) (3 diffs)
- branches/1.0/test/unit/util/sfFillInFormTest.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.0/lib/util/sfFillInForm.class.php
r2976 r4883 19 19 { 20 20 protected 21 $converters = array(),22 $skipFields = array(),23 $types = array('text', 'checkbox', 'radio', 'hidden', 'password');21 $converters = array(), 22 $skipFields = array(), 23 $types = array('text', 'checkbox', 'radio', 'hidden', 'password'); 24 24 25 25 public function addConverter($callable, $fields) … … 64 64 { 65 65 $xpath = new DomXPath($dom); 66 67 $query = 'descendant::input[@name and (not(@type)'; 66 if ($dom->documentElement && $dom->documentElement->namespaceURI) 67 { 68 $xpath->registerNamespace('xhtml', $dom->documentElement->namespaceURI); 69 $ns = 'xhtml:'; 70 } 71 else 72 { 73 $ns = ''; 74 } 75 76 $query = 'descendant::'.$ns.'input[@name and (not(@type)'; 68 77 foreach ($this->types as $type) 69 78 { 70 79 $query .= ' or @type="'.$type.'"'; 71 80 } 72 $query .= ')] | descendant:: textarea[@name] | descendant::select[@name]';81 $query .= ')] | descendant::'.$ns.'textarea[@name] | descendant::'.$ns.'select[@name]'; 73 82 74 83 // find our form 75 84 if ($formName) 76 85 { 77 $xpath_query = '// form[@name="'.$formName.'"]';86 $xpath_query = '//'.$ns.'form[@name="'.$formName.'"]'; 78 87 } 79 88 elseif ($formId) 80 89 { 81 $xpath_query = '// form[@id="'.$formId.'"]';90 $xpath_query = '//'.$ns.'form[@id="'.$formId.'"]'; 82 91 } 83 92 else 84 93 { 85 $xpath_query = '// form';94 $xpath_query = '//'.$ns.'form'; 86 95 } 87 96 … … 143 152 $value = $this->getValue($values, $name); 144 153 $multiple = $element->hasAttribute('multiple'); 145 foreach ($xpath->query('descendant:: option', $element) as $option)154 foreach ($xpath->query('descendant::'.$ns.'option', $element) as $option) 146 155 { 147 156 $option->removeAttribute('selected'); branches/1.0/test/unit/util/sfFillInFormTest.php
r2678 r4883 12 12 require_once($_test_dir.'/../lib/util/sfFillInForm.class.php'); 13 13 14 $t = new lime_test( 46, new lime_output_color());14 $t = new lime_test(50, new lime_output_color()); 15 15 16 16 $html = <<<EOF … … 189 189 return (string) $values[0][$attribute]; 190 190 } 191 192 // ->fillInXml() 193 $t->diag('->fillInXml()'); 194 $f = new sfFillInForm(); 195 196 $xml = <<<EOF 197 <html> 198 <body> 199 <form action="#" method="post" name="form"> 200 <input type="text" name="foo" /> 201 </form> 202 </body> 203 </html> 204 EOF; 205 $xml = $f->fillInXml($xml, 'form', null, array('foo' => 'bar')); 206 $t->like($xml, '#<input type="text" name="foo" value="bar"\s*/>#', '->fillInXml() outputs valid XML'); 207 208 $xml = <<<EOF 209 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 210 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> 211 <body> 212 <form action="#" method="post" name="form"> 213 <input type="text" name="foo" /> 214 </form> 215 </body> 216 </html> 217 EOF; 218 $xml = $f->fillInXml($xml, 'form', null, array('foo' => 'bar')); 219 $t->like($xml, '#<input type="text" name="foo" value="bar"\s*/>#', '->fillInXml() outputs valid XML'); 220 221 // ->fillInHtml() 222 $t->diag('->fillInHtml()'); 223 $f = new sfFillInForm(); 224 225 $xml = <<<EOF 226 <html> 227 <body> 228 <form action="#" method="post" name="form"> 229 <input type="text" name="foo"> 230 </form> 231 </body> 232 </html> 233 EOF; 234 $xml = $f->fillInHtml($xml, 'form', null, array('foo' => 'bar')); 235 $t->like($xml, '#<input type="text" name="foo" value="bar">#', '->fillInHtml() outputs valid HTML'); 236 237 $xml = <<<EOF 238 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 239 <html lang="en"> 240 <body> 241 <form action="#" method="post" name="form"> 242 <input type="text" name="foo"> 243 </form> 244 </body> 245 </html> 246 EOF; 247 $xml = $f->fillInHtml($xml, 'form', null, array('foo' => 'bar')); 248 $t->like($xml, '#<input type="text" name="foo" value="bar">#', '->fillInHtml() outputs valid HTML');

