Changeset 5819
- Timestamp:
- 11/02/07 18:30:38 (10 months ago)
- Files:
-
- trunk/lib/validator/sfValidatorChoice.class.php (modified) (1 diff)
- trunk/test/unit/validator/sfValidatorChoiceTest.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/validator/sfValidatorChoice.class.php
r5816 r5819 38 38 protected function doClean($value) 39 39 { 40 if (!in_array($value, $this->getOption('choices'))) 40 $choices = $this->getOption('choices'); 41 if ($choices instanceof sfCallable) 42 { 43 $choices = $choices->call(); 44 } 45 46 if (!in_array($value, $choices)) 41 47 { 42 48 throw new sfValidatorError($this, 'invalid', array('value' => $value)); trunk/test/unit/validator/sfValidatorChoiceTest.php
r5757 r5819 11 11 require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 12 12 13 $t = new lime_test(5, new lime_output_color()); 13 $t = new lime_test(6, new lime_output_color()); 14 15 function choice_callable() 16 { 17 return array(1, 2, 3); 18 } 14 19 15 20 // __construct() … … 45 50 $t->diag('->asString()'); 46 51 $t->is($v->asString(), 'Choice({ choices: [foo, bar] })', '->asString() returns a string representation of the validator'); 52 53 // choices as a callable 54 $t->diag('choices as a callable'); 55 $v = new sfValidatorChoice(array('choices' => new sfCallable('choice_callable'))); 56 $t->is($v->clean('2'), '2', '__construct() can take a sfCallable object as a choices option');