Hotfix/multiple nested collection test #5495

Closed
wants to merge 6 commits into
from

Conversation

Projects
None yet
4 participants
@fabiocarneiro
Contributor

fabiocarneiro commented Nov 18, 2013

Tests for making sure we can bind objects to multiple fieldsets and collections

@Maks3w

View changes

tests/ZendTest/Form/Element/CollectionTest.php
+ public function testCanBindObjectMultipleNestedFieldsets()
+ {
+
+ $productFieldset = new \ZendTest\Form\TestAsset\ProductFieldset();

This comment has been minimized.

@Maks3w

Maks3w Nov 18, 2013

Member

please import the classes using use statements.

@Maks3w

Maks3w Nov 18, 2013

Member

please import the classes using use statements.

This comment has been minimized.

@fabiocarneiro

fabiocarneiro Nov 19, 2013

Contributor

I've copied it from the function above. The class is full of that.

@fabiocarneiro

fabiocarneiro Nov 19, 2013

Contributor

I've copied it from the function above. The class is full of that.

This comment has been minimized.

@fabiocarneiro

fabiocarneiro Nov 19, 2013

Contributor

@Maks3w There it is!

@fabiocarneiro

fabiocarneiro Nov 19, 2013

Contributor

@Maks3w There it is!

@thestanislav

View changes

tests/ZendTest/Form/Element/CollectionTest.php
+ $shop[1] = new stdClass();
+ $shop[1]->products = $products;
+
+ $market->collection = $shop;

This comment has been minimized.

@thestanislav

thestanislav Nov 19, 2013

Contributor

I do no see any element named "collection" in the form

@thestanislav

thestanislav Nov 19, 2013

Contributor

I do no see any element named "collection" in the form

This comment has been minimized.

@fabiocarneiro

fabiocarneiro Nov 19, 2013

Contributor

You're right!

@fabiocarneiro

fabiocarneiro Nov 19, 2013

Contributor

You're right!

+ ),
+ ));
+
+ $mainFieldset = new Fieldset('main');

This comment has been minimized.

@thestanislav

thestanislav Nov 19, 2013

Contributor

And once again, $mainFieldset should be Collection according to the object. You've mixed up with fieldsets and binding object

@thestanislav

thestanislav Nov 19, 2013

Contributor

And once again, $mainFieldset should be Collection according to the object. You've mixed up with fieldsets and binding object

This comment has been minimized.

@fabiocarneiro

fabiocarneiro Nov 19, 2013

Contributor

Form has a mainFieldset, that has a collection of nestedFieldset, that has a collection of productFieldset. the missing part is useasbasefieldset.

@fabiocarneiro

fabiocarneiro Nov 19, 2013

Contributor

Form has a mainFieldset, that has a collection of nestedFieldset, that has a collection of productFieldset. the missing part is useasbasefieldset.

This comment has been minimized.

@thestanislav

thestanislav Nov 19, 2013

Contributor

Should be something like this

$form = new Form();
$form->setHydrator(new ObjectPropertyHydrator());

$form->add(array(
            'name' => 'main',
            'type' => 'Collection',
            'options' => array(
                'target_element' => $nestedFieldset,
                'count' => 2
            ),
));
@thestanislav

thestanislav Nov 19, 2013

Contributor

Should be something like this

$form = new Form();
$form->setHydrator(new ObjectPropertyHydrator());

$form->add(array(
            'name' => 'main',
            'type' => 'Collection',
            'options' => array(
                'target_element' => $nestedFieldset,
                'count' => 2
            ),
));

This comment has been minimized.

@thestanislav

thestanislav Nov 19, 2013

Contributor

Assume this:
Fieldset = object
Collection = array/Traversable
Element = object property/class method

@thestanislav

thestanislav Nov 19, 2013

Contributor

Assume this:
Fieldset = object
Collection = array/Traversable
Element = object property/class method

This comment has been minimized.

@thestanislav

thestanislav Nov 19, 2013

Contributor

$market -> $form
$shop -> "main" fieldset but should be a collection
????? -> "nested" collection
.....

@thestanislav

thestanislav Nov 19, 2013

Contributor

