Skip to content

Commit

Permalink
add support for strings passed to the addOption method
Browse files Browse the repository at this point in the history
  • Loading branch information
theDisco committed Aug 13, 2015
1 parent b0869c4 commit 5b978d0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 7 additions & 3 deletions phalcon/forms/element/select.zep
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,13 @@ class Select extends Element implements ElementInterface {
*/
public function addOption(var option) -> <Element>
{
var key, value;
for key, value in option {
let this->_optionsValues[key] = value;
if is_array(option) {
var key, value;
for key, value in option {
let this->_optionsValues[key] = value;
}
} else {
let this->_optionsValues[] = option;
}
return this;
}
Expand Down
10 changes: 9 additions & 1 deletion unit-tests/FormsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -518,11 +518,19 @@ public function testIssue2045()
$this->assertEquals('<input type="text" name="name" class="big-input" />', $element->render());
}

public function testCorrectlyAddOptionToSelectElement()
public function testCorrectlyAddOptionToSelectElementIfParameterIsAnArray()
{
$element = new Select('test-select');
$element->addOption(array('key' => 'value'));

$this->assertEquals('<select id="test-select" name="test-select"><option value="key">value</option></select>', preg_replace('/[[:cntrl:]]/', '', $element->render()));
}

public function testCorrectlyAddOptionToSelectElementIfParameterIsAString()
{
$element = new Select('test-select');
$element->addOption('value');

$this->assertEquals('<select id="test-select" name="test-select"><option value="0">value</option></select>', preg_replace('/[[:cntrl:]]/', '', $element->render()));
}
}

0 comments on commit 5b978d0

Please sign in to comment.