Skip to content

Commit

Permalink
Merge pull request zendframework#3487 branch 'hotfix/allow-traversabl…
Browse files Browse the repository at this point in the history
…e-in-captcha'
  • Loading branch information
Maks3w committed Jan 18, 2013
2 parents c0e2d53 + d32a381 commit e2045fc
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
4 changes: 2 additions & 2 deletions library/Zend/Form/Element/Captcha.php
Expand Up @@ -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;
Expand Down
20 changes: 20 additions & 0 deletions tests/ZendTest/Form/Element/CaptchaTest.php
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
}
}
29 changes: 29 additions & 0 deletions 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 e2045fc

Please sign in to comment.