Permalink
Browse files

[#3446] Allow generic traversable configuration to Captcha element

  • Loading branch information...
1 parent 0217b59 commit 50647c46d70f74a40a557d4c729fcdfa51daf395 @weierophinney weierophinney committed Jan 18, 2013
View
4 library/Zend/Form/Element/Captcha.php
@@ -39,8 +39,8 @@ public function setOptions($options)
{
parent::setOptions($options);
- if (isset($options['captcha'])) {
- $this->setCaptcha($options['captcha']);
+ if (isset($this->options['captcha'])) {
+ $this->setCaptcha($this->options['captcha']);
}
return $this;
View
20 tests/ZendTest/Form/Element/CaptchaTest.php
@@ -11,10 +11,12 @@
namespace ZendTest\Form\Element;
use PHPUnit_Framework_TestCase as TestCase;
+use ArrayIterator;
use ArrayObject;
use Zend\Captcha;
use Zend\Form\Element\Captcha as CaptchaElement;
use Zend\Form\Factory;
+use ZendTest\Form\TestAsset;
class CaptchaTest extends TestCase
{
@@ -107,4 +109,22 @@ public function testProvidesInputSpecificationThatIncludesCaptchaAsValidator()
$test = array_shift($inputSpec['validators']);
$this->assertSame($captcha, $test);
}
+
+ /**
+ * @group 3446
+ */
+ public function testAllowsPassingTraversableOptionsToConstructor()
+ {
+ $options = new TestAsset\IteratorAggregate(new ArrayIterator(array(
+ 'captcha' => array(
+ 'class' => 'dumb',
+ 'options' => array(
+ 'sessionClass' => 'ZendTest\Captcha\TestAsset\SessionContainer',
+ ),
+ ),
+ )));
+ $element = new CaptchaElement('captcha', $options);
+ $captcha = $element->getCaptcha();
+ $this->assertInstanceOf('Zend\Captcha\Dumb', $captcha);
+ }
}
View
29 tests/ZendTest/Form/TestAsset/IteratorAggregate.php
@@ -0,0 +1,29 @@
+<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @package Zend_Form
+ */
+
+namespace ZendTest\Form\TestAsset;
+
+use Traversable;
+use IteratorAggregate as IteratorAggregateInterface;
+
+class IteratorAggregate implements IteratorAggregateInterface
+{
+ protected $iterator;
+
+ public function __construct(Traversable $iterator)
+ {
+ $this->iterator = $iterator;
+ }
+
+ public function getIterator()
+ {
+ return $this->iterator;
+ }
+}

0 comments on commit 50647c4

Please sign in to comment.