Hi i am l开发者_Python百科ooking for an idea to skip my captcha comming from sfFormExtraPlugin when I am processing my functional test in symfony?
Any idea?
Thanks!
The way I've done it is simply not to use the captcha at all if the code is running in the test environment. That way you don't have to worry about it during testing. Though I still run it in the development environment, because at least then I can still make sure it works every now and again.
This isn't the greatest solution, though. I'd have hoped that reCaptcha would allow you to define an extra "test" API key, where everything would work as normal except that the keys would always validate, but they didn't the last time I checked.
I suppose the next best thing would be to code the validator for the reCaptcha widget so that if the environment is "test", or based on some app config setting, you just pass the validation without bothering the reCaptcha server.
I'd love to hear if anyone has any better ideas.
ried few stuff, like extended the validator, or the widget to test context, but finally i have just done that: In app.yml :
test:
.general:
recaptcha_enabled: false
In my form :
if(sfConfig::get('app_recaptcha_enabled', true))
$this->validatorSchema['captcha'] = new sfValidatorReCaptcha(array('private_key' => sfConfig::get('app_recaptcha_private_key'), "required" => true));
else
$this->validatorSchema['captcha'] = new sfValidatorString(array('required' => false));
That's all. app.yml is environnement sensitive, so you just have to specify the value for your environnement.
Hope this is going to someone!
精彩评论