ZF-12161: Allow setting custom prefix path for CAPTCHA adapters in Zend_Form_Element_Captcha

Issue Type: Bug Created: 2012-04-20T00:55:38.000+0000 Last Updated: 2012-05-07T22:13:43.000+0000 Status: Resolved Fix version(s): - 1.11.12 (22/Jun/12)

  • 1.12.0 (27/Aug/12)

Reporter: Tim Klever (tklever) Assignee: Frank Brückner (frosch) Tags: - Zend_Form

  • FixForZF1.12
  • zf-crteam-priority

Related issues: Attachments: - Captcha.php.patch


When Zend_Form_Element_Captcha::setOptions() runs, it runs Zend_Form_Element_Captcha::setCaptcha() BEFORE it runs Zend_Form_Element::setOptions(). This causes it to attempt to load Captcha Adapters WITHOUT first checking prefix paths passed in the element config. There is no way to specify a custom prefix path for the captcha plugin loader.

Here's the fix:

<pre class="highlight">
public function setOptions(array $options)
        $captcha = NULL;
        $captchaOptions = array();
        if (array_key_exists('captcha', $options)) {
            $captcha = $options['captcha'];
            if (array_key_exists('captchaOptions', $options)) {
                $captchaOptions = $options['captchaOptions'];
        if($captcha !== NULL)
            $this->setCaptcha($captcha, $captchaOptions);
        return $this;


Posted by Frank Brückner (frosch) on 2012-04-20T07:40:08.000+0000

Hi Tim, can you write an unit test for your fix? Thanks.

Posted by Tim Klever (tklever) on 2012-04-23T21:11:29.000+0000

Frank, I'm having a bit of trouble thinking up a unit test.

I can't test the setOptioons function itself (as by the completion of the function, everything will be in place). Testing requires me to have a captcha adapter with a known path that is outside the Zend library. This is going to vary based on testing environment, hence my test would be specific to me.

I'd need to somehow have the test run at line 166 of Zend_Form_Element_Captcha.

The problem is that setCaptcha runs at line 159, and if a custom prefixPath has been passed, it will not be in the plugin loader until line 166. I'm not sure how to write a test that would check the pluginLoader at line 166 and throw an exception if the pluginLoader doesn't contain the passed prefixPath.

Posted by Frank Brückner (frosch) on 2012-04-24T08:51:33.000+0000

Patch and unit test added.

Posted by Adam Lundrigan (adamlundrigan) on 2012-05-07T21:57:21.000+0000

Updated patch to correct issue with unit test (use of assertInstanceOf, which is not PHPUnit 3.4 compatible)

Posted by Adam Lundrigan (adamlundrigan) on 2012-05-07T22:13:43.000+0000

Fixed in trunk (1.12.0): r24773 Fixed in release-1.11 (1.11.12): r24774

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.