Changeset 6968
- Timestamp:
- 01/06/08 07:48:13 (11 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.1/lib/validator/sfValidatorCallback.class.php
r5882 r6968 24 24 * Available options: 25 25 * 26 * * callback: A valid PHP callback (required) 26 * * callback: A valid PHP callback (required) 27 * * arguments: An array of arguments to pass to the callback 27 28 * 28 29 * @see sfValidator … … 31 32 { 32 33 $this->addRequiredOption('callback'); 34 $this->addOption('arguments', array()); 33 35 34 36 $this->setOption('required', false); … … 40 42 protected function doClean($value) 41 43 { 42 return call_user_func($this->getOption('callback'), $this, $value );44 return call_user_func($this->getOption('callback'), $this, $value, $this->getOption('arguments')); 43 45 } 44 46 } branches/1.1/test/unit/validator/sfValidatorCallbackTest.php
r6945 r6968 11 11 require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 12 12 13 $t = new lime_test( 6, new lime_output_color());13 $t = new lime_test(7, new lime_output_color()); 14 14 15 function clean_test($validator, $value )15 function clean_test($validator, $value, $arguments) 16 16 { 17 17 if ($value != 'foo') … … 20 20 } 21 21 22 return "*$value*" ;22 return "*$value*".implode('-', $arguments); 23 23 } 24 24 … … 37 37 $v = new sfValidatorCallback(array('callback' => 'clean_test')); 38 38 39 // ->configure() 40 $t->diag('->configure()'); 41 $t->is($v->clean(''), null, '->configure() switch required to false by default'); 42 39 43 // ->clean() 40 44 $t->diag('->clean()'); … … 52 56 } 53 57 54 // ->configure() 55 $ t->diag('->configure()');56 $t->is($v->clean(' '), null, '->configure() switch required to false by default');58 $t->diag('callback with arguments'); 59 $v = new sfValidatorCallback(array('callback' => 'clean_test', 'arguments' => array('fabien', 'symfony'))); 60 $t->is($v->clean('foo'), '*foo*fabien-symfony', '->configure() can take an arguments option'); 57 61 58 62 // ->asString() 59 63 $t->diag('->asString()'); 64 $v = new sfValidatorCallback(array('callback' => 'clean_test')); 60 65 $t->is($v->asString(), 'Callback({ callback: clean_test })', '->asString() returns a string representation of the validator');