-
Notifications
You must be signed in to change notification settings - Fork 87
Form::getMessages() on plain array collection - fix for issue #135 #136
Conversation
test/FieldsetTest.php
Outdated
*/ | ||
public function testRetrieveErrorMessagesForArrayInputCollection() | ||
{ | ||
$form = new TestAsset\ArrayInputCollectionForm(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please test here the Fieldset
not the Form
class or the Collection
element.
test/FieldsetTest.php
Outdated
$messages = $form->getMessages(); | ||
|
||
$this->assertArrayHasKey('foo', $messages); | ||
$this->assertArrayNotHasKey('bar', $messages); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is bar
and why do you test it?
use Zend\InputFilter\ArrayInput; | ||
use Zend\InputFilter\InputFilterProviderInterface; | ||
|
||
class ArrayInputCollectionForm extends Form\Form implements InputFilterProviderInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, the class is not needed. Please have a look at ZendTest\Form\Element\CollectionTest
.
@froschdesign I think about the test again and again. Basically this patch allows storing messages for elements which are not founds. It does not break any other test. I would rewrite test to:
agreed? |
@vaclavvanik This works with your changes: // ZendTest\Form\Element\CollectionTest
public function testGetErrorMessagesForInvalidCollectionElements()
{
// Configure InputFilter
$inputFilter = $this->form->getInputFilter();
$inputFilter->add(
[
'name' => 'colors',
'type' => ArrayInput::class,
'required' => true,
]
);
$inputFilter->add(
[
'name' => 'fieldsets',
'type' => ArrayInput::class,
'required' => true,
]
);
$this->form->setData([]);
$this->form->isValid();
$this->assertEquals(
[
'colors' => [
'isEmpty' => "Value is required and can't be empty",
],
'fieldsets' => [
'isEmpty' => "Value is required and can't be empty",
],
],
$this->form->getMessages()
);
} |
First look at Code from
Error messages are set only when validation fails. This test is imho unrelated to my patch. |
Right, the My original intention: we need another test for the Collection element. (based on
All error messages received? |
@froschdesign tests updated. I hope I did not miss anything. |
@froschdesign can you merge if don't have any other ideas? |
Why is this change on the Fieldset class and not the Collection class? |
@akrabat |
I mean, why isn't this fixed as new methods i.e. does this bug affect |
Right! |
That's a "yes it does" I assume. Next question. Will this have any side-effects for people using normal elements inside |
@akrabat
No and the unit tests for these scenarios says the same. |
Form::getMessages() on plain array collection - fix for issue #135
Thanks, @vaclavvanik |
I used this fix. If anyone has better idea let me know!