Skip to content

Commit

Permalink
[Form] Fixed: Objects are stored in the form before calling configure()
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernhard Schussek committed Jul 4, 2010
1 parent fd3243a commit 34dd0ea
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/Symfony/Components/Form/Field.php
Expand Up @@ -42,9 +42,12 @@ public function __construct($key, array $options = array())
$this->addOption('property_path', (string)$key);

$this->key = (string)$key;
$this->locale = class_exists('\Locale', false) ? \Locale::getDefault() : 'en';
$this->generator = new HtmlGenerator();

if ($this->locale === null) {
$this->locale = class_exists('\Locale', false) ? \Locale::getDefault() : 'en';
}

parent::__construct($options);

$this->transformedData = $this->transform($this->data);
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Components/Form/Form.php
Expand Up @@ -58,8 +58,6 @@ public function __construct($name, $object, ValidatorInterface $validator, array
$this->generator = new HtmlGenerator();
$this->validator = $validator;

parent::__construct($name, $options);

$this->setData($object);
$this->setCsrfFieldName(self::$defaultCsrfFieldName);

Expand All @@ -80,6 +78,8 @@ public function __construct($name, $object, ValidatorInterface $validator, array
if (self::$defaultTranslator !== null) {
$this->setTranslator(self::$defaultTranslator);
}

parent::__construct($name, $options);
}

/**
Expand Down
24 changes: 24 additions & 0 deletions tests/Symfony/Tests/Components/Form/FormTest.php
Expand Up @@ -25,6 +25,25 @@ protected function configure()
}
}

class TestSetDataBeforeConfigureForm extends Form
{
protected $testCase;
protected $object;

public function __construct($testCase, $name, $object, $validator)
{
$this->testCase = $testCase;
$this->object = $object;

parent::__construct($name, $object, $validator);
}

protected function configure()
{
$this->testCase->assertEquals($this->object, $this->getData());
}
}

class FormTest extends \PHPUnit_Framework_TestCase
{
protected $validator;
Expand All @@ -43,6 +62,11 @@ public function testConstructInitializesObject()
$this->assertEquals(new Author(), $this->form->getData());
}

public function testSetDataBeforeConfigure()
{
new TestSetDataBeforeConfigureForm($this, 'author', new Author(), $this->validator);
}

public function testIsCsrfProtected()
{
$this->assertFalse($this->form->isCsrfProtected());
Expand Down

0 comments on commit 34dd0ea

Please sign in to comment.