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/form-csrf-options-inheritance' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Sep 14, 2012
2 parents 9ff5e2c + 9d72376 commit c3fefd2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
18 changes: 18 additions & 0 deletions library/Zend/Form/Element/Csrf.php
Expand Up @@ -42,6 +42,24 @@ class Csrf extends Element implements InputProviderInterface, ElementPrepareAwar
*/
protected $csrfValidator;

/**
* Accepted options for Csrf:
* - csrf_options: an array used in the Csrf
*
* @param array|\Traversable $options
* @return Csrf
*/
public function setOptions($options)
{
parent::setOptions($options);

if (isset($options['csrf_options'])) {
$this->setCsrfValidatorOptions($options['csrf_options']);
}

return $this;
}

/**
* @return array
*/
Expand Down
15 changes: 15 additions & 0 deletions tests/ZendTest/Form/Element/CsrfTest.php
Expand Up @@ -37,6 +37,7 @@ public function testProvidesInputSpecificationThatIncludesValidatorsBasedOnAttri
break;
default:
break;

}
}
}
Expand All @@ -57,4 +58,18 @@ public function testAllowSettingCsrfValidatorOptions()
$this->assertEquals('foo', $validator->getName());
$this->assertEquals(777, $validator->getTimeout());
}

public function testAllowSettingCsrfOptions()
{
$element = new CsrfElement('foo');
$element->setOptions(array(
'csrf_options' => array(
'timeout' => 777,
'salt' => 'MySalt')
));
$validator = $element->getCsrfValidator();
$this->assertEquals('foo', $validator->getName());
$this->assertEquals(777, $validator->getTimeOut());
$this->assertEquals('MySalt', $validator->getSalt());
}
}

0 comments on commit c3fefd2

Please sign in to comment.