Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bakura10 committed Jul 26, 2012
1 parent 5fdfa98 commit a619b9e
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion library/Zend/Form/View/Helper/FormButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function openTag($attributesOrElement = null)

$element = $attributesOrElement;
$name = $element->getName();
if (empty($name) && $name !== 0) {
if (is_null($name) || $name === '') {
throw new Exception\DomainException(sprintf(
'%s requires that the element has an assigned name; none discovered',
__METHOD__
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Form/View/Helper/FormCheckbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class FormCheckbox extends FormInput
public function render(ElementInterface $element)
{
$name = $element->getName();
if (empty($name) && $name !== 0) {
if (is_null($name) || $name === '') {
throw new Exception\DomainException(sprintf(
'%s requires that the element has an assigned name; none discovered',
__METHOD__
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Form/View/Helper/FormSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class FormSelect extends AbstractHelper
public function render(ElementInterface $element)
{
$name = $element->getName();
if (empty($name) && $name !== 0) {
if (is_null($name) || $name === '') {
throw new Exception\DomainException(sprintf(
'%s requires that the element has an assigned name; none discovered',
__METHOD__
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Form/View/Helper/FormTextarea.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class FormTextarea extends AbstractHelper
public function render(ElementInterface $element)
{
$name = $element->getName();
if (empty($name) && $name !== 0) {
if (is_null($name) || $name === '') {
throw new Exception\DomainException(sprintf(
'%s requires that the element has an assigned name; none discovered',
__METHOD__
Expand Down
6 changes: 6 additions & 0 deletions tests/Zend/Form/View/Helper/FormButtonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,10 @@ public function testInvokeWithNoElementChainsHelper()
$element = new Element('foo');
$this->assertSame($this->helper, $this->helper->__invoke());
}

public function testDoesNotThrowExceptionIfNameIsZero()
{
$element = new Element('0');
$this->helper->__invoke($element, '{button_content}');
}
}
6 changes: 6 additions & 0 deletions tests/Zend/Form/View/Helper/FormCheckboxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,10 @@ public function testSetUseHiddenElementAttributeDoesNotRenderHiddenInput()
$this->assertRegexp('#type="checkbox".*?(value="1")#', $markup);
$this->assertNotRegexp('#type="hidden"\s+name="foo"\s+value="0"#', $markup);
}

public function testDoesNotThrowExceptionIfNameIsZero()
{
$element = new Element\Checkbox('0');
$this->helper->__invoke($element);
}
}
8 changes: 8 additions & 0 deletions tests/Zend/Form/View/Helper/FormSelectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,12 @@ public function testTranslatorMethods()
$this->helper->setTranslatorEnabled(false);
$this->assertFalse($this->helper->isTranslatorEnabled());
}

public function testDoesNotThrowExceptionIfNameIsZero()
{
$element = $this->getElement();
$element->setName(0);

$this->helper->__invoke($element);
}
}

0 comments on commit a619b9e

Please sign in to comment.