Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/2361' into develop
Browse files Browse the repository at this point in the history
Close #2361
  • Loading branch information
weierophinney committed Sep 18, 2012
2 parents 89997a1 + 1b3b278 commit e98c3f4
Show file tree
Hide file tree
Showing 21 changed files with 560 additions and 11 deletions.
2 changes: 1 addition & 1 deletion library/Zend/Form/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Form/View/Helper/FormCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function setShouldWrap($wrap)
*/
public function shouldWrap()
{
return $this->shouldWrap();
return $this->shouldWrap;
}

/**
Expand Down
15 changes: 8 additions & 7 deletions library/Zend/Form/View/Helper/FormMultiCheckbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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 changes: 7 additions & 0 deletions tests/ZendTest/Form/Element/CaptchaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
13 changes: 13 additions & 0 deletions tests/ZendTest/Form/Element/CheckboxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 53 additions & 0 deletions tests/ZendTest/Form/Element/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 changes: 11 additions & 0 deletions tests/ZendTest/Form/Element/MultiCheckboxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 15 additions & 0 deletions tests/ZendTest/Form/Element/SelectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 49 additions & 0 deletions tests/ZendTest/Form/ElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 81 additions & 0 deletions tests/ZendTest/Form/FieldsetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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');
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 changes: 33 additions & 0 deletions tests/ZendTest/Form/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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());
}


}
Loading

0 comments on commit e98c3f4

Please sign in to comment.