Permalink
Browse files

Merge branch 'hotfix/5015'

Close #5015
  • Loading branch information...
2 parents 1cb24f5 + d7eba45 commit 98b5b8504a1d81556622cf814c6b16a30754d853 @weierophinney weierophinney committed Aug 26, 2013
Showing with 44 additions and 1 deletion.
  1. +20 −0 library/Zend/Form/Form.php
  2. +24 −1 tests/ZendTest/Form/FormTest.php
@@ -122,6 +122,26 @@ class Form extends Fieldset implements FormInterface
*/
protected $validationGroup;
+
+ /**
+ * Set options for a form. Accepted options are:
+ * - prefer_form_input_filter: is form input filter is preferred?
+ *
+ * @param array|Traversable $options
+ * @return Element|ElementInterface
+ * @throws Exception\InvalidArgumentException
+ */
+ public function setOptions($options)
+ {
+ parent::setOptions($options);
+
+ if (isset($options['prefer_form_input_filter'])) {
+ $this->setPreferFormInputFilter($options['prefer_form_input_filter']);
+ }
+
+ return $this;
+ }
+
/**
* Add an element or fieldset
*
@@ -1633,10 +1633,33 @@ public function testInputFilterOrderOfPrecedence1()
)
);
- $factory = new \Zend\Form\Factory();
+ $factory = new Factory();
$this->form = $factory->createForm($spec);
$this->form->setPreferFormInputFilter(true);
$this->assertFalse($this->form->getInputFilter()->get('element')
->isRequired());
}
+
+ public function testCanSetPreferFormInputFilterFlagViaSetOptions()
+ {
+ $flag = ! $this->form->getPreferFormInputFilter();
+ $this->form->setOptions(array(
+ 'prefer_form_input_filter' => $flag,
+ ));
+ $this->assertSame($flag, $this->form->getPreferFormInputFilter());
+ }
+
+ public function testFactoryCanSetPreferFormInputFilterFlag()
+ {
+ $factory = new Factory();
+ foreach (array(true, false) as $flag) {
+ $form = $factory->createForm(array(
+ 'name' => 'form',
+ 'options' => array(
+ 'prefer_form_input_filter' => $flag,
+ ),
+ ));
+ $this->assertSame($flag, $form->getPreferFormInputFilter());
+ }
+ }
}

0 comments on commit 98b5b85

Please sign in to comment.