merged branch ChrisTickner/formbuilder_remove_bug_fix (PR #4826)
Commits
-------
f71e2a8
[Form] FormBuilder Bug Fix: remove() was not properly removing children
Discussion
----------
[Form] FormBuilder Bug Fix: remove() was not properly removing children
Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: #4803
License of the code: MIT
FormBuilder initially sets unresolved children as NULL, until resolved.
If FormBuilder::remove() is called before that child is resolved, the
if statement turns false, because isset(null) is false, when it should
be true. Instead, we should check to see if the key exists, and if so,
process and unset it.
Closes #4803
---------------------------------------------------------------------------
by bschussek at 2012-07-10T07:41:55Z
Can you please add a test covering this case?
---------------------------------------------------------------------------
by ChrisTickner at 2012-07-10T09:43:07Z
Sure, added a test case. It fails before the patch and passes after.
---------------------------------------------------------------------------
by bschussek at 2012-07-10T09:47:06Z
Thanks. Can you please add a comment to the test with the URL of this PR? Also, please squash your commits into one when your done.
---------------------------------------------------------------------------
by ChrisTickner at 2012-07-10T10:02:16Z
Oops, I deleted the remote branch and re-pushed without realizing we'd lose some history on this PR page. Live and learn I suppose.
---------------------------------------------------------------------------
by bschussek at 2012-07-10T10:18:20Z
Thanks!
This commit is contained in:
commit
5487a1f076
|
@ -144,7 +144,7 @@ class FormBuilder extends FormConfig implements \IteratorAggregate, FormBuilderI
|
|||
{
|
||||
unset($this->unresolvedChildren[$name]);
|
||||
|
||||
if (isset($this->children[$name])) {
|
||||
if (array_key_exists($name, $this->children)) {
|
||||
if ($this->children[$name] instanceof self) {
|
||||
$this->children[$name]->setParent(null);
|
||||
}
|
||||
|
|
|
@ -134,6 +134,15 @@ class FormBuilderTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertFalse($this->builder->has('foo'));
|
||||
}
|
||||
|
||||
// https://github.com/symfony/symfony/pull/4826
|
||||
public function testRemoveAndGetForm()
|
||||
{
|
||||
$this->builder->add('foo', 'text');
|
||||
$this->builder->remove('foo');
|
||||
$form = $this->builder->getForm();
|
||||
$this->assertInstanceOf('Symfony\Component\Form\Form', $form);
|
||||
}
|
||||
|
||||
public function testCreateNoTypeNo()
|
||||
{
|
||||
$this->factory->expects($this->once())
|
||||
|
|
Reference in New Issue