From 7f2e1abf8b934408b78990e57131b2ef31cd4c14 Mon Sep 17 00:00:00 2001 From: Rodrigo Boratto Date: Wed, 21 Sep 2016 16:43:15 -0300 Subject: [PATCH 1/2] fix #106 PR problem (bug #121) --- src/Fieldset.php | 2 +- test/FormTest.php | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/Fieldset.php b/src/Fieldset.php index ea26ad5b..409d878d 100644 --- a/src/Fieldset.php +++ b/src/Fieldset.php @@ -570,7 +570,7 @@ public function bindValues(array $values = [], array $validationGroup = null) foreach ($this->iterator as $element) { $name = $element->getName(); - if ($validationGroup && (array_key_exists($name, $validationGroup) || !in_array($name, $validationGroup))) { + if ($validationGroup && (!array_key_exists($name, $validationGroup) && !in_array($name, $validationGroup))) { continue; } diff --git a/test/FormTest.php b/test/FormTest.php index 7f2841d4..17620901 100644 --- a/test/FormTest.php +++ b/test/FormTest.php @@ -567,6 +567,47 @@ public function testSettingValidationGroupBindsOnlyThoseValuesToModel() $this->assertObjectNotHasAttribute('foobar', $model); } + public function testFormWithCollectionAndValidationGroupBindValuesToModel() + { + $model = new stdClass; + $data = [ + 'foo' => 'abcde', + 'categories' => [ + [ + 'name' => 'category' + ] + ] + ]; + $this->populateForm(); + $this->form->add([ + 'type' => 'Zend\Form\Element\Collection', + 'name' => 'categories', + 'options' => [ + 'count' => 0, + 'target_element' => [ + 'type' => 'ZendTest\Form\TestAsset\CategoryFieldset' + ] + ] + ]); + $this->form->setHydrator(new Hydrator\ObjectProperty()); + $this->form->bind($model); + $this->form->setData($data); + $this->form->setValidationGroup([ + 'foo', + 'categories' => [ + 'name' + ] + ]); + $this->form->isValid(); + + $this->assertObjectHasAttribute('foo', $model); + $this->assertEquals('abcde', $model->foo); + $this->assertObjectHasAttribute('categories', $model); + $this->assertObjectHasAttribute('name', $model->categories[0]); + $this->assertEquals('category', $model->categories[0]->getName()); + $this->assertObjectNotHasAttribute('foobar', $model); + } + public function testSettingValidationGroupWithoutCollectionBindsOnlyThoseValuesToModel() { $model = new stdClass; From 662bf1b8b03a29ba6b29e7007ac11ae029783a88 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Thu, 22 Sep 2016 10:53:01 -0500 Subject: [PATCH 2/2] Added CHANGELOG for #122 --- CHANGELOG.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6f571ff..79c1a165 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All notable changes to this project will be documented in this file, in reverse chronological order by release. -## 2.9.2 - TBD +## 2.9.2 - 2016-09-22 ### Added @@ -18,7 +18,11 @@ All notable changes to this project will be documented in this file, in reverse ### Fixed -- Nothing. +- [#122](https://github.com/zendframework/zend-form/pull/122) fixes collection + binding following successful validation. The fix introduced in #106, while it + corrected the behavior around binding a collection that was not re-submitted, + broke behavior around binding submitted collections. #122 corrects the issue, + retaining the fix from #106. ## 2.9.1 - 2016-09-14