Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix for #2541 #2976

Closed
wants to merge 2 commits into from

3 participants

@davidwindell

In the case where an empty array is sent to a form with sub-fieldset, the validation group was never being prepared.

This resolves #2541, tests pass.

@Maks3w
Collaborator

Please add a test case

@davidwindell

@Maks3w done, this will fail against current master but pass with my changes

@weierophinney

Nice test case, @davidwindell ! Merged!

@davidwindell

Thanks Matthew!

@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/2976'
Close #2976
a2facc2
@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/2976' into develop
Forward port #2976
18526bc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 15, 2012
  1. @davidwindell

    Fix for #2541

    davidwindell authored
Commits on Nov 19, 2012
  1. @davidwindell

    Added test for #2541

    davidwindell authored
This page is out of date. Refresh to see the latest.
Showing with 31 additions and 2 deletions.
  1. +3 −2 library/Zend/Form/Form.php
  2. +28 −0 tests/ZendTest/Form/FormTest.php
View
5 library/Zend/Form/Form.php
@@ -559,9 +559,10 @@ protected function prepareValidationGroup(FieldsetInterface $formOrFieldset, arr
$value = $values;
} else {
- if (isset($data[$key])) {
- $this->prepareValidationGroup($fieldset, $data[$key], $validationGroup[$key]);
+ if (!isset($data[$key])) {
+ $data[$key] = array();
}
+ $this->prepareValidationGroup($fieldset, $data[$key], $validationGroup[$key]);
}
}
}
View
28 tests/ZendTest/Form/FormTest.php
@@ -1025,6 +1025,34 @@ public function testRemoveCollectionFromValidationGroupWhenZeroCountAndNoData()
$this->assertTrue($this->form->isValid());
}
+ public function testFieldsetValidationGroupStillPreparedWhenEmptyData()
+ {
+ $emptyData = array();
+
+ $this->populateForm();
+ $this->form->get('foobar')->add(array(
+ 'type' => 'Zend\Form\Element\Collection',
+ 'name' => 'categories',
+ 'options' => array(
+ 'count' => 0,
+ 'target_element' => array(
+ 'type' => 'ZendTest\Form\TestAsset\CategoryFieldset'
+ )
+ )
+ ));
+
+ $this->form->setValidationGroup(array(
+ 'foobar' => array(
+ 'categories' => array(
+ 'name'
+ )
+ )
+ ));
+
+ $this->form->setData($emptyData);
+ $this->assertFalse($this->form->isValid());
+ }
+
public function testApplyObjectInputFilterToBaseFieldsetAndApplyValidationGroup()
{
$fieldset = new Fieldset('foobar');
Something went wrong with that request. Please try again.