[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:
parent
05842c54b8
commit
4120f1392f
@ -643,6 +643,16 @@ class FormBuilder
|
|||||||
return isset($this->children[$name]);
|
return isset($this->children[$name]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the children.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function all()
|
||||||
|
{
|
||||||
|
return $this->children;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the form.
|
* Creates the form.
|
||||||
*
|
*
|
||||||
|
@ -110,6 +110,22 @@ class FormBuilderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertTrue($this->builder->has('foo'));
|
$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()
|
public function testAddFormType()
|
||||||
{
|
{
|
||||||
$this->assertFalse($this->builder->has('foo'));
|
$this->assertFalse($this->builder->has('foo'));
|
||||||
|
Reference in New Issue
Block a user