Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix#3373 #4123

Closed
wants to merge 2 commits into from

2 participants

@bartmcleod

Provides a fix, a unit test and three test assets for issue #3373

bartmcleod added some commits
@bartmcleod bartmcleod fix for #3373 f2daf50
@bartmcleod bartmcleod Making sure this branch isn't behind master
Merge remote-tracking branch 'zf2/master' into fix#3373
be1c091
@weierophinney weierophinney referenced this pull request from a commit
@weierophinney weierophinney [#4123] CS fixes
- EOF ending
f9a2e6c
@weierophinney weierophinney closed this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/4123'
Close #4123
Fixes #3373
dce846c
@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney [#4123] CS fixes
- EOF ending
5264864
@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/4123'
Close #4123
Fixes #3373
2a192e3
@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/4123' into develop
Forward port #4123
db24f5d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 26, 2013
  1. @bartmcleod

    fix for #3373

    bartmcleod authored
  2. @bartmcleod

    Making sure this branch isn't behind master

    bartmcleod authored
    Merge remote-tracking branch 'zf2/master' into fix#3373
This page is out of date. Refresh to see the latest.
View
4 library/Zend/Form/Form.php
@@ -272,7 +272,9 @@ public function setHydrator(HydratorInterface $hydrator)
public function bindValues(array $values = array())
{
if (!is_object($this->object)) {
- return;
+ if ( $this->baseFieldset === null || $this->baseFieldset->allowValueBinding() == false ) {
+ return;
+ }
}
if (!$this->hasValidated() && !empty($values)) {
$this->setData($values);
View
56 tests/ZendTest/Form/FormTest.php
@@ -995,6 +995,62 @@ public function testCanCorrectlyPopulateDataToOneToManyEntites()
$this->assertEquals($product, $emptyProduct, var_export($product, 1) . "\n\n" . var_export($emptyProduct, 1));
}
+ public function testCanCorrectlyPopulateOrphanedEntities()
+ {
+ if (!extension_loaded('intl')) {
+ $this->markTestSkipped("The Intl extension is not loaded");
+ }
+
+ $form = new TestAsset\OrphansForm();
+
+ $data = array(
+ 'test' => array(
+ array(
+ 'name' => 'Foo'
+ ),
+ array(
+ 'name' => 'Bar'
+ ),
+ )
+ );
+
+ $form->setData($data);
+ $valid = $form->isValid();
+ $this->assertEquals(true, $valid);
+
+ $formCollections = $form->getFieldsets();
+ $formCollection = $formCollections['test'];
+
+ $fieldsets = $formCollection->getFieldsets();
+
+ $fieldsetFoo = $fieldsets[0];
+ $fieldsetBar = $fieldsets[1];
+
+ $objectFoo = $fieldsetFoo->getObject();
+ $this->assertTrue(
+ $objectFoo instanceof Entity\Orphan,
+ 'FormCollection with orphans does not bind objects from fieldsets'
+ );
+
+ $objectBar = $fieldsetBar->getObject();
+ $this->assertTrue(
+ $objectBar instanceof Entity\Orphan,
+ 'FormCollection with orphans does not bind objects from fieldsets'
+ );
+
+ $this->assertSame(
+ 'Foo',
+ $objectFoo->name,
+ 'Object is not populated if it is an orphan in a fieldset inside a formCollection'
+ );
+
+ $this->assertSame(
+ 'Bar',
+ $objectBar->name,
+ 'Object is not populated if it is an orphan in a fieldset inside a formCollection'
+ );
+ }
+
public function testAssertElementsNamesAreNotWrappedAroundFormNameByDefault()
{
$form = new \ZendTest\Form\TestAsset\FormCollection();
View
30 tests/ZendTest/Form/TestAsset/Entity/Orphan.php
@@ -0,0 +1,30 @@
+<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2013 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 Orphan
+{
+ /**
+ * Name
+ * @var string
+ */
+ public $name;
+
+ public function getArrayCopy()
+ {
+ return get_object_vars($this);
+ }
+
+ public function exchangeArray($data = array())
+ {
+ $this->name = $data['name'];
+ }
+}
View
43 tests/ZendTest/Form/TestAsset/OrphansFieldset.php
@@ -0,0 +1,43 @@
+<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2013 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;
+
+use Zend\Form\Fieldset;
+use Zend\InputFilter\InputFilterProviderInterface;
+use Zend\Stdlib\Hydrator\ArraySerializable;
+use ZendTest\Form\TestAsset\Entity\Orphan;
+
+class OrphansFieldset extends Fieldset implements InputFilterProviderInterface
+{
+ public function __construct( $name = null, $options = array() )
+ {
+ parent::__construct( $name, $options );
+
+ $this->setHydrator(new ArraySerializable())
+ ->setObject(new Orphan());
+
+ $this->add(array(
+ 'name' => 'name',
+ 'options' => array('label' => 'Name field'),
+ ));
+ }
+
+ public function getInputFilterSpecification()
+ {
+ return array(
+ 'name' => array(
+ 'required' => false,
+ 'filters' => array(),
+ 'validators' => array(),
+ )
+ );
+ }
+}
View
60 tests/ZendTest/Form/TestAsset/OrphansForm.php
@@ -0,0 +1,60 @@
+<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2013 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;
+
+use Zend\Form\Form;
+
+class OrphansForm extends Form
+{
+ public function __construct()
+ {
+ parent::__construct('orphans');
+
+ $this->setAttribute('method', 'post')
+ ->setBindOnValidate(self::BIND_ON_VALIDATE)
+ ->setInputFilter(new InputFilter());
+
+ //adds a collection of 2
+ $this->add(
+ array(
+ 'type' => '\Zend\Form\Element\Collection',
+ 'name' => 'test',
+ 'options' => array(
+ 'use_as_base_fieldset' => true,
+ 'count' => 2,
+ 'should_create_template' => true,
+ 'allow_add' => true,
+ 'target_element' => array(
+ 'type' => '\ZendTest\Form\TestAsset\OrphansFieldset'
+ ),
+ )
+ )
+ );
+
+ $this->add(
+ array(
+ 'name' => 'submit',
+ 'attributes' => array(
+ 'type' => 'submit',
+ 'value' => 'Send'
+ )
+ )
+ );
+
+ $this->setValidationGroup(
+ array(
+ 'test' => array(
+ 'name',
+ ),
+ )
+ );
+ }
+}
Something went wrong with that request. Please try again.