Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'bugfix558' of https://github.com/igormx/zf2 into hotfix…

…/zf2-558
  • Loading branch information...
commit 41c69315e8fc8d77ae7f51f2fb58035b79458446 2 parents 3b9784c + b04198f
@weierophinney weierophinney authored
View
7 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;
}
View
7 library/Zend/Form/Element/Select.php
@@ -80,6 +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());
+ }
+
return $this;
}
View
20 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();
View
20 tests/ZendTest/Form/Element/SelectTest.php
@@ -151,6 +151,26 @@ 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();
+
+ $inArrayValidator = $inputSpec['validators'][0];
+ $this->assertInstanceOf('Zend\Validator\InArray', $inArrayValidator);
+
+ $element->setValueOptions($options);
+ $haystack=$inArrayValidator->getHaystack();
+ $this->assertCount(count($options), $haystack);
+ }
+
public function testOptionsHasArrayOnConstruct()
{
Please sign in to comment.
Something went wrong with that request. Please try again.