Permalink
Browse files

Merge branch 'hotfix/5923' into develop

Close #5923
Fixes #5906
  • Loading branch information...
2 parents b06a6c7 + bef8443 commit 4599c6cedbb951b743b950698c437243d158cfe7 @weierophinney weierophinney committed Mar 7, 2014
Showing with 50 additions and 1 deletion.
  1. +0 −1 library/Zend/Form/Element/Collection.php
  2. +50 −0 tests/ZendTest/Form/Element/CollectionTest.php
@@ -197,7 +197,6 @@ public function populateValues($data)
// Can't do anything with empty data
if (empty($data)) {
- $this->shouldCreateChildrenOnPrepareElement = false;
return;
}
@@ -823,4 +823,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'));
+ }
}

0 comments on commit 4599c6c

Please sign in to comment.