[Form] Test case for binding a collection of field groups with an ArrayObject of objects.
This commit is contained in:
parent
b3648b219b
commit
9f5469f62d
@ -5,6 +5,7 @@ namespace Symfony\Tests\Component\Form;
|
|||||||
require_once __DIR__ . '/Fixtures/TestField.php';
|
require_once __DIR__ . '/Fixtures/TestField.php';
|
||||||
|
|
||||||
use Symfony\Component\Form\CollectionField;
|
use Symfony\Component\Form\CollectionField;
|
||||||
|
use Symfony\Component\Form\FieldGroup;
|
||||||
use Symfony\Tests\Component\Form\Fixtures\TestField;
|
use Symfony\Tests\Component\Form\Fixtures\TestField;
|
||||||
|
|
||||||
|
|
||||||
@ -96,4 +97,25 @@ class CollectionFieldTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('foo@foo.com', $field[0]->getData());
|
$this->assertEquals('foo@foo.com', $field[0]->getData());
|
||||||
$this->assertEquals('bar@bar.com', $field[1]->getData());
|
$this->assertEquals('bar@bar.com', $field[1]->getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCollectionOfFieldGroupsBoundWithArrayObjectContainingObjects()
|
||||||
|
{
|
||||||
|
$fieldGroup = new FieldGroup('name');
|
||||||
|
$fieldGroup->add(new TestField('first'));
|
||||||
|
$fieldGroup->add(new TestField('last'));
|
||||||
|
|
||||||
|
$field = new CollectionField($fieldGroup);
|
||||||
|
|
||||||
|
$nameData = (object) array('first' => 'Foo', 'last' => 'Bar');
|
||||||
|
$collectionData = new \ArrayObject(array($nameData));
|
||||||
|
$field->setData($collectionData);
|
||||||
|
|
||||||
|
$boundNameData = (object) array('first' => 'Foo', 'last' => 'Baz');
|
||||||
|
$boundCollectionData = new \ArrayObject(array($nameData));
|
||||||
|
$field->bind($boundCollectionData);
|
||||||
|
|
||||||
|
$this->assertTrue($field->has('0'));
|
||||||
|
$this->assertFalse($field->has('1'));
|
||||||
|
$this->assertEquals($boundNameData, $field[0]->getData());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user