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


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:

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;


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

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.

Patch and unit test added.

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

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