CCompareValidator not working in a unit test

Hi,

I have a rule specifying that the user has to accept terms of use:




public function rules() {

...

array('termsAccepted', 'compare', 'compareValue'=>'1', 'on'=>'register', 'message'=>'You must accept the terms of use.'),

...

}



That rule works in my register form but not in my unit test:




...

$user->setAttribute('termsAccepted', '1');

$this->assertTrue($user->save());

...



…gives me validation errors on the attribute ‘termsAccepted’.

Could you please explain me why ? Thank you,

Fabrice

is termsAccepted a checkbox??

than you have to set compareValue to ‘on’

According to this page on the wiki, compareValue should be set to true, not ‘on’.

http://www.yiiframework.com/wiki/134/enforcing-you-must-agree-requirements-in-forms

Same behaviour: it works in the browser but not in the unit test.




public function rules() {

...

array('termsAccepted', 'compare', 'compareValue'=>true, 'on'=>'register', 'message'=>'You must accept the terms of use.'),

...

}






...

$user->setAttribute('termsAccepted', true);

$this->assertTrue($user->save());

...



$user->save() gives me false :(