Skip to content

Commit

Permalink
Merge remote-tracking branch 'macnibblet/macnibblet/hotfix/form-field…
Browse files Browse the repository at this point in the history
…set'
  • Loading branch information
akrabat committed Jul 9, 2012
2 parents 402074c + 5a5df38 commit bc59012
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
14 changes: 14 additions & 0 deletions library/Zend/Form/Element/Collection.php
Expand Up @@ -133,6 +133,20 @@ public function setOptions($options)
*/
public function populateValues($data)
{
if (!is_array($data) && !$data instanceof Traversable) {
throw new Exception\InvalidArgumentException(sprintf(
'%s expects an array or Traversable set of data; received "%s"',
__METHOD__,
(is_object($data) ? get_class($data) : gettype($data))
));
}

// Can't do anything with empty data
if (empty($data)) {

return;
}

if ($this->targetElement instanceof FieldsetInterface) {
foreach ($this->byName as $name => $fieldset) {
$fieldset->populateValues($data[$name]);
Expand Down
6 changes: 6 additions & 0 deletions tests/Zend/Form/FieldsetTest.php
Expand Up @@ -98,6 +98,12 @@ public function getMessages()
);
}

public function testExtractOnAnEmptyRelationship()
{
$form = new TestAsset\FormCollection();
$form->populateValues(array('fieldsets' => array()));
}

public function testFieldsetIsEmptyByDefault()
{
$this->assertEquals(0, count($this->fieldset));
Expand Down

0 comments on commit bc59012

Please sign in to comment.