How To Unittest Models With Captcha?

How do we unit test models with Captcha?

(or)

How do we avoid Captcha check during unittest?

Hi

you could set in config/test.php a parameter that you assign that your application is in test mode. then add a condition in the model and view when the captcha is required using this parameter.

That was the only approach I could think of too. Thanks.

I prefer things like captcha check to be in the controller and not the model.




array('verifyCode', 'captcha', 'allowEmpty' => !(CCaptcha::checkRequirements() && Yii::app()->user->isGuest && (!Yii::app()->params['testing']))),



Hi,

If you want to do it in controller, set a scenario for model in Controller


if (Yii::app()->user->isGuest && (!Yii::app()->params['testing'])) {

$model->scenario='test'

}

In model


array('verifyCode', 'captcha', 'allowEmpty' => !CCaptcha::checkRequirements(), 'on'=>'test ),