Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 8, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions library/Zend/Form/Element/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,19 @@ protected function getValueOptionsValues()
$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)){
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add whitespace between if and opening paren, and between closing paren and opening brace.

foreach ($optionSpec['options'] as $nestedKey => $nestedOptionSpec) {
$values[] = $this->getOptionValue($nestedKey, $nestedOptionSpec);
}
}else{
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add whitespace around the else keyword, please.

$values[] = $this->getOptionValue($key, $optionSpec);
}
}
return $values;
}

private function getOptionValue($key, $optionSpec)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

protected visibility, please.

{
return is_array($optionSpec) ? $optionSpec['value'] : $key;
}
}
37 changes: 36 additions & 1 deletion tests/ZendTest/Form/Element/SelectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -137,4 +172,4 @@ public function testDeprecateOptionsInAttributes()
));
$this->assertEquals($valueOptions, $element->getValueOptions());
}
}
}