Permalink
Browse files

Merge branch 'release'

Conflicts:
	tests/ZendTest/Form/Element/SelectTest.php
  • Loading branch information...
2 parents 8d68789 + c154ad2 commit d6cd20dc0b50b6c645c5c0be5f3c380e23aafb8e @weierophinney weierophinney committed Sep 13, 2012
Showing with 50 additions and 6 deletions.
  1. +14 −3 library/Zend/Form/Element/Select.php
  2. +36 −3 tests/ZendTest/Form/Element/SelectTest.php
@@ -208,12 +208,23 @@ public function getInputSpecification()
*/
protected function getValueOptionsValues()
{
- $values = array();
+ $values = array();
$options = $this->getValueOptions();
foreach ($options as $key => $optionSpec) {
- $value = (is_array($optionSpec)) ? $optionSpec['value'] : $key;
- $values[] = $value;
+ if (is_array($optionSpec) && array_key_exists('options', $optionSpec)) {
+ foreach ($optionSpec['options'] as $nestedKey => $nestedOptionSpec) {
+ $values[] = $this->getOptionValue($nestedKey, $nestedOptionSpec);
+ }
+ continue;
+ }
+
+ $values[] = $this->getOptionValue($key, $optionSpec);
}
return $values;
}
+
+ protected function getOptionValue($key, $optionSpec)
+ {
+ return is_array($optionSpec) ? $optionSpec['value'] : $key;
+ }
}
@@ -49,6 +49,41 @@ public function testProvidesInputSpecificationForSingleSelect()
}
}
+ public function testValidateWorksForNestedSelectElementWithSimpleNaming()
+ {
+ $element = new SelectElement();
+ $element->setValueOptions(array(
+ array('label' => 'group 1', 'options' => array(
+ 'Option 1' => 'Label 1',
+ 'Option 2' => 'Label 2',
+ 'Option 3' => 'Label 2',
+ ))));
+
+ $inputSpec = $element->getInputSpecification();
+ $inArrayValidator = $inputSpec['validators'][0];
+
+ $this->assertTrue($inArrayValidator->isValid('Option 1'));
+ $this->assertFalse($inArrayValidator->isValid('Option 5'));
+ }
+
+ public function testValidateWorksForNestedSelectElementWithExplicitNaming()
+ {
+ $element = new SelectElement();
+ $element->setValueOptions(array(
+ array('label' => 'group 1', 'options' => array(
+ array('value' => 'Option 1', 'label'=> 'Label 1'),
+ array('value' => 'Option 2', 'label'=> 'Label 2'),
+ array('value' => 'Option 3', 'label'=> 'Label 3'),
+ ))));
+
+ $inputSpec = $element->getInputSpecification();
+ $inArrayValidator = $inputSpec['validators'][0];
+
+ $this->assertTrue($inArrayValidator->isValid('Option 1'));
+ $this->assertTrue($inArrayValidator->isValid('Option 2'));
+ $this->assertTrue($inArrayValidator->isValid('Option 3'));
+ $this->assertFalse($inArrayValidator->isValid('Option 5'));
+ }
public function testProvidesInputSpecificationForMultipleSelect()
{
$element = new SelectElement();
@@ -137,6 +172,4 @@ public function testDeprecateOptionsInAttributes()
));
$this->assertEquals($valueOptions, $element->getValueOptions());
}
-
-
-}
+}

0 comments on commit d6cd20d

Please sign in to comment.