Development

Changeset 5632

You must first sign up to be able to contribute.

Changeset 5632

Show
Ignore:
Timestamp:
10/23/07 09:04:55 (1 year ago)
Author:
fabien
Message:

added the possibility to return a sfValidatorError instead of a sfValidatorErrorSchema for sfValidatorAll and sfValidatorAny if the invalid error message is not empty

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/validator/sfValidatorAll.class.php

    r5581 r5632  
    5555    } 
    5656 
     57    if (!isset($messages['invalid'])) 
     58    { 
     59      $messages['invalid'] = null; 
     60    } 
     61 
    5762    parent::__construct($options, $messages); 
    5863  } 
     
    107112    if (count($errors)) 
    108113    { 
     114      if ($this->getMessage('invalid')) 
     115      { 
     116        throw new sfValidatorError($this, 'invalid', array('value' => $value)); 
     117      } 
     118 
    109119      throw new sfValidatorErrorSchema($this, $errors); 
    110120    } 
  • trunk/lib/validator/sfValidatorAny.class.php

    r5581 r5632  
    5555    } 
    5656 
     57    if (!isset($messages['invalid'])) 
     58    { 
     59      $messages['invalid'] = null; 
     60    } 
     61 
    5762    parent::__construct($options, $messages); 
    5863  } 
     
    104109    } 
    105110 
     111    if ($this->getMessage('invalid')) 
     112    { 
     113      throw new sfValidatorError($this, 'invalid', array('value' => $value)); 
     114    } 
     115 
    106116    throw new sfValidatorErrorSchema($this, $errors); 
    107117  } 
  • trunk/test/unit/validator/sfValidatorAllTest.php

    r5581 r5632  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(7, new lime_output_color()); 
     13$t = new lime_test(12, new lime_output_color()); 
    1414 
    1515$v1 = new sfValidatorString(array('max_length' => 3)); 
     
    5252  $v->clean('foo'); 
    5353  $t->fail('->clean() throws an sfValidatorError exception if one of the validators fails'); 
     54  $t->skip('', 2); 
    5455} 
    5556catch (sfValidatorError $e) 
    5657{ 
    5758  $t->pass('->clean() throws an sfValidatorError exception if one of the validators fails'); 
     59  $t->is($e[0]->getCode(), 'max_length', '->clean() throws a sfValidatorSchemaError'); 
     60  $t->is($e instanceof sfValidatorErrorSchema, 'max_length', '->clean() throws a sfValidatorSchemaError'); 
    5861} 
    5962 
     63try 
     64{ 
     65  $v->setMessage('invalid', 'Invalid.'); 
     66  $v->clean('foo'); 
     67  $t->fail('->clean() throws an sfValidatorError exception if one of the validators fails'); 
     68  $t->skip('', 2); 
     69} 
     70catch (sfValidatorError $e) 
     71{ 
     72  $t->pass('->clean() throws an sfValidatorError exception if one of the validators fails'); 
     73  $t->is($e->getCode(), 'invalid', '->clean() throws a sfValidatorError if invalid message is not empty'); 
     74  $t->is(!$e instanceof sfValidatorErrorSchema, 'max_length', '->clean() throws a sfValidatorError if invalid message is not empty'); 
     75} 
  • trunk/test/unit/validator/sfValidatorAnyTest.php

    r5581 r5632  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(9, new lime_output_color()); 
     13$t = new lime_test(14, new lime_output_color()); 
    1414 
    1515$v1 = new sfValidatorString(array('max_length' => 3)); 
     
    5353  $v->clean('foo'); 
    5454  $t->fail('->clean() throws an sfValidatorError exception if all the validators fails'); 
    55   $t->fail(); 
     55  $t->skip('', 3); 
    5656} 
    5757catch (sfValidatorError $e) 
     
    5959  $t->pass('->clean() throws an sfValidatorError exception if all the validators fails'); 
    6060  $t->is(count($e), 2, '->clean() throws an exception with all error messages'); 
     61  $t->is($e[0]->getCode(), 'max_length', '->clean() throws a sfValidatorSchemaError'); 
     62  $t->is($e instanceof sfValidatorErrorSchema, 'max_length', '->clean() throws a sfValidatorSchemaError'); 
     63} 
     64 
     65try 
     66{ 
     67  $v->setMessage('invalid', 'Invalid.'); 
     68  $v->clean('foo'); 
     69  $t->fail('->clean() throws an sfValidatorError exception if one of the validators fails'); 
     70  $t->skip('', 2); 
     71} 
     72catch (sfValidatorError $e) 
     73{ 
     74  $t->pass('->clean() throws an sfValidatorError exception if one of the validators fails'); 
     75  $t->is($e->getCode(), 'invalid', '->clean() throws a sfValidatorError if invalid message is not empty'); 
     76  $t->is(!$e instanceof sfValidatorErrorSchema, 'max_length', '->clean() throws a sfValidatorError if invalid message is not empty'); 
    6177} 
    6278