sfForm::disableCSRFProtection(); // ->setDefault() ->getDefault() ->hasDefault() ->setDefaults() ->getDefaults() $t->diag('->setDefault() ->getDefault() ->hasDefault() ->setDefaults() ->getDefaults()'); $f = new FormTest(); $f->setDefaults(array('first_name' => 'Fabien')); $t->is($f->getDefaults(), array('first_name' => 'Fabien'), 'setDefaults() sets the form default values'); $f->setDefault('last_name', 'Potencier'); $t->is($f->getDefaults(), array('first_name' => 'Fabien', 'last_name' => 'Potencier'), 'setDefault() sets a default value'); $t->is($f->hasDefault('first_name'), true, 'hasDefault() returns true if the form has a default value for the given field'); $t->is($f->hasDefault('name'), false, 'hasDefault() returns false if the form does not have a default value for the given field'); $t->is($f->getDefault('first_name'), 'Fabien', 'getDefault() returns a default value for a given field'); $t->is($f->getDefault('name'), null, 'getDefault() returns null if the form does not have a default value for a given field'); sfForm::enableCSRFProtection('*mygreatsecret*'); $f = new FormTest(); $f->setDefaults(array('first_name' => 'Fabien')); $t->is($f->getDefault('_csrf_token'), $f->getCSRFToken('*mygreatsecret*'), '->getDefaults() keeps the CSRF token default value'); $f = new FormTest(array(), array(), false); $f->setDefaults(array('first_name' => 'Fabien')); $t->is(array_key_exists('_csrf_token', $f->getDefaults()), false, '->setDefaults() does not set the CSRF token if CSRF is disabled'); sfForm::disableCSRFProtection(); // ->getName() $t->diag('->getName()'); $f = new FormTest(); $w = new sfWidgetFormSchema(); $f->setWidgetSchema($w); $t->ok($f->getName() === false, '->getName() returns false if the name format is not an array'); $w->setNameFormat('foo_%s'); $t->ok($f->getName() === false, '->getName() returns false if the name format is not an array'); $w->setNameFormat('foo[%s]'); $t->is($f->getName(), 'foo', '->getName() returns the name under which user data can be retrieved'); // ::enableCSRFProtection() ::disableCSRFProtection() ->isCSRFProtected()