Permalink
Browse files

Merge branch 'hotfix/2716'

Close #2716
  • Loading branch information...
2 parents 17c7687 + 6d31aa4 commit bce7ef3aa7ca284603dfa78d5959561afa9a3afc @weierophinney weierophinney committed Oct 9, 2012
@@ -287,7 +287,14 @@ public function bindValues(array $values = array())
}
$data = $this->prepareBindData($data, $this->data);
- $this->object = parent::bindValues($data);
+
+ // If there is a base fieldset, only hydrate beginning from the base fieldset
+ if ($this->baseFieldset !== null) {
+ $data = $data[$this->baseFieldset->getName()];
+ $this->object = $this->baseFieldset->bindValues($data);
+ } else {
+ $this->object = parent::bindValues($data);
+ }
}
/**
@@ -19,6 +19,7 @@
use Zend\InputFilter\InputFilter;
use Zend\InputFilter\Factory as InputFilterFactory;
use Zend\Stdlib\Hydrator;
+use ZendTest\Form\TestAsset\Entity;
class FormTest extends TestCase
{
@@ -1161,4 +1162,41 @@ public function testResetPasswordValueIfFormIsNotValid()
$this->assertEquals('', $this->form->get('password')->getValue());
}
+
+ public function testCorrectlyHydrateBaseFieldsetWhenHydratorThatDoesNotIgnoreInvalidDataIsUsed()
+ {
+ $fieldset = new Fieldset('example');
+ $fieldset->add(array(
+ 'name' => 'foo'
+ ));
+
+ // Add an hydrator that ignores if values does not exist in the
+ $fieldset->setObject(new Entity\SimplePublicProperty());
+ $fieldset->setHydrator(new \Zend\Stdlib\Hydrator\ObjectProperty());
+
+ $this->form->add($fieldset);
+ $this->form->setBaseFieldset($fieldset);
+ $this->form->setHydrator(new \Zend\Stdlib\Hydrator\ObjectProperty());
+
+ // Add some inputs that do not belong to the base fieldset
+ $this->form->add(array(
+ 'type' => 'Zend\Form\Element\Submit',
+ 'name' => 'submit'
+ ));
+
+ $object = new Entity\SimplePublicProperty();
+ $this->form->bind($object);
+
+ $this->form->setData(array(
+ 'submit' => 'Confirm',
+ 'example' => array(
+ 'foo' => 'value example'
+ )
+ ));
+
+ $this->assertTrue($this->form->isValid());
+
+ // Make sure the object was not hydrated at the "form level"
+ $this->assertFalse(isset($object->submit));
+ }
}
@@ -0,0 +1,16 @@
+<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @package Zend_Form
+ */
+
+namespace ZendTest\Form\TestAsset\Entity;
+
+class SimplePublicProperty
+{
+ public $foo;
+}
@@ -62,7 +62,7 @@ public function setUp()
public function tearDown()
{
// remove captcha images
- foreach (new DirectoryIterator($this->testDir) as $file) {
+ foreach (new DirectoryIterator($this->tmpDir) as $file) {
if (!$file->isDot() && !$file->isDir()) {
unlink($file->getPathname());
}

0 comments on commit bce7ef3

Please sign in to comment.