Example #1
0
 public function testSettingCaptchaSetsCaptchaAttribute()
 {
     $element = new CaptchaElement();
     $captcha = new Captcha\Dumb(array('sessionClass' => 'ZendTest\\Captcha\\TestAsset\\SessionContainer'));
     $element->setCaptcha($captcha);
     $this->assertSame($captcha, $element->getCaptcha());
 }
Example #2
0
 /**
  * @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);
 }
Example #3
0
 /**
  * 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();
 }