Development

Changeset 7124

You must first sign up to be able to contribute.

Changeset 7124

Show
Ignore:
Timestamp:
01/21/08 14:42:38 (9 months ago)
Author:
fabien
Message:

fixed setDefaults() when CSRFProtection is enabled

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/lib/form/sfForm.class.php

    r7053 r7124  
    402402    $this->defaults = $defaults; 
    403403 
     404    if (self::$CSRFProtection) 
     405    { 
     406      $this->setDefault(self::$CSRFFieldName, $this->getCSRFToken(self::$CSRFSecret)); 
     407    } 
     408 
    404409    $this->resetFormFields(); 
    405410  } 
  • branches/1.1/test/unit/form/sfFormTest.php

    r7053 r7124  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(83, new lime_output_color()); 
     13$t = new lime_test(84, new lime_output_color()); 
    1414 
    1515class FormTest extends sfForm 
     
    6464$t->is($f->getDefault('first_name'), 'Fabien', 'getDefault() returns a default value for a given field'); 
    6565$t->is($f->getDefault('name'), null, 'getDefault() returns null if the form does not have a default value for a given field'); 
     66 
     67sfForm::enableCSRFProtection('*mygreatsecret*'); 
     68$f = new FormTest(); 
     69$f->setDefaults(array('first_name' => 'Fabien')); 
     70$t->is($f->getDefault('_csrf_token'), $f->getCSRFToken('*mygreatsecret*'), '->getDefaults() keeps the CSRF token default value'); 
     71sfForm::disableCSRFProtection(); 
    6672 
    6773// ::enableCSRFProtection() ::disableCSRFProtection() ->isCSRFProtected() 
     
    7884 
    7985$f = new FormTest(array(), array(), false); 
    80 $t->ok(!$f->isCSRFProtected(),'->isCSRFProtected() returns true if the form is CSRF protected'); 
     86$t->ok(!$f->isCSRFProtected(), '->isCSRFProtected() returns true if the form is CSRF protected'); 
    8187 
    8288sfForm::enableCSRFProtection('mygreatsecret');