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
13 changes: 13 additions & 0 deletions library/Zend/Form/Element/MultiCheckbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@ public function setValueOptions(array $options)
return $this;
}

/**
* @param string $key
* @return self
*/
public function unsetValueOption($key)
{
if (isset($this->valueOptions[$key])) {
unset($this->valueOptions[$key]);
}

return $this;
}

/**
* Set options for an element. Accepted options are:
* - label: label to associate with the element
Expand Down
13 changes: 13 additions & 0 deletions library/Zend/Form/Element/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ public function setValueOptions(array $options)
return $this;
}

/**
* @param string $key
* @return self
*/
public function unsetValueOption($key)
{
if (isset($this->valueOptions[$key])) {
unset($this->valueOptions[$key]);
}

return $this;
}

/**
* Set options for an element. Accepted options are:
* - label: label to associate with the element
Expand Down
28 changes: 28 additions & 0 deletions tests/ZendTest/Form/Element/MultiCheckboxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,32 @@ public function testDisableInputSpecification()
$inputSpec = $element->getInputSpecification();
$this->assertArrayNotHasKey('validators', $inputSpec);
}

public function testUnsetValueOption()
{
$element = new MultiCheckboxElement();
$element->setValueOptions(array(
'Option 1' => 'option1',
'Option 2' => 'option2',
'Option 3' => 'option3',
));
$element->unsetValueOption('Option 2');

$valueOptions = $element->getValueOptions();
$this->assertArrayNotHasKey('Option 2', $valueOptions);
}

public function testUnsetUndefinedValueOption()
{
$element = new MultiCheckboxElement();
$element->setValueOptions(array(
'Option 1' => 'option1',
'Option 2' => 'option2',
'Option 3' => 'option3',
));
$element->unsetValueOption('Option Undefined');

$valueOptions = $element->getValueOptions();
$this->assertArrayNotHasKey('Option Undefined', $valueOptions);
}
}
28 changes: 28 additions & 0 deletions tests/ZendTest/Form/Element/SelectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,32 @@ public function testDisableInputSpecification()
$this->assertArrayNotHasKey('validators', $inputSpec);
}

public function testUnsetValueOption()
{
$element = new SelectElement();
$element->setValueOptions(array(
'Option 1' => 'option1',
'Option 2' => 'option2',
'Option 3' => 'option3',
));
$element->unsetValueOption('Option 2');

$valueOptions = $element->getValueOptions();
$this->assertArrayNotHasKey('Option 2', $valueOptions);
}

public function testUnsetUndefinedValueOption()
{
$element = new SelectElement();
$element->setValueOptions(array(
'Option 1' => 'option1',
'Option 2' => 'option2',
'Option 3' => 'option3',
));
$element->unsetValueOption('Option Undefined');

$valueOptions = $element->getValueOptions();
$this->assertArrayNotHasKey('Option Undefined', $valueOptions);
}

}