Development

Changeset 6963

You must first sign up to be able to contribute.

Changeset 6963

Show
Ignore:
Timestamp:
01/06/08 05:27:04 (9 months ago)
Author:
fabien
Message:

fixed form error merging with complex post validators

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/lib/validator/sfValidatorErrorSchema.class.php

    r6954 r6963  
    5757      if ($error instanceof sfValidatorErrorSchema) 
    5858      { 
    59         throw new LogicException('Unable to merge a sfValidatorErrorSchema to global errors.'); 
    60       } 
    61  
    62       $this->globalErrors[] = $error; 
    63       $this->errors[] = $error; 
     59        $this->addErrors($error); 
     60      } 
     61      else 
     62      { 
     63        $this->globalErrors[] = $error; 
     64        $this->errors[] = $error; 
     65      } 
    6466    } 
    6567    else 
  • branches/1.1/test/unit/validator/sfValidatorSchemaTest.php

    r6961 r6963  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(60, new lime_output_color()); 
     13$t = new lime_test(73, new lime_output_color()); 
    1414 
    1515class PreValidator extends sfValidator 
     
    303303  $t->is($e->getCode(), 'test [min_length] embedded [test [min_length] left [invalid]] left [required invalid]', '->clean() throws an exception with all error messages'); 
    304304} 
     305 
     306$t->diag('complex postValidator'); 
     307$comparator1 = new sfValidatorSchemaCompare('password', sfValidatorSchemaCompare::EQUAL, 'password_bis'); 
     308$v = new sfValidatorSchema(array( 
     309  'left'         => new sfValidatorString(array('min_length' => 2)), 
     310  'right'        => new sfValidatorString(array('min_length' => 2)), 
     311  'password'     => new sfValidatorString(array('min_length' => 2)), 
     312  'password_bis' => new sfValidatorString(array('min_length' => 2)), 
     313)); 
     314$v->setPostValidator(new sfValidatorAnd(array($comparator, $comparator1))); 
     315try 
     316{ 
     317  $v->clean(array('left' => 'foo', 'right' => 'bar', 'password' => 'oof', 'password_bis' => 'rab')); 
     318  $t->skip('', 3); 
     319} 
     320catch (sfValidatorErrorSchema $e) 
     321{ 
     322  $t->is(count($e->getNamedErrors()), 2, '->clean() throws an exception with all error messages'); 
     323  $t->is(count($e->getGlobalErrors()), 0, '->clean() throws an exception with all error messages'); 
     324  $t->is($e->getCode(), 'left [invalid] password [invalid]', '->clean() throws an exception with all error messages'); 
     325} 
     326 
     327$comparator->setOption('throw_global_error', true); 
     328try 
     329{ 
     330  $v->clean(array('left' => 'foo', 'right' => 'bar', 'password' => 'oof', 'password_bis' => 'rab')); 
     331  $t->skip('', 3); 
     332} 
     333catch (sfValidatorErrorSchema $e) 
     334{ 
     335  $t->is(count($e->getNamedErrors()), 1, '->clean() throws an exception with all error messages'); 
     336  $t->is(count($e->getGlobalErrors()), 1, '->clean() throws an exception with all error messages'); 
     337  $t->is($e->getCode(), 'invalid password [invalid]', '->clean() throws an exception with all error messages'); 
     338} 
     339 
     340$userValidator = new sfValidatorSchema(array( 
     341  'left'         => new sfValidatorString(array('min_length' => 2)), 
     342  'right'        => new sfValidatorString(array('min_length' => 2)), 
     343  'password'     => new sfValidatorString(array('min_length' => 2)), 
     344  'password_bis' => new sfValidatorString(array('min_length' => 2)), 
     345)); 
     346$userValidator->setPostValidator(new sfValidatorAnd(array($comparator, $comparator1))); 
     347$v = new sfValidatorSchema(array( 
     348  'left'         => new sfValidatorString(array('min_length' => 2)), 
     349  'right'        => new sfValidatorString(array('min_length' => 2)), 
     350  'password'     => new sfValidatorString(array('min_length' => 2)), 
     351  'password_bis' => new sfValidatorString(array('min_length' => 2)), 
     352  'user'         => $userValidator, 
     353)); 
     354$v->setPostValidator(new sfValidatorAnd(array($comparator, $comparator1))); 
     355try 
     356{ 
     357  $v->clean(array('left' => 'foo', 'right' => 'bar', 'password' => 'oof', 'password_bis' => 'rab', 'user' => array('left' => 'foo', 'right' => 'bar', 'password' => 'oof', 'password_bis' => 'rab'))); 
     358  $t->skip('', 7); 
     359} 
     360catch (sfValidatorErrorSchema $e) 
     361{ 
     362  $t->is(count($e->getNamedErrors()), 2, '->clean() throws an exception with all error messages'); 
     363  $t->is(count($e->getGlobalErrors()), 1, '->clean() throws an exception with all error messages'); 
     364  $t->is(count($e['user']->getNamedErrors()), 1, '->clean() throws an exception with all error messages'); 
     365  $t->is(count($e['user']->getGlobalErrors()), 1, '->clean() throws an exception with all error messages'); 
     366  $t->is(isset($e['user']) ? $e['user']->getCode() : '', 'invalid password [invalid]', '->clean() throws an exception with all error messages'); 
     367  $t->is(isset($e['user']['password']) ? $e['user']['password']->getCode() : '', 'invalid', '->clean() throws an exception with all error messages'); 
     368  $t->is($e->getCode(), 'invalid user [invalid password [invalid]] password [invalid]', '->clean() throws an exception with all error messages'); 
     369}