[Form] Added all() method to the FormBuilder class

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(),
...).
This commit is contained in:
William DURAND 2012-04-11 19:07:08 +02:00
parent 05842c54b8
commit 4120f1392f
2 changed files with 26 additions and 0 deletions

View File

@ -643,6 +643,16 @@ class FormBuilder
return isset($this->children[$name]);
}
/**
* Returns the children.
*
* @return array
*/
public function all()
{
return $this->children;
}
/**
* Creates the form.
*

View File

@ -110,6 +110,22 @@ class FormBuilderTest extends \PHPUnit_Framework_TestCase
$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'));