Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'hotfix/2361' into develop

Close #2361
  • Loading branch information...
commit e98c3f4080fb3069757abf10b7d4efca1b4d83af 2 parents 89997a1 + 1b3b278
Matthew Weier O'Phinney weierophinney authored
Showing with 560 additions and 11 deletions.
  1. +1 −1  library/Zend/Form/Form.php
  2. +1 −1  library/Zend/Form/View/Helper/FormCollection.php
  3. +8 −7 library/Zend/Form/View/Helper/FormMultiCheckbox.php
  4. +7 −0 tests/ZendTest/Form/Element/CaptchaTest.php
  5. +13 −0 tests/ZendTest/Form/Element/CheckboxTest.php
  6. +53 −0 tests/ZendTest/Form/Element/CollectionTest.php
  7. +11 −0 tests/ZendTest/Form/Element/MultiCheckboxTest.php
  8. +15 −0 tests/ZendTest/Form/Element/SelectTest.php
  9. +49 −0 tests/ZendTest/Form/ElementTest.php
  10. +81 −0 tests/ZendTest/Form/FieldsetTest.php
  11. +33 −0 tests/ZendTest/Form/FormTest.php
  12. +16 −0 tests/ZendTest/Form/View/Helper/Captcha/DumbTest.php
  13. +7 −0 tests/ZendTest/Form/View/Helper/FormButtonTest.php
  14. +7 −0 tests/ZendTest/Form/View/Helper/FormCheckboxTest.php
  15. +26 −0 tests/ZendTest/Form/View/Helper/FormCollectionTest.php
  16. +13 −0 tests/ZendTest/Form/View/Helper/FormElementErrorsTest.php
  17. +9 −0 tests/ZendTest/Form/View/Helper/FormElementTest.php
  18. +19 −0 tests/ZendTest/Form/View/Helper/FormLabelTest.php
  19. +98 −0 tests/ZendTest/Form/View/Helper/FormMultiCheckboxTest.php
  20. +58 −2 tests/ZendTest/Form/View/Helper/FormRowTest.php
  21. +35 −0 tests/ZendTest/Form/View/Helper/FormSelectTest.php
