Changeset 6326
- Timestamp:
- 12/05/07 15:32:24 (9 months ago)
- Files:
-
- trunk/lib/form/sfForm.class.php (modified) (3 diffs)
- trunk/test/unit/form/sfFormTest.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/form/sfForm.class.php
r6196 r6326 37 37 $taintedValues = array(), 38 38 $values = null, 39 $defaults = array(); 39 $defaults = array(), 40 $options = array(); 40 41 41 42 /** … … 43 44 * 44 45 * @param array An array of field default values 46 * @param array An array of options 45 47 * @param string A CSRF secret (false to disable CSRF protection, null to use the global CSRF secret) 46 48 */ 47 public function __construct($defaults = array(), $ CSRFSecret = null)49 public function __construct($defaults = array(), $options = array(), $CSRFSecret = null) 48 50 { 49 51 $this->setDefaults($defaults); 52 $this->options = $options; 50 53 51 54 $this->validatorSchema = new sfValidatorSchema(); … … 300 303 301 304 /** 305 * Sets an option value. 306 * 307 * @param string The option name 308 * @param mixed The default value 309 */ 310 public function setOption($name, $value) 311 { 312 $this->options[$name] = $value; 313 } 314 315 /** 316 * Gets an option value. 317 * 318 * @param string The option name 319 * @param mixed The default value (null by default) 320 * 321 * @param mixed The default value 322 */ 323 public function getOption($name, $default = null) 324 { 325 return isset($this->options[$name]) ? $this->options[$name] : $default; 326 } 327 328 /** 302 329 * Sets a default value for a form field. 303 330 * trunk/test/unit/form/sfFormTest.php
r6197 r6326 11 11 require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 12 12 13 $t = new lime_test(5 6, new lime_output_color());13 $t = new lime_test(58, new lime_output_color()); 14 14 15 15 class FormTest extends sfForm … … 37 37 $t->is($f->getDefaults(), array('first_name' => 'Fabien'), '__construct() can take an array of default values as its first argument'); 38 38 39 $f = new FormTest(array(), 'secret');39 $f = new FormTest(array(), array(), 'secret'); 40 40 $v = $f->getValidatorSchema(); 41 41 $t->ok($f->isCSRFProtected(), '__construct() takes a CSRF secret as its second argument'); … … 43 43 44 44 sfForm::enableCSRFProtection(); 45 $f = new FormTest(array(), false);45 $f = new FormTest(array(), array(), false); 46 46 $t->ok(!$f->isCSRFProtected(), '__construct() can disable the CSRF protection by passing false as the second argument'); 47 47 48 48 $f = new FormTest(); 49 49 $t->ok($f->isCSRFProtected(), '__construct() uses CSRF protection if null is passed as the second argument and it\'s enabled globally'); 50 51 // ->getOption() ->setOption() 52 $t->diag('->getOption() ->setOption()'); 53 $f = new FormTest(array(), array('foo' => 'bar')); 54 $t->is($f->getOption('foo'), 'bar', '__construct takes an option array as its second argument'); 55 $f->setOption('bar', 'foo'); 56 $t->is($f->getOption('bar'), 'foo', '->setOption() changes the value of an option'); 50 57 51 58 sfForm::disableCSRFProtection(); … … 75 82 $t->ok(!$f2->isCSRFProtected(),'::disableCSRFProtection() disables CSRF protection for all future forms'); 76 83 77 $f = new FormTest(array(), false);84 $f = new FormTest(array(), array(), false); 78 85 $t->ok(!$f->isCSRFProtected(),'->isCSRFProtected() returns true if the form is CSRF protected'); 79 86