Просмотр исходного кода

Added support for setting ReCaptcha options via Zend_Captcha_Recaptcha - fixes ZF-7654

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@18164 44c647ce-9c0f-0410-b52a-842ac1e357ba
padraic 16 лет назад
Родитель
Сommit
ae4d18f81f
2 измененных файлов с 50 добавлено и 1 удалено
  1. 14 1
      library/Zend/Captcha/ReCaptcha.php
  2. 36 0
      tests/Zend/Captcha/ReCaptchaTest.php

+ 14 - 1
library/Zend/Captcha/ReCaptcha.php

@@ -63,6 +63,13 @@ class Zend_Captcha_ReCaptcha extends Zend_Captcha_Base
      */
     protected $_serviceParams = array();
 
+    /**
+     * Options defined by the service
+     *
+     * @var array
+     */
+    protected $_serviceOptions = array();
+
     /**#@+
      * Error codes
      */
@@ -135,6 +142,7 @@ class Zend_Captcha_ReCaptcha extends Zend_Captcha_Base
     {
         $this->setService(new Zend_Service_ReCaptcha());
         $this->_serviceParams = $this->getService()->getParams();
+        $this->_serviceOptions = $this->getService()->getOptions();
 
         parent::__construct($options);
 
@@ -171,7 +179,8 @@ class Zend_Captcha_ReCaptcha extends Zend_Captcha_Base
     /**
      * Set option
      *
-     * If option is a service parameter, proxies to the service.
+     * If option is a service parameter, proxies to the service. The same
+     * goes for any service options (distinct from service params)
      *
      * @param  string $key
      * @param  mixed $value
@@ -184,6 +193,10 @@ class Zend_Captcha_ReCaptcha extends Zend_Captcha_Base
             $service->setParam($key, $value);
             return $this;
         }
+        if (isset($this->_serviceOptions[$key])) {
+            $service->setOption($key, $value);
+            return $this;
+        }
         return parent::setOption($key, $value);
     }
 

+ 36 - 0
tests/Zend/Captcha/ReCaptchaTest.php

@@ -130,6 +130,42 @@ class Zend_Captcha_ReCaptchaTest extends PHPUnit_Framework_TestCase
         $this->assertSame($pubKey, $captcha->getService()->getPublicKey());
         $this->assertSame($privKey, $captcha->getService()->getPrivateKey());
     }
+
+    /**
+     * Regression tests for ZF-7654
+     */
+
+    public function testConstructorShouldAllowSettingLangOptionOnServiceObject()
+    {
+        $options = array('lang'=>'fr');
+        $captcha = new Zend_Captcha_ReCaptcha($options);
+        $this->assertEquals('fr', $captcha->getService()->getOption('lang'));
+    }
+
+    public function testConstructorShouldAllowSettingThemeOptionOnServiceObject()
+    {
+        $options = array('theme'=>'black');
+        $captcha = new Zend_Captcha_ReCaptcha($options);
+        $this->assertEquals('black', $captcha->getService()->getOption('theme'));
+    }
+
+    public function testAllowsSettingLangOptionOnServiceObject()
+    {
+        $captcha = new Zend_Captcha_ReCaptcha;
+        $captcha->setOption('lang', 'fr');
+        $this->assertEquals('fr', $captcha->getService()->getOption('lang'));
+    }
+
+    public function testAllowsSettingThemeOptionOnServiceObject()
+    {
+        $captcha = new Zend_Captcha_ReCaptcha;
+        $captcha->setOption('theme', 'black');
+        $this->assertEquals('black', $captcha->getService()->getOption('theme'));
+    }
+
+    /**
+     * End ZF-7654 tests
+    */
 }
 
 class Zend_Captcha_ReCaptchaTest_SessionContainer