Got it to work with this way:
1. Add to your test config (it uses by Yii unit tests) some variable lets say, it will be "testmode":
...
'params' => array(
'testmode' => true, // to avoid captcha validation
),
...
-
In your model validation rules set corresponding condition. For me it is following:
In rules:
array(
'verifyCode',
'captchaValid',
'allowEmpty'=>!Yii::app()->user->isGuest || !CCaptcha::checkRequirements(),
'enableClientValidation' => true,
'message'=>Yii::t('app', 'wrong code'),
'on' => array('create'),
),
Below:
public function captchaValid($field, $params) {
if(!$this->hasErrors($field))
{
if (Yii::app()->params['testmode'] == true) // here is our mark
return;
$vc_key = "Yii.CCaptchaAction." . Yii::app()->getId() . ".site.captcha";
if ( Yii::app()->session->get($vc_key) != $this->{$field} )
{
$this->addError($field, $params['message']);
}
}
}
That's all. For my case it was some additional completions, but in most of cases, approach above should work. If you will have some problems with it, let me know.