Skip to content

Commit

Permalink
[Form] Added all() method to the FormBuilder class
Browse files Browse the repository at this point in the history
In order to perform some introspection on a FormBuilder instance,
we need to be able to get its children. Almost everything is accessible
in this class, but the children are not.

This PR adds a all() method to respect the current API (get(), remove(),
...).
  • Loading branch information
willdurand committed Apr 11, 2012
1 parent 05842c5 commit 4120f13
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Symfony/Component/Form/FormBuilder.php
Expand Up @@ -643,6 +643,16 @@ public function has($name)
return isset($this->children[$name]);
}

/**
* Returns the children.
*
* @return array
*/
public function all()
{
return $this->children;
}

/**
* Creates the form.
*
Expand Down
16 changes: 16 additions & 0 deletions src/Symfony/Component/Form/Tests/FormBuilderTest.php
Expand Up @@ -110,6 +110,22 @@ public function testAdd()
$this->assertTrue($this->builder->has('foo'));
}

public function testAll()
{
$this->assertEquals(0, count($this->builder->all()));
$this->assertFalse($this->builder->has('foo'));

$this->builder->add('foo', 'text');
$children = $this->builder->all();

$this->assertTrue($this->builder->has('foo'));
$this->assertEquals(1, count($children));
$this->assertArrayHasKey('foo', $children);

$foo = $children['foo'];
$this->assertEquals('text', $foo['type']);
}

public function testAddFormType()
{
$this->assertFalse($this->builder->has('foo'));
Expand Down

0 comments on commit 4120f13

Please sign in to comment.