From 294a7d18a832ce5eb297b43832c2b67db77fb425 Mon Sep 17 00:00:00 2001 From: Carlos Date: Tue, 18 Sep 2012 21:07:12 -0500 Subject: [PATCH 1/8] Trying to solve the issue ZF2-558 with the solution provided by Chris Willis, if you set the options values and you have InArray Validator the patch update the validator too --- library/Zend/Form/Element/MultiCheckbox.php | 7 +++++++ library/Zend/Form/Element/Select.php | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/library/Zend/Form/Element/MultiCheckbox.php b/library/Zend/Form/Element/MultiCheckbox.php index ad7d1311b97..4338dfa069a 100644 --- a/library/Zend/Form/Element/MultiCheckbox.php +++ b/library/Zend/Form/Element/MultiCheckbox.php @@ -62,6 +62,13 @@ public function getValueOptions() public function setValueOptions(array $options) { $this->valueOptions = $options; + + // Update InArray validator haystack + if (!is_null($this->validator)) { + $validator = $this->validator->getValidator(); + $validator->setHaystack($this->getValueOptionsValues()); + } + return $this; } diff --git a/library/Zend/Form/Element/Select.php b/library/Zend/Form/Element/Select.php index 48984c3623a..e08c16bed79 100644 --- a/library/Zend/Form/Element/Select.php +++ b/library/Zend/Form/Element/Select.php @@ -80,6 +80,13 @@ public function getValueOptions() public function setValueOptions(array $options) { $this->valueOptions = $options; + + // Update InArray validator haystack + if (!is_null($this->validator)) { + $validator = $this->validator instanceof InArray ? $this->validator : $this->validator->getValidator(); + $validator->setHaystack($this->getValueOptionsValues()); + } + return $this; } From 555519356b7322b0807de1f3dff1f2be937128d7 Mon Sep 17 00:00:00 2001 From: igor Date: Thu, 20 Sep 2012 16:46:01 -0500 Subject: [PATCH 2/8] Changed InArray for InArrayValidator that is used as alias --- library/Zend/Form/Element/Select.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/Zend/Form/Element/Select.php b/library/Zend/Form/Element/Select.php index e08c16bed79..f6749fd3cca 100644 --- a/library/Zend/Form/Element/Select.php +++ b/library/Zend/Form/Element/Select.php @@ -81,9 +81,9 @@ public function setValueOptions(array $options) { $this->valueOptions = $options; - // Update InArray validator haystack + // Update InArrayValidator validator haystack if (!is_null($this->validator)) { - $validator = $this->validator instanceof InArray ? $this->validator : $this->validator->getValidator(); + $validator = $this->validator instanceof InArrayValidator ? $this->validator : $this->validator->getValidator(); $validator->setHaystack($this->getValueOptionsValues()); } From df521d315748696ef48471396b1e1d51e53f40dc Mon Sep 17 00:00:00 2001 From: igor Date: Thu, 20 Sep 2012 17:06:11 -0500 Subject: [PATCH 3/8] Created unit test for the change --- library/Zend/Form/Element/Select.php | 2 +- tests/ZendTest/Form/Element/SelectTest.php | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/library/Zend/Form/Element/Select.php b/library/Zend/Form/Element/Select.php index f6749fd3cca..d1c2c9b6dce 100644 --- a/library/Zend/Form/Element/Select.php +++ b/library/Zend/Form/Element/Select.php @@ -86,7 +86,7 @@ public function setValueOptions(array $options) $validator = $this->validator instanceof InArrayValidator ? $this->validator : $this->validator->getValidator(); $validator->setHaystack($this->getValueOptionsValues()); } - + return $this; } diff --git a/tests/ZendTest/Form/Element/SelectTest.php b/tests/ZendTest/Form/Element/SelectTest.php index bb0f6fff26f..085c6e54713 100644 --- a/tests/ZendTest/Form/Element/SelectTest.php +++ b/tests/ZendTest/Form/Element/SelectTest.php @@ -151,6 +151,28 @@ public function testInArrayValidationOfOptions($valueTests, $options) $this->assertTrue($inArrayValidator->isValid($valueToTest)); } } + + /** + * Testing that InArray Validator Haystack is Updated if the Options + * are added after the validator is attached + * + * @dataProvider selectOptionsDataProvider + */ + public function testInArrayValidatorHaystakIsUpdated($valueTests, $options) + { + $element = new SelectElement('my-select'); + $inputSpec = $element->getInputSpecification(); + + $explodeValidator = $inputSpec['validators'][0]; + $this->assertInstanceOf('Zend\Validator\InArray', $explodeValidator); + + $element->setAttributes(array( + 'options' => $options, + )); + $haystack=$explodeValidator->getHaystack(); + $this->assertCount(count($options), $haystack); + } + public function testOptionsHasArrayOnConstruct() { From 50c85396a047b82ebc7c07c8ba187093c3e8c280 Mon Sep 17 00:00:00 2001 From: igor Date: Thu, 20 Sep 2012 17:12:42 -0500 Subject: [PATCH 4/8] Changing the var name for the Inarray Validator within the test method --- tests/ZendTest/Form/Element/SelectTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ZendTest/Form/Element/SelectTest.php b/tests/ZendTest/Form/Element/SelectTest.php index 085c6e54713..3d712766add 100644 --- a/tests/ZendTest/Form/Element/SelectTest.php +++ b/tests/ZendTest/Form/Element/SelectTest.php @@ -163,8 +163,8 @@ public function testInArrayValidatorHaystakIsUpdated($valueTests, $options) $element = new SelectElement('my-select'); $inputSpec = $element->getInputSpecification(); - $explodeValidator = $inputSpec['validators'][0]; - $this->assertInstanceOf('Zend\Validator\InArray', $explodeValidator); + $inArrayValidator = $inputSpec['validators'][0]; + $this->assertInstanceOf('Zend\Validator\InArray', $inArrayValidator); $element->setAttributes(array( 'options' => $options, From 9d57fd91b6846a043a4c176d9733dca22715ff0f Mon Sep 17 00:00:00 2001 From: igor Date: Thu, 20 Sep 2012 17:13:37 -0500 Subject: [PATCH 5/8] Changing the last apparence of the old var name for the InArray validator --- tests/ZendTest/Form/Element/SelectTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ZendTest/Form/Element/SelectTest.php b/tests/ZendTest/Form/Element/SelectTest.php index 3d712766add..3e9172bcb8a 100644 --- a/tests/ZendTest/Form/Element/SelectTest.php +++ b/tests/ZendTest/Form/Element/SelectTest.php @@ -169,7 +169,7 @@ public function testInArrayValidatorHaystakIsUpdated($valueTests, $options) $element->setAttributes(array( 'options' => $options, )); - $haystack=$explodeValidator->getHaystack(); + $haystack=$inArrayValidator->getHaystack(); $this->assertCount(count($options), $haystack); } From 22768c61622cea9afa952b5d8d43df589f12c7f8 Mon Sep 17 00:00:00 2001 From: igor Date: Thu, 20 Sep 2012 17:23:46 -0500 Subject: [PATCH 6/8] Adding the Unit testing method for the modification on Zend/Form/Element/MultiCheckbox --- .../Form/Element/MultiCheckboxTest.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/ZendTest/Form/Element/MultiCheckboxTest.php b/tests/ZendTest/Form/Element/MultiCheckboxTest.php index 903eea3688b..b573112e8ca 100644 --- a/tests/ZendTest/Form/Element/MultiCheckboxTest.php +++ b/tests/ZendTest/Form/Element/MultiCheckboxTest.php @@ -105,6 +105,26 @@ public function testInArrayValidationOfOptions($valueTests, $options) $this->assertTrue($explodeValidator->isValid($valueTests)); } + /** + * Testing that InArray Validator Haystack is Updated if the Options + * are added after the validator is attached + * + * @dataProvider multiCheckboxOptionsDataProvider + */ + public function testInArrayValidatorHaystakIsUpdated($valueTests, $options) + { + $element = new MultiCheckboxElement('my-checkbox'); + $inputSpec = $element->getInputSpecification(); + $inArrayValidator=$inputSpec['validators'][0]->getValidator(); + + $element->setAttributes(array( + 'options' => $options, + )); + $haystack=$inArrayValidator->getHaystack(); + $this->assertCount(count($options), $haystack); + } + + public function testAttributeType() { $element = new MultiCheckboxElement(); From b04198f4d6e0057bedc8e14365575adb1349cc31 Mon Sep 17 00:00:00 2001 From: igor Date: Fri, 21 Sep 2012 08:51:15 -0500 Subject: [PATCH 7/8] fixing Coding Standards for the added code --- library/Zend/Form/Element/MultiCheckbox.php | 4 ++-- .../ZendTest/Form/Element/MultiCheckboxTest.php | 14 +++++++------- tests/ZendTest/Form/Element/SelectTest.php | 16 +++++++--------- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/library/Zend/Form/Element/MultiCheckbox.php b/library/Zend/Form/Element/MultiCheckbox.php index 4338dfa069a..ba10e8c4c8b 100644 --- a/library/Zend/Form/Element/MultiCheckbox.php +++ b/library/Zend/Form/Element/MultiCheckbox.php @@ -65,8 +65,8 @@ public function setValueOptions(array $options) // Update InArray validator haystack if (!is_null($this->validator)) { - $validator = $this->validator->getValidator(); - $validator->setHaystack($this->getValueOptionsValues()); + $validator = $this->validator->getValidator(); + $validator->setHaystack($this->getValueOptionsValues()); } return $this; diff --git a/tests/ZendTest/Form/Element/MultiCheckboxTest.php b/tests/ZendTest/Form/Element/MultiCheckboxTest.php index b573112e8ca..2844955c512 100644 --- a/tests/ZendTest/Form/Element/MultiCheckboxTest.php +++ b/tests/ZendTest/Form/Element/MultiCheckboxTest.php @@ -113,15 +113,15 @@ public function testInArrayValidationOfOptions($valueTests, $options) */ public function testInArrayValidatorHaystakIsUpdated($valueTests, $options) { - $element = new MultiCheckboxElement('my-checkbox'); - $inputSpec = $element->getInputSpecification(); - $inArrayValidator=$inputSpec['validators'][0]->getValidator(); + $element = new MultiCheckboxElement('my-checkbox'); + $inputSpec = $element->getInputSpecification(); + $inArrayValidator=$inputSpec['validators'][0]->getValidator(); - $element->setAttributes(array( - 'options' => $options, + $element->setAttributes(array( + 'options' => $options, )); - $haystack=$inArrayValidator->getHaystack(); - $this->assertCount(count($options), $haystack); + $haystack=$inArrayValidator->getHaystack(); + $this->assertCount(count($options), $haystack); } diff --git a/tests/ZendTest/Form/Element/SelectTest.php b/tests/ZendTest/Form/Element/SelectTest.php index 3e9172bcb8a..e5654f289f3 100644 --- a/tests/ZendTest/Form/Element/SelectTest.php +++ b/tests/ZendTest/Form/Element/SelectTest.php @@ -160,17 +160,15 @@ public function testInArrayValidationOfOptions($valueTests, $options) */ public function testInArrayValidatorHaystakIsUpdated($valueTests, $options) { - $element = new SelectElement('my-select'); - $inputSpec = $element->getInputSpecification(); + $element = new SelectElement('my-select'); + $inputSpec = $element->getInputSpecification(); - $inArrayValidator = $inputSpec['validators'][0]; - $this->assertInstanceOf('Zend\Validator\InArray', $inArrayValidator); + $inArrayValidator = $inputSpec['validators'][0]; + $this->assertInstanceOf('Zend\Validator\InArray', $inArrayValidator); - $element->setAttributes(array( - 'options' => $options, - )); - $haystack=$inArrayValidator->getHaystack(); - $this->assertCount(count($options), $haystack); + $element->setValueOptions($options); + $haystack=$inArrayValidator->getHaystack(); + $this->assertCount(count($options), $haystack); } From 07c7e6c689368841974d8a97e08eba50d27b8dfa Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Fri, 21 Sep 2012 11:51:55 -0500 Subject: [PATCH 8/8] [#2393][ZF2-558] CS fixes - indentation - trailing spaces --- library/Zend/Form/Element/MultiCheckbox.php | 4 ++-- library/Zend/Form/Element/Select.php | 6 +++--- tests/ZendTest/Form/Element/MultiCheckboxTest.php | 10 +++++----- tests/ZendTest/Form/Element/SelectTest.php | 8 ++++---- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/library/Zend/Form/Element/MultiCheckbox.php b/library/Zend/Form/Element/MultiCheckbox.php index ba10e8c4c8b..a0ccf7a39c0 100644 --- a/library/Zend/Form/Element/MultiCheckbox.php +++ b/library/Zend/Form/Element/MultiCheckbox.php @@ -62,13 +62,13 @@ public function getValueOptions() public function setValueOptions(array $options) { $this->valueOptions = $options; - + // Update InArray validator haystack if (!is_null($this->validator)) { $validator = $this->validator->getValidator(); $validator->setHaystack($this->getValueOptionsValues()); } - + return $this; } diff --git a/library/Zend/Form/Element/Select.php b/library/Zend/Form/Element/Select.php index d1c2c9b6dce..a6850ffac42 100644 --- a/library/Zend/Form/Element/Select.php +++ b/library/Zend/Form/Element/Select.php @@ -80,13 +80,13 @@ public function getValueOptions() public function setValueOptions(array $options) { $this->valueOptions = $options; - + // Update InArrayValidator validator haystack if (!is_null($this->validator)) { $validator = $this->validator instanceof InArrayValidator ? $this->validator : $this->validator->getValidator(); - $validator->setHaystack($this->getValueOptionsValues()); + $validator->setHaystack($this->getValueOptionsValues()); } - + return $this; } diff --git a/tests/ZendTest/Form/Element/MultiCheckboxTest.php b/tests/ZendTest/Form/Element/MultiCheckboxTest.php index 737b9b7dc6f..22ac0b4193f 100644 --- a/tests/ZendTest/Form/Element/MultiCheckboxTest.php +++ b/tests/ZendTest/Form/Element/MultiCheckboxTest.php @@ -114,17 +114,17 @@ public function testInArrayValidationOfOptions($valueTests, $options) public function testInArrayValidatorHaystakIsUpdated($valueTests, $options) { $element = new MultiCheckboxElement('my-checkbox'); - $inputSpec = $element->getInputSpecification(); + $inputSpec = $element->getInputSpecification(); $inArrayValidator=$inputSpec['validators'][0]->getValidator(); $element->setAttributes(array( - 'options' => $options, - )); + 'options' => $options, + )); $haystack=$inArrayValidator->getHaystack(); $this->assertCount(count($options), $haystack); } - - + + public function testAttributeType() { $element = new MultiCheckboxElement(); diff --git a/tests/ZendTest/Form/Element/SelectTest.php b/tests/ZendTest/Form/Element/SelectTest.php index e5654f289f3..d47736749ad 100644 --- a/tests/ZendTest/Form/Element/SelectTest.php +++ b/tests/ZendTest/Form/Element/SelectTest.php @@ -151,7 +151,7 @@ public function testInArrayValidationOfOptions($valueTests, $options) $this->assertTrue($inArrayValidator->isValid($valueToTest)); } } - + /** * Testing that InArray Validator Haystack is Updated if the Options * are added after the validator is attached @@ -162,15 +162,15 @@ public function testInArrayValidatorHaystakIsUpdated($valueTests, $options) { $element = new SelectElement('my-select'); $inputSpec = $element->getInputSpecification(); - + $inArrayValidator = $inputSpec['validators'][0]; $this->assertInstanceOf('Zend\Validator\InArray', $inArrayValidator); - + $element->setValueOptions($options); $haystack=$inArrayValidator->getHaystack(); $this->assertCount(count($options), $haystack); } - + public function testOptionsHasArrayOnConstruct() {