From 08e09a35ce1cf68263b7275c6c0c17b0be277b9a Mon Sep 17 00:00:00 2001 From: blanchonvincent Date: Wed, 16 Apr 2014 12:43:26 +0200 Subject: [PATCH 1/4] Add fail test case --- .../ZendTest/Form/Element/CollectionTest.php | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/ZendTest/Form/Element/CollectionTest.php b/tests/ZendTest/Form/Element/CollectionTest.php index d8599b73392..cfd4999bdff 100644 --- a/tests/ZendTest/Form/Element/CollectionTest.php +++ b/tests/ZendTest/Form/Element/CollectionTest.php @@ -150,6 +150,32 @@ public function testCanValidateFormWithCollectionWithoutTemplate() $this->assertEquals(true, $this->form->isValid()); } + public function testCannotValidateFormWithCollectionWithBadColor() + { + $this->form->setData(array( + 'colors' => array( + '#ffffff', + '123465' + ), + 'fieldsets' => array( + array( + 'field' => 'oneValue', + 'nested_fieldset' => array( + 'anotherField' => 'anotherValue' + ) + ), + array( + 'field' => 'twoValue', + 'nested_fieldset' => array( + 'anotherField' => 'anotherValue' + ) + ) + ) + )); + + $this->assertEquals(false, $this->form->isValid()); + } + public function testCanValidateFormWithCollectionWithTemplate() { $collection = $this->form->get('colors'); From a50698d776cc1442f6bee453492d81a1c0c6bca5 Mon Sep 17 00:00:00 2001 From: blanchonvincent Date: Wed, 16 Apr 2014 12:43:45 +0200 Subject: [PATCH 2/4] Fix collection with element validation --- library/Zend/Form/Form.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/Zend/Form/Form.php b/library/Zend/Form/Form.php index 637fbf0d28b..5beeb3864a4 100644 --- a/library/Zend/Form/Form.php +++ b/library/Zend/Form/Form.php @@ -760,7 +760,7 @@ public function attachInputFilterDefaults(InputFilterInterface $inputFilter, Fie $elements = $fieldset->getElements(); } - if (!$fieldset instanceof Collection || $inputFilter instanceof CollectionInputFilter) { + if (!$fieldset instanceof Collection || !$fieldset->getTargetElement() instanceof FieldsetInterface || $inputFilter instanceof CollectionInputFilter) { foreach ($elements as $element) { $name = $element->getName(); From 964f690b64826dd9ce1514d5ec5dec4b5865c823 Mon Sep 17 00:00:00 2001 From: blanchonvincent Date: Wed, 16 Apr 2014 12:49:15 +0200 Subject: [PATCH 3/4] Add error message assertion --- tests/ZendTest/Form/Element/CollectionTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/ZendTest/Form/Element/CollectionTest.php b/tests/ZendTest/Form/Element/CollectionTest.php index cfd4999bdff..dba2da7af4e 100644 --- a/tests/ZendTest/Form/Element/CollectionTest.php +++ b/tests/ZendTest/Form/Element/CollectionTest.php @@ -174,6 +174,8 @@ public function testCannotValidateFormWithCollectionWithBadColor() )); $this->assertEquals(false, $this->form->isValid()); + $messages = $this->form->getMessages(); + $this->assertArrayHasKey('colors', $messages); } public function testCanValidateFormWithCollectionWithTemplate() From f5758d8b61515b64b0d65219497720b888c715b4 Mon Sep 17 00:00:00 2001 From: blanchonvincent Date: Wed, 16 Apr 2014 12:53:18 +0200 Subject: [PATCH 4/4] Add assertion with fieldset inside collection --- .../ZendTest/Form/Element/CollectionTest.php | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/ZendTest/Form/Element/CollectionTest.php b/tests/ZendTest/Form/Element/CollectionTest.php index dba2da7af4e..abb90cc9782 100644 --- a/tests/ZendTest/Form/Element/CollectionTest.php +++ b/tests/ZendTest/Form/Element/CollectionTest.php @@ -178,6 +178,35 @@ public function testCannotValidateFormWithCollectionWithBadColor() $this->assertArrayHasKey('colors', $messages); } + public function testCannotValidateFormWithCollectionWithBadFieldsetField() + { + $this->form->setData(array( + 'colors' => array( + '#ffffff', + '#ffffff' + ), + 'fieldsets' => array( + array( + 'field' => 'oneValue', + 'nested_fieldset' => array( + 'anotherField' => 'anotherValue' + ) + ), + array( + 'field' => 'twoValue', + 'nested_fieldset' => array( + 'anotherField' => null, + ) + ) + ) + )); + + $this->assertEquals(false, $this->form->isValid()); + $messages = $this->form->getMessages(); + $this->assertCount(1, $messages); + $this->assertArrayHasKey('fieldsets', $messages); + } + public function testCanValidateFormWithCollectionWithTemplate() { $collection = $this->form->get('colors');