2  library/Zend/Form/Form.php
View
@@ -489,7 +489,7 @@ public function setValidationGroup()
$argv = func_get_args();
$this->hasValidated = false;
- if (1 < $argc) {
+ if ($argc > 1) {
$this->validationGroup = $argv;
return $this;
}
2  library/Zend/Form/View/Helper/FormCollection.php
View
@@ -148,7 +148,7 @@ public function setShouldWrap($wrap)
*/
public function shouldWrap()
{
- return $this->shouldWrap();
+ return $this->shouldWrap;
}
/**
15 library/Zend/Form/View/Helper/FormMultiCheckbox.php
View
@@ -202,12 +202,6 @@ public function render(ElementInterface $element)
}
$name = static::getName($element);
- if ($name === null || $name === '') {
- throw new Exception\DomainException(sprintf(
- '%s requires that the element has an assigned name; none discovered',
- __METHOD__
- ));
- }
$options = $element->getValueOptions();
if (empty($options)) {
@@ -453,6 +447,13 @@ protected function getLabelHelper()
*/
protected static function getName(ElementInterface $element)
{
- return $element->getName() . '[]';
+ $name = $element->getName();
+ if ($name === null || $name === '') {
+ throw new Exception\DomainException(sprintf(
+ '%s requires that the element has an assigned name; none discovered',
+ __METHOD__
+ ));
+ }
+ return $name . '[]';
}
}
7 tests/ZendTest/Form/Element/CaptchaTest.php
View
@@ -56,6 +56,13 @@ public function testCaptchaIsMutable()
$this->assertInstanceOf('Zend\Captcha\Dumb', $element->getCaptcha());
}
+ public function testCaptchaWithNullRaisesException()
+ {
+ $element = new CaptchaElement();
+ $this->setExpectedException('Zend\Form\Exception\InvalidArgumentException');
+ $element->setCaptcha(null);
+ }
+
public function testSettingCaptchaSetsCaptchaAttribute()
{
$element = new CaptchaElement();
13 tests/ZendTest/Form/Element/CheckboxTest.php
View
@@ -106,4 +106,17 @@ public function testCheckWithCheckedValue()
$element->setValue($element->getCheckedValue());
$this->assertEquals(true, $element->isChecked());
}
+
+ public function testSetOptions()
+ {
+ $element = new CheckboxElement();
+ $element->setOptions(array(
+ 'use_hidden_element' => true,
+ 'unchecked_value' => 'foo',
+ 'checked_value' => 'bar',
+ ));
+ $this->assertEquals(true, $element->getOption('use_hidden_element'));
+ $this->assertEquals('foo', $element->getOption('unchecked_value'));
+ $this->assertEquals('bar', $element->getOption('checked_value'));
+ }
}
53 tests/ZendTest/Form/Element/CollectionTest.php
View
@@ -11,6 +11,7 @@
namespace ZendTest\Form\Element;
use PHPUnit_Framework_TestCase as TestCase;
+use Zend\Form\Element;
use Zend\Form\Element\Collection as Collection;
use Zend\Form\Factory;
@@ -180,4 +181,56 @@ public function testCanValidateLessThanSpecifiedCount()
$this->assertEquals(true, $this->form->isValid());
}
+
+ public function testSetOptions()
+ {
+ $collection = $this->form->get('colors');
+ $element = new Element('foo');
+ $collection->setOptions(array(
+ 'target_element' => $element,
+ 'count' => 2,
+ 'allow_add' => true,
+ 'allow_remove' => false,
+ 'should_create_template' => true,
+ 'template_placeholder' => 'foo',
+ ));
+ $this->assertInstanceOf('Zend\Form\Element', $collection->getOption('target_element'));
+ $this->assertEquals(2, $collection->getOption('count'));
+ $this->assertEquals(true, $collection->getOption('allow_add'));
+ $this->assertEquals(false, $collection->getOption('allow_remove'));
+ $this->assertEquals(true, $collection->getOption('should_create_template'));
+ $this->assertEquals('foo', $collection->getOption('template_placeholder'));
+ }
+
+ public function testSetObjectNullRaisesException()
+ {
+ $collection = $this->form->get('colors');
+ $this->setExpectedException('Zend\Form\Exception\InvalidArgumentException');
+ $collection->setObject(null);
+ }
+
+ public function testPopulateValuesNullRaisesException()
+ {
+ $collection = $this->form->get('colors');
+ $this->setExpectedException('Zend\Form\Exception\InvalidArgumentException');
+ $collection->populateValues(null);
+ }
+
+ public function testSetTargetElementNullRaisesException()
+ {
+ $collection = $this->form->get('colors');
+ $this->setExpectedException('Zend\Form\Exception\InvalidArgumentException');
+ $collection->setTargetElement(null);
+ }
+
+ public function testGetTargetElement()
+ {
+ $collection = $this->form->get('colors');
+ $element = new Element('foo');
+ $collection->setTargetElement($element);
+
+ $this->assertInstanceOf('Zend\Form\Element', $collection->getTargetElement());
+ }
+
+
}
11 tests/ZendTest/Form/Element/MultiCheckboxTest.php
View
@@ -113,4 +113,15 @@ public function testAttributeType()
$this->assertArrayHasKey('type', $attributes);
$this->assertEquals('multi_checkbox', $attributes['type']);
}
+
+ public function testSetOptionsOptions()
+ {
+ $element = new MultiCheckboxElement();
+ $element->setOptions(array(
+ 'value_options' => array('bar' => 'baz'),
+ 'options' => array('foo' => 'bar'),
+ ));
+ $this->assertEquals(array('bar' => 'baz'), $element->getOption('value_options'));
+ $this->assertEquals(array('foo' => 'bar'), $element->getOption('options'));
+ }
}
15 tests/ZendTest/Form/Element/SelectTest.php
View
@@ -172,4 +172,19 @@ public function testDeprecateOptionsInAttributes()
));
$this->assertEquals($valueOptions, $element->getValueOptions());
}
+
+ public function testSetOptionsOptions()
+ {
+ $element = new SelectElement();
+ $element->setOptions(array(
+ 'value_options' => array('bar' => 'baz'),
+ 'options' => array('foo' => 'bar'),
+ 'empty_option' => array('baz' => 'foo'),
+ ));
+ $this->assertEquals(array('bar' => 'baz'), $element->getOption('value_options'));
+ $this->assertEquals(array('foo' => 'bar'), $element->getOption('options'));
+ $this->assertEquals(array('baz' => 'foo'), $element->getOption('empty_option'));
+ }
+
+
}
49 tests/ZendTest/Form/ElementTest.php
View
@@ -128,4 +128,53 @@ public function testCanRetrieveSpecificOption()
$option = $element->getOption('custom');
$this->assertEquals('option', $option);
}
+
+ public function testSpecificOptionsSetLabelAttributes()
+ {
+ $element = new Element('foo');
+ $element->setOptions(array(
+ 'label' => 'foo',
+ 'label_attributes' => array('bar' => 'baz')
+ ));
+ $option = $element->getOption('label_attributes');
+ $this->assertEquals(array('bar' => 'baz'), $option);
+ }
+
+ public function testSetOptionsWrongInputRaisesException()
+ {
+ $element = new Element('foo');
+
+ $this->setExpectedException('Zend\Form\Exception\InvalidArgumentException');
+ $element->setOptions(null);
+ }
+
+ public function testSetOptionsIsTraversable()
+ {
+ $element = new Element('foo');
+ $element->setOptions(new \ArrayObject(array('foo' => 'bar')));
+ $this->assertEquals('foo', $element->getName());
+ $this->assertEquals(array('foo' => 'bar'), $element->getOptions());
+ }
+
+ public function testGetOption()
+ {
+ $element = new Element('foo');
+ $this->assertNull($element->getOption('foo'));
+ }
+
+ public function testSetAttributesWrongInputRaisesException()
+ {
+ $element = new Element('foo');
+
+ $this->setExpectedException('Zend\Form\Exception\InvalidArgumentException');
+ $element->setAttributes(null);
+ }
+
+ public function testSetMessagesWrongInputRaisesException()
+ {
+ $element = new Element('foo');
+
+ $this->setExpectedException('Zend\Form\Exception\InvalidArgumentException');
+ $element->setMessages(null);
+ }
}
81 tests/ZendTest/Form/FieldsetTest.php
View
@@ -93,6 +93,12 @@ public function testExtractOnAnEmptyRelationship()
$form->populateValues(array('fieldsets' => array()));
}
+ public function testPopulateValuesWithInvalidElementRaisesException()
+ {
+ $this->setExpectedException('Zend\Form\Exception\InvalidArgumentException');
+ $this->fieldset->populateValues(null);
+ }
+
public function testFieldsetIsEmptyByDefault()
{
$this->assertEquals(0, count($this->fieldset));
@@ -114,6 +120,12 @@ public function testCanSetCustomOptionFromConstructor()
$this->assertEquals('option', $options['custom']);
}
+ public function testAddWithInvalidElementRaisesException()
+ {
+ $this->setExpectedException('Zend\Form\Exception\InvalidArgumentException');
+ $this->fieldset->add(null);
+ }
+
public function testCanGrabElementByNameWhenNotProvidedWithAlias()
{
$element = new Element('foo');
@@ -174,6 +186,25 @@ public function testCanRemoveFieldsetsByName()
$this->assertFalse($this->fieldset->has('foo'));
}
+ public function testCanRemoveElementsByWrongName()
+ {
+ $element = new Element('foo');
+ $this->fieldset->add($element);
+ $element2 = new Element('bar');
+ $this->fieldset->add($element2);
+ $this->assertTrue($this->fieldset->has('foo'));
+ $this->assertTrue($this->fieldset->has('bar'));
+
+ // remove wrong element, bar still available
+ $this->fieldset->remove('bars');
+ $this->assertTrue($this->fieldset->has('foo'));
+ $this->assertTrue($this->fieldset->has('bar'));
+
+ $this->fieldset->remove('bar');
+ $this->assertTrue($this->fieldset->has('foo'));
+ $this->assertFalse($this->fieldset->has('bar'));
+ }
+
public function testCanRetrieveAllAttachedElementsSeparateFromFieldsetsAtOnce()
{
$this->populateFieldset();
@@ -207,6 +238,12 @@ public function testCanSetAndRetrieveErrorMessagesForAllElementsAndFieldsets()
$this->assertEquals($messages, $test);
}
+ public function testSetMessagesWithInvalidElementRaisesException()
+ {
+ $this->setExpectedException('Zend\Form\Exception\InvalidArgumentException');
+ $this->fieldset->setMessages(null);
+ }
+
public function testOnlyElementsWithErrorsInMessages()
{
$fieldset = new TestAsset\FieldsetWithInputFilter('set');
@@ -244,6 +281,12 @@ public function testCanRetrieveMessagesForSingleFieldsetsAfterMessagesHaveBeenSe
$this->assertEquals($messages['barbaz'], $test);
}
+ public function testGetMessagesWithInvalidElementRaisesException()
+ {
+ $this->setExpectedException('Zend\Form\Exception\InvalidArgumentException');
+ $this->fieldset->getMessages('foo');
+ }
+
public function testCountGivesCountOfAttachedElementsAndFieldsets()
{
$this->populateFieldset();
@@ -340,4 +383,42 @@ public function testFieldsetExposesFluentInterface()
$fieldset = $this->fieldset->remove('foo');
$this->assertSame($this->fieldset, $fieldset);
}
+
+ public function testSetOptions()
+ {
+ $this->fieldset->setOptions(array(
+ 'foo' => 'bar'
+ ));
+ $option = $this->fieldset->getOption('foo');
+
+ $this->assertEquals('bar', $option);
+ }
+
+ public function testSetOptionsUseAsBaseFieldset()
+ {
+ $this->fieldset->setOptions(array(
+ 'use_as_base_fieldset' => 'bar'
+ ));
+ $option = $this->fieldset->getOption('use_as_base_fieldset');
+
+ $this->assertEquals('bar', $option);
+ }
+
+ public function testGetReturnsNull()
+ {
+ $foo = $this->fieldset->get('foo');
+ $this->assertNull($foo);
+ }
+
+ public function testBindValuesHasNoName()
+ {
+ $bindValues = $this->fieldset->bindValues(array('foo'));
+ $this->assertNull($bindValues);
+ }
+
+ public function testSetObjectWithStringRaisesException()
+ {
+ $this->setExpectedException('Zend\Form\Exception\InvalidArgumentException');
+ $this->fieldset->setObject('foo');
+ }
}
33 tests/ZendTest/Form/FormTest.php
View
@@ -264,6 +264,12 @@ public function testSettingValidateAllFlagAfterPartialValidationForcesFullValida
$this->assertArrayHasKey('foobar', $messages, var_export($messages, 1));
}
+ public function testSetValidationGroupWithNoArgumentsRaisesException()
+ {
+ $this->setExpectedException('Zend\Form\Exception\InvalidArgumentException');
+ $this->form->setValidationGroup();
+ }
+
public function testCallingGetDataPriorToValidationRaisesException()
{
$this->setExpectedException('Zend\Form\Exception\DomainException');
@@ -1067,4 +1073,31 @@ public function testHydratorAppliedToBaseFieldset()
$baseHydrator = $this->form->get('foobar')->getHydrator();
$this->assertInstanceOf('Zend\Stdlib\Hydrator\ArraySerializable', $baseHydrator);
}
+
+ public function testBindWithWrongFlagRaisesException()
+ {
+ $model = new stdClass;
+ $this->setExpectedException('Zend\Form\Exception\InvalidArgumentException');
+ $this->form->bind($model, Form::VALUES_AS_ARRAY);
+ }
+
+ public function testSetBindOnValidateWrongFlagRaisesException()
+ {
+ $this->setExpectedException('Zend\Form\Exception\InvalidArgumentException');
+ $this->form->setBindOnValidate(Form::VALUES_AS_ARRAY);
+ }
+
+ public function testSetDataOnValidateWrongFlagRaisesException()
+ {
+ $this->setExpectedException('Zend\Form\Exception\InvalidArgumentException');
+ $this->form->setData(null);
+ }
+
+ public function testSetDataIsTraversable()
+ {
+ $this->form->setData(new \ArrayObject(array('foo' => 'bar')));
+ $this->assertTrue($this->form->isValid());
+ }
+
+
}
16 tests/ZendTest/Form/View/Helper/Captcha/DumbTest.php
View
@@ -76,4 +76,20 @@ public function testCanRenderLabelFollowingInput()
$this->assertContains('>' . $this->captcha->getLabel() . ' <b>' . strrev($this->captcha->getWord()) . '</b>' . $this->helper->getSeparator(), $markup);
}
+ public function testSetCaptchaPositionWithNullRaisesException()
+ {
+ $this->setExpectedException('Zend\Form\Exception\InvalidArgumentException');
+ $this->helper->setCaptchaPosition(null);
+
+ }
+
+ public function testSetSeparator()
+ {
+ $this->helper->setCaptchaPosition('prepend');
+ $element = $this->getElement();
+ $this->helper->render($element);
+ $this->helper->setSeparator('-');
+
+ $this->assertEquals('-', $this->helper->getSeparator());
+ }
}
7 tests/ZendTest/Form/View/Helper/FormButtonTest.php
View
@@ -68,6 +68,13 @@ public function testRaisesExceptionWhenNameIsNotPresentInElementWhenPassedToOpen
$this->helper->openTag($element);
}
+ public function testOpenTagWithWrongElementRaisesException()
+ {
+ $element = new \arrayObject();
+ $this->setExpectedException('Zend\Form\Exception\InvalidArgumentException', 'ArrayObject');
+ $this->helper->openTag($element);
+ }
+
public function testGeneratesSubmitTypeWhenProvidedAnElementWithNoTypeAttribute()
{
$element = new Element('foo');
7 tests/ZendTest/Form/View/Helper/FormCheckboxTest.php
View
@@ -37,6 +37,13 @@ public function getElement()
return $element;
}
+ public function testRaisesExceptionWhenNameIsNotPresentInElement()
+ {
+ $element = new Element\Checkbox();
+ $this->setExpectedException('Zend\Form\Exception\DomainException', 'name');
+ $this->helper->render($element);
+ }
+
public function testUsesOptionsAttributeToGenerateCheckedAndUnCheckedValues()
{
$element = $this->getElement();
26 tests/ZendTest/Form/View/Helper/FormCollectionTest.php
View
@@ -114,4 +114,30 @@ public function testRenderWithCustomHelper()
$this->assertContains('id="customcolors0"', $markup);
$this->assertContains('id="customcolors1"', $markup);
}
+
+ public function testShouldWrapReturnsDefaultTrue()
+ {
+ $this->assertTrue($this->helper->shouldWrap());
+ }
+
+ public function testSetShouldWrapReturnsFalse()
+ {
+ $this->helper->setShouldWrap(false);
+ $this->assertFalse($this->helper->shouldWrap());
+ }
+
+ public function testGetDefaultElementHelperReturnsFormrow()
+ {
+ $defaultElement = $this->helper->getDefaultElementHelper();
+ $this->assertSame('formrow', $defaultElement);
+ }
+
+ public function testSetDefaultElementHelperToFoo()
+ {
+ $this->helper->setDefaultElementHelper('foo');
+ $defaultElement = $this->helper->getDefaultElementHelper();
+ $this->assertSame('foo', $defaultElement);
+ }
+
+
}
13 tests/ZendTest/Form/View/Helper/FormElementErrorsTest.php
View
@@ -99,6 +99,19 @@ public function testSpecifiedAttributesOverrideDefaults()
$this->assertContains('ul class="error"', $markup);
}
+ public function testGetAttributes()
+ {
+ $messages = $this->getMessageList();
+ $element = new Element('foo');
+ $element->setMessages($messages);
+
+ $this->helper->setAttributes(array('class' => 'error'));
+
+ $this->helper->render($element);
+
+ $this->assertEquals(array('class' => 'error'), $this->helper->getAttributes());
+ }
+
public function testRendersNestedMessageSetsAsAFlatList()
{
$messages = array(
9 tests/ZendTest/Form/View/Helper/FormElementTest.php
View
@@ -184,6 +184,15 @@ public function testRendersTextareaAsExpected()
$this->assertContains('>Initial content<', $markup);
}
+ public function testRendersCollectionAsExpected()
+ {
+ $element = new Element\Collection();
+ $element->setLabel('foo');
+
+ $markup = $this->helper->render($element);
+ $this->assertContains('<legend>foo</legend>', $markup);
+ }
+
public function testRendersButtonAsExpected()
{
$element = new Element\Button('foo');
19 tests/ZendTest/Form/View/Helper/FormLabelTest.php
View
@@ -34,6 +34,13 @@ public function testCanEmitStartTagOnly()
$this->assertEquals('<label>', $markup);
}
+ public function testOpenTagWithWrongElementRaisesException()
+ {
+ $element = new \arrayObject();
+ $this->setExpectedException('Zend\Form\Exception\InvalidArgumentException', 'ArrayObject');
+ $this->helper->openTag($element);
+ }
+
public function testPassingArrayToOpenTagRendersAttributes()
{
$attributes = array(
@@ -126,6 +133,18 @@ public function testCanAppendLabelContentUsingFlagToInvoke()
$this->assertContains('><input type="text" id="foo" />', $markup);
}
+ public function testsetLabelAttributes()
+ {
+ $element = new Element('foo');
+ $element->setLabel('The value for foo:');
+ $element->setLabelAttributes(array('id' => 'bar'));
+ $markup = $this->helper->__invoke($element, '<input type="text" id="foo" />', FormLabelHelper::APPEND);
+ $this->assertContains('"foo" />The value for foo:</label>', $markup);
+ $this->assertContains('id="bar" for="foo"', $markup);
+ $this->assertContains('<label', $markup);
+ $this->assertContains('><input type="text" id="foo" />', $markup);
+ }
+
public function testPassingElementAndContextAndFlagToInvokeRaisesExceptionForMissingLabelAttribute()
{
$element = new Element('foo');
98 tests/ZendTest/Form/View/Helper/FormMultiCheckboxTest.php
View
@@ -266,4 +266,102 @@ public function testTranslatorMethods()
$this->helper->setTranslatorEnabled(false);
$this->assertFalse($this->helper->isTranslatorEnabled());
}
+
+ public function testRenderInputNotSelectElementRaisesException()
+ {
+ $element = new Element\Text('foo');
+ $this->setExpectedException('Zend\Form\Exception\InvalidArgumentException');
+ $this->helper->render($element);
+ }
+
+ public function testRenderElementWithNoNameRaisesException()
+ {
+ $element = new MultiCheckboxElement(null);
+
+ $this->setExpectedException('Zend\Form\Exception\DomainException');
+ $this->helper->render($element);
+ }
+
+ public function testRenderElementWithNoValueOptionsRaisesException()
+ {
+ $element = new MultiCheckboxElement('foo');
+
+ $this->setExpectedException('Zend\Form\Exception\DomainException');
+ $this->helper->render($element);
+ }
+
+ public function testCanMarkSingleOptionAsSelected()
+ {
+ $element = new MultiCheckboxElement('foo');
+ $options = array(
+ 'value1' => 'This is the first label',
+ 1 => array(
+ 'value' => 'value2',
+ 'label' => 'This is the second label (overridden)',
+ 'disabled' => false,
+ 'selected' => true,
+ 'label_attributes' => array('class' => 'label-class'),
+ 'attributes' => array('class' => 'input-class'),
+ ),
+ 'value3' => 'This is the third label',
+ );
+ $element->setValueOptions($options);
+
+ $markup = $this->helper->render($element);
+ $this->assertRegexp('#class="input-class" value="value2" checked="checked"#', $markup);
+ $this->assertNotRegexp('#class="input-class" value="value1" checked="checked"#', $markup);
+ $this->assertNotRegexp('#class="input-class" value="value3" checked="checked"#', $markup);
+ }
+
+ public function testInvokeSetLabelPositionToAppend()
+ {
+ $element = new MultiCheckboxElement('foo');
+ $element->setValueOptions(array(
+ array(
+ 'label' => 'label1',
+ 'value' => 'value1',
+ ),
+ ));
+ $this->helper->__invoke($element, 'append');
+
+ $this->assertSame('append', $this->helper->getLabelPosition());
+ }
+
+ public function testSetLabelPositionInputNullRaisesException()
+ {
+ $this->setExpectedException('Zend\Form\Exception\InvalidArgumentException');
+ $this->helper->setLabelPosition(null);
+ }
+
+ public function testSetLabelAttributes()
+ {
+ $this->helper->setLabelAttributes(array('foo', 'bar'));
+ $this->assertEquals(array(0 => 'foo', 1 => 'bar'), $this->helper->getLabelAttributes());
+ }
+
+ public function testGetUseHiddenElementReturnsDefaultFalse()
+ {
+ $hiddenElement = $this->helper->getUseHiddenElement();
+ $this->assertFalse($hiddenElement);
+ }
+
+ public function testGetUseHiddenElementSetToTrue()
+ {
+ $this->helper->setUseHiddenElement(true);
+ $hiddenElement = $this->helper->getUseHiddenElement();
+ $this->assertTrue($hiddenElement);
+ }
+
+ public function testGetUncheckedValueReturnsDefaultEmptyString()
+ {
+ $uncheckedValue = $this->helper->getUncheckedValue();
+ $this->assertSame('', $uncheckedValue);
+ }
+
+ public function testGetUncheckedValueSetToFoo()
+ {
+ $this->helper->setUncheckedValue('foo');
+ $uncheckedValue = $this->helper->getUncheckedValue();
+ $this->assertSame('foo', $uncheckedValue);
+ }
}
60 tests/ZendTest/Form/View/Helper/FormRowTest.php
View
@@ -106,6 +106,18 @@ public function testCanHandleMultiCheckboxesCorrectly()
$this->assertContains("<label>", $markup);
}
+
+ public function testRenderAttributeId()
+ {
+ $element = new Element\Text('foo');
+ $element->setAttribute('type', 'text');
+ $element->setAttribute('id', 'textId');
+ $element->setLabel('This is a text');
+ $markup = $this->helper->render($element);
+ $this->assertContains('<label for="textId">This is a text</label>', $markup);
+ $this->assertContains('<input type="text" name="foo" id="textId"', $markup);
+ }
+
public function testCanRenderErrors()
{
$element = new Element('foo');
@@ -186,8 +198,6 @@ public function testLabelWillBeTranslated()
$this->assertContains('</label>', $markup);
}
-
-
public function testTranslatorMethods()
{
$translatorMock = $this->getMock('Zend\I18n\Translator\Translator');
@@ -201,4 +211,50 @@ public function testTranslatorMethods()
$this->helper->setTranslatorEnabled(false);
$this->assertFalse($this->helper->isTranslatorEnabled());
}
+
+ public function testInvokeSetLabelPositionToAppend()
+ {
+ $element = new Element('foo');
+ $this->helper->__invoke($element, 'append');
+
+ $this->assertSame('append', $this->helper->getLabelPosition());
+ }
+
+ public function testSetLabelPositionInputNullRaisesException()
+ {
+ $this->setExpectedException('Zend\Form\Exception\InvalidArgumentException');
+ $this->helper->setLabelPosition(null);
+ }
+
+ public function testGetLabelPositionReturnsDefaultPrepend()
+ {
+ $labelPosition = $this->helper->getLabelPosition();
+ $this->assertEquals('prepend', $labelPosition);
+ }
+
+ public function testGetLabelPositionReturnsAppend()
+ {
+ $this->helper->setLabelPosition('append');
+ $labelPosition = $this->helper->getLabelPosition();
+ $this->assertEquals('append', $labelPosition);
+ }
+
+ public function testGetRenderErrorsReturnsDefaultTrue()
+ {
+ $renderErrors = $this->helper->getRenderErrors();
+ $this->assertTrue($renderErrors);
+ }
+
+ public function testGetRenderErrorsSetToFalse()
+ {
+ $this->helper->setRenderErrors(false);
+ $renderErrors = $this->helper->getRenderErrors();
+ $this->assertFalse($renderErrors);
+ }
+
+ public function testSetLabelAttributes()
+ {
+ $this->helper->setLabelAttributes(array('foo', 'bar'));
+ $this->assertEquals(array(0 => 'foo', 1 => 'bar'), $this->helper->getLabelAttributes());
+ }
}
35 tests/ZendTest/Form/View/Helper/FormSelectTest.php
View
@@ -11,6 +11,7 @@
namespace ZendTest\Form\View\Helper;
use PHPUnit_Framework_TestCase as TestCase;
+use Zend\Form\Element;
use Zend\Form\Element\Select as SelectElement;
use Zend\Form\View\Helper\FormSelect as FormSelectHelper;
@@ -104,6 +105,17 @@ public function testCanMarkOptionsAsDisabled()
$this->assertRegexp('#option .*?value="value2" .*?disabled="disabled"#', $markup);
}
+ public function testCanMarkOptionsAsSelected()
+ {
+ $element = $this->getElement();
+ $options = $element->getValueOptions('options');
+ $options[1]['selected'] = true;
+ $element->setValueOptions($options);
+
+ $markup = $this->helper->render($element);
+ $this->assertRegexp('#option .*?value="value2" .*?selected="selected"#', $markup);
+ }
+
public function testOptgroupsAreCreatedWhenAnOptionHasAnOptionsKey()
{
$element = $this->getElement();
@@ -310,4 +322,27 @@ public function testNullEmptyOptionDoesNotRenderEmptyOption()
$this->assertNotContains('<option value=""></option>', $markup);
}
+
+ public function testRenderInputNotSelectElementRaisesException()
+ {
+ $element = new Element\Text('foo');
+ $this->setExpectedException('Zend\Form\Exception\InvalidArgumentException');
+ $this->helper->render($element);
+ }
+
+ public function testRenderElementWithNoNameRaisesException()
+ {
+ $element = new SelectElement();
+
+ $this->setExpectedException('Zend\Form\Exception\DomainException');
+ $this->helper->render($element);
+ }
+
+ public function testRenderElementWithNoValueOptionsRaisesException()
+ {
+ $element = new SelectElement('foo');
+
+ $this->setExpectedException('Zend\Form\Exception\DomainException');
+ $this->helper->render($element);
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.