public function testSettingCaptchaSetsCaptchaAttribute() { $element = new CaptchaElement(); $captcha = new Captcha\Dumb(array('sessionClass' => 'ZendTest\\Captcha\\TestAsset\\SessionContainer')); $element->setCaptcha($captcha); $this->assertSame($captcha, $element->getCaptcha()); }
/** * @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); }
/** * Retrieve captcha (if any) * * @return null|ZendCaptcha\AdapterInterface */ public function getCaptcha() { if (null === $this->captcha) { $serviceLocator = $this->getServiceLocator(); if ($serviceLocator && $serviceLocator->has('Zend\\Session\\ManagerInterface')) { $defaultManager = SessionContainer::getDefaultManager(); $serviceManager = $serviceLocator->get('Zend\\Session\\ManagerInterface'); if ($defaultManager !== $serviceManager) { SessionContainer::setDefaultManager($serviceManager); } } if ($this->defaultCaptcha instanceof AdapterInterface) { $captcha = clone $this->defaultCaptcha; } else { $captcha = $this->defaultCaptcha; } $this->setCaptcha($captcha); } return parent::getCaptcha(); }