Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/2716'
Browse files Browse the repository at this point in the history
Close #2716
  • Loading branch information
weierophinney committed Oct 9, 2012
2 parents ccefd4f + a435cf6 commit cf33738
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
9 changes: 8 additions & 1 deletion library/Zend/Form/Form.php
Expand Up @@ -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);
}
}

/**
Expand Down
38 changes: 38 additions & 0 deletions tests/ZendTest/Form/FormTest.php
Expand Up @@ -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
{
Expand Down Expand Up @@ -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));
}
}
16 changes: 16 additions & 0 deletions tests/ZendTest/Form/TestAsset/Entity/SimplePublicProperty.php
@@ -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;
}
2 changes: 1 addition & 1 deletion tests/ZendTest/Form/View/Helper/Captcha/ImageTest.php
Expand Up @@ -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());
}
Expand Down

0 comments on commit cf33738

Please sign in to comment.