$market -> $form
$shop -> "main" fieldset but should be a collection
????? -> "nested" collection
.....

This comment has been minimized.

@fabiocarneiro

fabiocarneiro Nov 19, 2013

Contributor

I want to achieve two levels of collections.
Form
--> Fieldset
--> --> Collection
--> --> --> Fieldset
--> --> --> --> Collection
--> --> --> --> --> Fieldset

@fabiocarneiro

fabiocarneiro Nov 19, 2013

Contributor

I want to achieve two levels of collections.
Form
--> Fieldset
--> --> Collection
--> --> --> Fieldset
--> --> --> --> Collection
--> --> --> --> --> Fieldset

@thestanislav

This comment has been minimized.

Show comment
Hide comment
@thestanislav

thestanislav Nov 19, 2013

Contributor

I think i understand your issue.
As I know you should always bind an empty objects to your fieldsets. Look this https://github.com/zendframework/zf2/blob/master/tests/ZendTest/Form/TestAsset/ProductFieldset.php#L23

So you should do something like these

$nestedFieldset = new Fieldset('nested');
$nestedFieldset = new Fieldset('nested');
$nestedFieldset->setHydrator(new ClassMethods());
$nestedFieldset->setObject(new Stdclass()); // or what ever you object is

....
....
....
$mainFieldset = new Fieldset('main');
$mainFieldset->setHydrator(new ClassMethods());
$mainFieldset->setObject(new Stdclass()); // or what ever you object is

Otherwise nested objects would not bound to appropriate fieldsets

Contributor

thestanislav commented Nov 19, 2013

I think i understand your issue.
As I know you should always bind an empty objects to your fieldsets. Look this https://github.com/zendframework/zf2/blob/master/tests/ZendTest/Form/TestAsset/ProductFieldset.php#L23

So you should do something like these

$nestedFieldset = new Fieldset('nested');
$nestedFieldset = new Fieldset('nested');
$nestedFieldset->setHydrator(new ClassMethods());
$nestedFieldset->setObject(new Stdclass()); // or what ever you object is

....
....
....
$mainFieldset = new Fieldset('main');
$mainFieldset->setHydrator(new ClassMethods());
$mainFieldset->setObject(new Stdclass()); // or what ever you object is

Otherwise nested objects would not bound to appropriate fieldsets

@fabiocarneiro

This comment has been minimized.

Show comment
Hide comment
@fabiocarneiro

fabiocarneiro Nov 19, 2013

Contributor

I'm not doing it in the test, but i am doing in my actual code. If you could test it, it would be really awesome. I know its a bit too much to ask, but i'm on that issue for more than one week and i really need it working to move ahead.
https://github.com/fabiocarneiro/FhcsFormTest

I'ts a really simplified use case with only the necessary things.

Nested objects should be bound to the appropriate fieldsets, if its not doing it right now, it should be fixed, and i've been working hard to fix that, with no success.

Contributor

fabiocarneiro commented Nov 19, 2013

I'm not doing it in the test, but i am doing in my actual code. If you could test it, it would be really awesome. I know its a bit too much to ask, but i'm on that issue for more than one week and i really need it working to move ahead.
https://github.com/fabiocarneiro/FhcsFormTest

I'ts a really simplified use case with only the necessary things.

Nested objects should be bound to the appropriate fieldsets, if its not doing it right now, it should be fixed, and i've been working hard to fix that, with no success.

@weierophinney

This comment has been minimized.

Show comment
Hide comment
@weierophinney

weierophinney Mar 3, 2014

Member

@fabiocarneiro Have you been able to investigate this any further? Perhaps ping Bakura in #zftalk.dev on Freenode IRC to see if he can assist.

Member

weierophinney commented Mar 3, 2014

@fabiocarneiro Have you been able to investigate this any further? Perhaps ping Bakura in #zftalk.dev on Freenode IRC to see if he can assist.

weierophinney added a commit that referenced this pull request Mar 3, 2014

[#5502] Added test from #5495
- Unit test passes now, meaning we can close both issues.

@weierophinney weierophinney added this to the 2.2.6 milestone Mar 3, 2014

@weierophinney weierophinney self-assigned this Mar 3, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment