Skip to content

Commit

Permalink
[Form] Test case for binding a collection of field groups with an Arr…
Browse files Browse the repository at this point in the history
…ayObject of objects.
  • Loading branch information
Jeremy Mikola committed Sep 9, 2010
1 parent b3648b2 commit 9f5469f
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/Symfony/Tests/Component/Form/CollectionFieldTest.php
Expand Up @@ -5,6 +5,7 @@
require_once __DIR__ . '/Fixtures/TestField.php';

use Symfony\Component\Form\CollectionField;
use Symfony\Component\Form\FieldGroup;
use Symfony\Tests\Component\Form\Fixtures\TestField;


Expand Down Expand Up @@ -96,4 +97,25 @@ public function testResizedIfBoundWithExtraDataAndModifiable()
$this->assertEquals('foo@foo.com', $field[0]->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());
}
}

0 comments on commit 9f5469f

Please sign in to comment.