Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Merge branch 'bugfix558' of https://github.com/igormx/zf2 into hotfix…
Browse files Browse the repository at this point in the history
…/zf2-558
  • Loading branch information
weierophinney committed Sep 21, 2012
2 parents 3b9784c + b04198f commit 41c6931
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
7 changes: 7 additions & 0 deletions library/Zend/Form/Element/MultiCheckbox.php
Expand Up @@ -62,6 +62,13 @@ public function getValueOptions()
public function setValueOptions(array $options) public function setValueOptions(array $options)
{ {
$this->valueOptions = $options; $this->valueOptions = $options;

// Update InArray validator haystack
if (!is_null($this->validator)) {
$validator = $this->validator->getValidator();
$validator->setHaystack($this->getValueOptionsValues());
}

return $this; return $this;
} }


Expand Down
7 changes: 7 additions & 0 deletions library/Zend/Form/Element/Select.php
Expand Up @@ -80,6 +80,13 @@ public function getValueOptions()
public function setValueOptions(array $options) public function setValueOptions(array $options)
{ {
$this->valueOptions = $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; return $this;
} }


Expand Down
20 changes: 20 additions & 0 deletions tests/ZendTest/Form/Element/MultiCheckboxTest.php
Expand Up @@ -105,6 +105,26 @@ public function testInArrayValidationOfOptions($valueTests, $options)
$this->assertTrue($explodeValidator->isValid($valueTests)); $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() public function testAttributeType()
{ {
$element = new MultiCheckboxElement(); $element = new MultiCheckboxElement();
Expand Down
20 changes: 20 additions & 0 deletions tests/ZendTest/Form/Element/SelectTest.php
Expand Up @@ -151,6 +151,26 @@ public function testInArrayValidationOfOptions($valueTests, $options)
$this->assertTrue($inArrayValidator->isValid($valueToTest)); $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() public function testOptionsHasArrayOnConstruct()
{ {
Expand Down

0 comments on commit 41c6931

Please sign in to comment.