Esempio n. 1
0
$t->diag('__construct()');
$v = new MyValidator(array('required' => false));
$t->is($v->clean(null), null, '__construct() options override the embedded validator options');
$v = new MyValidator(array(), array('required' => 'This is required.'));
try {
    $v->clean(null);
    $t->fail('->clean() throws a sfValidatorError if the value is required');
    $t->skip('', 1);
} catch (sfValidatorError $e) {
    $t->pass('->clean() throws a sfValidatorError if the value is required');
    $t->is($e->getMessage(), 'This is required.', '__construct() messages override the embedded validator messages');
}
$v = new MyValidator();
// ->getErrorCodes()
$t->diag('->getErrorCodes()');
$t->is($v->getErrorCodes(), $v->getValidator()->getErrorCodes(), '->getErrorCodes() is a proxy to the embedded validator method');
// ->asString()
$t->diag('->asString()');
$t->is($v->asString(), $v->getValidator()->asString(), '->asString() is a proxy to the embedded validator method');
// ->getDefaultMessages()
$t->diag('->getDefaultMessages()');
$t->is($v->getDefaultMessages(), $v->getValidator()->getDefaultMessages(), '->getDefaultMessages() is a proxy to the embedded validator method');
// ->getDefaultOptions()
$t->diag('->getDefaultOptions()');
$t->is($v->getDefaultOptions(), $v->getValidator()->getDefaultOptions(), '->getDefaultOptions() is a proxy to the embedded validator method');
// ->getMessage() ->getMessages() ->setMessage() ->setMessages()
$t->diag('->getMessage() ->getMessages() ->setMessage() ->setMessages()');
$v = new MyValidator();
$t->is($v->getMessage('required'), 'This string is required.', '->getMessage() returns a message from the embedded validator');
$v->setMessage('invalid', 'This string is invalid.');
$t->is($v->getMessages(), array('required' => 'This string is required.', 'invalid' => 'This string is invalid.', 'max_length' => '"%value%" is too long (%max_length% characters max).', 'min_length' => '"%value%" is too short (%min_length% characters min).'), '->getMessages() returns messages from the embedded validator');