Development

Changeset 17587

You must first sign up to be able to contribute.

Changeset 17587

Show
Ignore:
Timestamp:
04/24/09 20:41:19 (3 years ago)
Author:
Kris.Wallsmith
Message:

[1.1, 1.2, 1.3] fixed rare occassion when a widget schema is paired with a simple validator error rather than a validator error schema

Files:

Legend:

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

    r9045 r17587  
    6868      } 
    6969 
    70       $class = $widget instanceof sfWidgetFormSchema ? 'sfFormFieldSchema' : 'sfFormField'
     70      $error = isset($this->error[$name]) ? $this->error[$name] : null
    7171 
    72       $this->fields[$name] = new $class($widget, $this, $name, isset($this->value[$name]) ? $this->value[$name] : null, isset($this->error[$name]) ? $this->error[$name] : null); 
     72      if ($widget instanceof sfWidgetFormSchema) 
     73      { 
     74        $class = 'sfFormFieldSchema'; 
     75 
     76        if ($error && !$error instanceof sfValidatorErrorSchema) 
     77        { 
     78          $error = new sfValidatorErrorSchema($error->getValidator(), array($error)); 
     79        } 
     80      } 
     81      else 
     82      { 
     83        $class = 'sfFormField'; 
     84      } 
     85 
     86      $this->fields[$name] = new $class($widget, $this, $name, isset($this->value[$name]) ? $this->value[$name] : null, $error); 
    7387    } 
    7488 
  • branches/1.1/lib/widget/sfWidgetFormSchema.class.php

    r16227 r17587  
    327327    { 
    328328      throw new InvalidArgumentException(sprintf('The field named "%s" does not exist.', $name)); 
     329    } 
     330 
     331    if ($widget instanceof sfWidgetFormSchema && $errors && !$errors instanceof sfValidatorErrorSchema) 
     332    { 
     333      $errors = new sfValidatorErrorSchema($errors->getValidator(), array($errors)); 
    329334    } 
    330335 
  • branches/1.1/test/unit/form/sfFormTest.php

    r17023 r17587  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(103, new lime_output_color()); 
     13$t = new lime_test(105, new lime_output_color()); 
    1414 
    1515class FormTest extends sfForm 
     
    382382 
    383383$t->is($w['authors'][0]->generateName('first_name'), 'article[authors][0][first_name]', '->embedFormForEach() changes the name format to reflect the embedding'); 
     384 
     385// bind too many values for embedded forms 
     386$t->diag('bind too many values for embedded forms'); 
     387$list = new FormTest(); 
     388$list->setWidgets(array('title' => new sfWidgetFormInput())); 
     389$list->setValidators(array('title' => new sfValidatorString())); 
     390$list->embedFormForEach('items', clone $list, 2); 
     391$list->bind(array( 
     392  'title' => 'list title', 
     393  'items' => array( 
     394    array('title' => 'item 1'), 
     395    array('title' => 'item 2'), 
     396    array('title' => 'extra item'), 
     397  ), 
     398)); 
     399 
     400$t->isa_ok($list['items'][0]->getError(), 'sfValidatorErrorSchema', '"sfFormFieldSchema" is given an error schema when an extra embedded form is bound'); 
     401 
     402// does this trigger a fatal error? 
     403$list['items']->render(); 
     404$t->pass('"sfFormFieldSchema" renders when an extra embedded form is bound'); 
    384405 
    385406// ::convertFileInformation() 
  • branches/1.2/lib/form/sfFormFieldSchema.class.php

    r9045 r17587  
    6868      } 
    6969 
    70       $class = $widget instanceof sfWidgetFormSchema ? 'sfFormFieldSchema' : 'sfFormField'
     70      $error = isset($this->error[$name]) ? $this->error[$name] : null
    7171 
    72       $this->fields[$name] = new $class($widget, $this, $name, isset($this->value[$name]) ? $this->value[$name] : null, isset($this->error[$name]) ? $this->error[$name] : null); 
     72      if ($widget instanceof sfWidgetFormSchema) 
     73      { 
     74        $class = 'sfFormFieldSchema'; 
     75 
     76        if ($error && !$error instanceof sfValidatorErrorSchema) 
     77        { 
     78          $error = new sfValidatorErrorSchema($error->getValidator(), array($error)); 
     79        } 
     80      } 
     81      else 
     82      { 
     83        $class = 'sfFormField'; 
     84      } 
     85 
     86      $this->fields[$name] = new $class($widget, $this, $name, isset($this->value[$name]) ? $this->value[$name] : null, $error); 
    7387    } 
    7488 
  • branches/1.2/lib/widget/sfWidgetFormSchema.class.php

    r16733 r17587  
    455455    { 
    456456      throw new InvalidArgumentException(sprintf('The field named "%s" does not exist.', $name)); 
     457    } 
     458 
     459    if ($widget instanceof sfWidgetFormSchema && $errors && !$errors instanceof sfValidatorErrorSchema) 
     460    { 
     461      $errors = new sfValidatorErrorSchema($errors->getValidator(), array($errors)); 
    457462    } 
    458463 
  • branches/1.2/test/unit/form/sfFormTest.php

    r17023 r17587  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(138, new lime_output_color()); 
     13$t = new lime_test(140, new lime_output_color()); 
    1414 
    1515class FormTest extends sfForm 
     
    505505 
    506506$t->is($w['authors'][0]->generateName('first_name'), 'article[authors][0][first_name]', '->embedFormForEach() changes the name format to reflect the embedding'); 
     507 
     508// bind too many values for embedded forms 
     509$t->diag('bind too many values for embedded forms'); 
     510$list = new FormTest(); 
     511$list->setWidgets(array('title' => new sfWidgetFormInput())); 
     512$list->setValidators(array('title' => new sfValidatorString())); 
     513$list->embedFormForEach('items', clone $list, 2); 
     514$list->bind(array( 
     515  'title' => 'list title', 
     516  'items' => array( 
     517    array('title' => 'item 1'), 
     518    array('title' => 'item 2'), 
     519    array('title' => 'extra item'), 
     520  ), 
     521)); 
     522 
     523$t->isa_ok($list['items'][0]->getError(), 'sfValidatorErrorSchema', '"sfFormFieldSchema" is given an error schema when an extra embedded form is bound'); 
     524 
     525// does this trigger a fatal error? 
     526$list['items']->render(); 
     527$t->pass('"sfFormFieldSchema" renders when an extra embedded form is bound'); 
    507528 
    508529// ->getEmbeddedForms() 
  • branches/1.3/lib/form/sfFormFieldSchema.class.php

    r9045 r17587  
    6868      } 
    6969 
    70       $class = $widget instanceof sfWidgetFormSchema ? 'sfFormFieldSchema' : 'sfFormField'
     70      $error = isset($this->error[$name]) ? $this->error[$name] : null
    7171 
    72       $this->fields[$name] = new $class($widget, $this, $name, isset($this->value[$name]) ? $this->value[$name] : null, isset($this->error[$name]) ? $this->error[$name] : null); 
     72      if ($widget instanceof sfWidgetFormSchema) 
     73      { 
     74        $class = 'sfFormFieldSchema'; 
     75 
     76        if ($error && !$error instanceof sfValidatorErrorSchema) 
     77        { 
     78          $error = new sfValidatorErrorSchema($error->getValidator(), array($error)); 
     79        } 
     80      } 
     81      else 
     82      { 
     83        $class = 'sfFormField'; 
     84      } 
     85 
     86      $this->fields[$name] = new $class($widget, $this, $name, isset($this->value[$name]) ? $this->value[$name] : null, $error); 
    7387    } 
    7488 
  • branches/1.3/lib/widget/sfWidgetFormSchema.class.php

    r16733 r17587  
    455455    { 
    456456      throw new InvalidArgumentException(sprintf('The field named "%s" does not exist.', $name)); 
     457    } 
     458 
     459    if ($widget instanceof sfWidgetFormSchema && $errors && !$errors instanceof sfValidatorErrorSchema) 
     460    { 
     461      $errors = new sfValidatorErrorSchema($errors->getValidator(), array($errors)); 
    457462    } 
    458463 
  • branches/1.3/test/unit/form/sfFormTest.php

    r17023 r17587  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(138, new lime_output_color()); 
     13$t = new lime_test(140, new lime_output_color()); 
    1414 
    1515class FormTest extends sfForm 
     
    505505 
    506506$t->is($w['authors'][0]->generateName('first_name'), 'article[authors][0][first_name]', '->embedFormForEach() changes the name format to reflect the embedding'); 
     507 
     508// bind too many values for embedded forms 
     509$t->diag('bind too many values for embedded forms'); 
     510$list = new FormTest(); 
     511$list->setWidgets(array('title' => new sfWidgetFormInput())); 
     512$list->setValidators(array('title' => new sfValidatorString())); 
     513$list->embedFormForEach('items', clone $list, 2); 
     514$list->bind(array( 
     515  'title' => 'list title', 
     516  'items' => array( 
     517    array('title' => 'item 1'), 
     518    array('title' => 'item 2'), 
     519    array('title' => 'extra item'), 
     520  ), 
     521)); 
     522 
     523$t->isa_ok($list['items'][0]->getError(), 'sfValidatorErrorSchema', '"sfFormFieldSchema" is given an error schema when an extra embedded form is bound'); 
     524 
     525// does this trigger a fatal error? 
     526$list['items']->render(); 
     527$t->pass('"sfFormFieldSchema" renders when an extra embedded form is bound'); 
    507528 
    508529// ->getEmbeddedForms()