Development

Changeset 4883

You must first sign up to be able to contribute.

Changeset 4883

Show
Ignore:
Timestamp:
08/20/07 16:15:13 (2 years ago)
Author:
fabien
Message:

fixed fillInFormFilter can't find form with content_type = xml (closes #1687)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.0/lib/util/sfFillInForm.class.php

    r2976 r4883  
    1919{ 
    2020  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'); 
    2424 
    2525  public function addConverter($callable, $fields) 
     
    6464  { 
    6565    $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)'; 
    6877    foreach ($this->types as $type) 
    6978    { 
    7079      $query .= ' or @type="'.$type.'"'; 
    7180    } 
    72     $query .= ')] | descendant::textarea[@name] | descendant::select[@name]'; 
     81    $query .= ')] | descendant::'.$ns.'textarea[@name] | descendant::'.$ns.'select[@name]'; 
    7382 
    7483    // find our form 
    7584    if ($formName) 
    7685    { 
    77       $xpath_query = '//form[@name="'.$formName.'"]'; 
     86      $xpath_query = '//'.$ns.'form[@name="'.$formName.'"]'; 
    7887    } 
    7988    elseif ($formId) 
    8089    { 
    81       $xpath_query = '//form[@id="'.$formId.'"]'; 
     90      $xpath_query = '//'.$ns.'form[@id="'.$formId.'"]'; 
    8291    } 
    8392    else 
    8493    { 
    85       $xpath_query = '//form'; 
     94      $xpath_query = '//'.$ns.'form'; 
    8695    } 
    8796 
     
    143152        $value    = $this->getValue($values, $name); 
    144153        $multiple = $element->hasAttribute('multiple'); 
    145         foreach ($xpath->query('descendant::option', $element) as $option) 
     154        foreach ($xpath->query('descendant::'.$ns.'option', $element) as $option) 
    146155        { 
    147156          $option->removeAttribute('selected'); 
  • branches/1.0/test/unit/util/sfFillInFormTest.php

    r2678 r4883  
    1212require_once($_test_dir.'/../lib/util/sfFillInForm.class.php'); 
    1313 
    14 $t = new lime_test(46, new lime_output_color()); 
     14$t = new lime_test(50, new lime_output_color()); 
    1515 
    1616$html = <<<EOF 
     
    189189  return (string) $values[0][$attribute]; 
    190190} 
     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> 
     204EOF; 
     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> 
     217EOF; 
     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> 
     233EOF; 
     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> 
     246EOF; 
     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'); 

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting.
Sensio Labs also supports several large Open-Source projects.