Development

Changeset 8883

You must first sign up to be able to contribute.

Changeset 8883

Show
Ignore:
Timestamp:
05/09/08 15:58:04 (1 year ago)
Author:
fabien
Message:

added an exception when binding a multipart form without a files argument

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/lib/form/sfForm.class.php

    r8696 r8883  
    126126   * @param array An array of uploaded files (in the $_FILES or $_GET format) 
    127127   */ 
    128   public function bind(array $taintedValues = null, array $taintedFiles = array()
     128  public function bind(array $taintedValues = null, array $taintedFiles = null
    129129  { 
    130130    $this->taintedValues = $taintedValues; 
     
    136136    { 
    137137      $this->taintedValues = array(); 
     138    } 
     139 
     140    if (is_null($this->taintedFiles)) 
     141    { 
     142      if ($this->isMultipart()) 
     143      { 
     144        throw new InvalidArgumentException('This form is multipart, which means you need to supply a files array as the bind() method second argument.'); 
     145      } 
     146 
     147      $this->taintedFiles = array(); 
    138148    } 
    139149 
  • branches/1.1/test/unit/form/sfFormTest.php

    r8756 r8883  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(87, new lime_output_color()); 
     13$t = new lime_test(88, new lime_output_color()); 
    1414 
    1515class FormTest extends sfForm 
     
    214214  'file' => new sfValidatorFile(array('max_size' => 2)), 
    215215))); 
    216 $f->bind(array( 
    217   1 => 'f', 
    218   2 => 'potencier', 
    219   'file' => array('name' => 'test1.txt', 'type' => 'text/plain', 'tmp_name' => '/tmp/test1.txt', 'error' => 0, 'size' => 100)) 
    220 ); 
     216$f->setWidgetSchema(new sfWidgetFormSchema(array('file' => new sfWidgetFormInputFile()))); 
     217$f->bind(array(1 => 'f', 2 => 'potencier'), array( 
     218  'file' => array('name' => 'test1.txt', 'type' => 'text/plain', 'tmp_name' => '/tmp/test1.txt', 'error' => 0, 'size' => 100) 
     219)); 
    221220$t->is($f->getErrorSchema()->getCode(), '1 [min_length] file [max_size]', '->bind() behaves correctly with files'); 
     221 
     222try 
     223{ 
     224  $f->bind(array(1 => 'f', 2 => 'potencier')); 
     225  $t->fail('->bind() second argument is mandatory if the form is multipart'); 
     226} 
     227catch (InvalidArgumentException $e) 
     228{ 
     229  $t->pass('->bind() second argument is mandatory if the form is multipart'); 
     230} 
    222231 
    223232// ->renderGlobalErrors() 

The Sensio Labs Network

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