Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 8, 2020. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion library/Zend/Form/Element/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ public function populateValues($data)

// Can't do anything with empty data
if (empty($data)) {
$this->shouldCreateChildrenOnPrepareElement = false;
return;
}

Expand Down
50 changes: 50 additions & 0 deletions tests/ZendTest/Form/Element/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -784,4 +784,54 @@ public function testNestedCollections()
$index++;
}
}

public function testSetDataOnFormPopulatesCollection()
{
$form = new Form();
$form->add(array(
'name' => 'names',
'type' => 'Collection',
'options' => array(
'target_element' => new Element\Text(),
),
));

$names = array('foo', 'bar', 'baz', 'bat');

$form->setData(array(
'names' => $names
));

$this->assertCount(count($names), $form->get('names'));

$i = 0;
foreach($form->get('names') as $field) {
$this->assertEquals($names[$i], $field->getValue());
$i++;
};
}

public function testSettingSomeDataButNoneForCollectionReturnsSpecifiedNumberOfElementsAfterPrepare()
{
$form = new Form();
$form->add(new Element\Text('input'));
$form->add(array(
'name' => 'names',
'type' => 'Collection',
'options' => array(
'target_element' => new Element\Text(),
'count' => 2
),
));

$form->setData(array(
'input' => 'foo',
));

$this->assertCount(0, $form->get('names'));

$form->prepare();

$this->assertCount(2, $form->get('names'));
}
}