Permalink
Browse files

Merge branch 'hotfix/2361' into develop

Close #2361
  • Loading branch information...
2 parents 89997a1 + 1b3b278 commit e98c3f4080fb3069757abf10b7d4efca1b4d83af @weierophinney weierophinney committed Sep 18, 2012
@@ -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;
}
@@ -148,7 +148,7 @@ public function setShouldWrap($wrap)
*/
public function shouldWrap()
{
- return $this->shouldWrap();
+ return $this->shouldWrap;
}
/**
@@ -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 . '[]';
}
}
@@ -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();
@@ -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'));
+ }
}
@@ -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());
+ }
+
+
}
@@ -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'));
+ }
}
@@ -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'));
+ }
+
+
}
@@ -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);
+ }
}
@@ -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');
+ }
}
@@ -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());
+ }
+
+
}
Oops, something went wrong.

0 comments on commit e98c3f4

Please sign in to comment.