Beispiel #1
0
$t->diag('->hasOption()');
$t->ok($v->hasOption('required'), '->hasOption() returns true if the validator has the option');
$t->ok(!$v->hasOption('nonexistant'), '->hasOption() returns false if the validator does not have the option');
// ->getOption()
$t->diag('->getOption()');
$t->is($v->getOption('required'), false, '->getOption() returns the value of an option');
$t->is($v->getOption('nonexistant'), null, '->getOption() returns null if the option does not exist');
// ->addOption()
$t->diag('->addOption()');
$v->addOption('foobar');
$v->setOption('foobar', 'foo');
$t->is($v->getOption('foobar'), 'foo', '->addOption() adds a new option to a validator');
// ->getOptions() ->setOptions()
$t->diag('->getOptions() ->setOptions()');
$v->setOptions(array('required' => true, 'trim' => false));
$t->is($v->getOptions(), array('required' => true, 'trim' => false, 'empty_value' => null), '->setOptions() changes all options');
// ->getMessages()
$t->diag('->getMessages()');
$t->is($v->getMessages(), array('required' => 'Required.', 'invalid' => 'Invalid.', 'foo' => 'bar'), '->getMessages() returns an array of all error messages');
// ->getMessage()
$t->diag('->getMessage()');
$t->is($v->getMessage('required'), 'Required.', '->getMessage() returns an error message string');
$t->is($v->getMessage('nonexistant'), '', '->getMessage() returns an empty string if the message does not exist');
// ->setMessage()
$t->diag('->setMessage()');
$v->setMessage('required', 'The field is required.');
try {
    $v->clean('');
    $t->isnt($e->getMessage(), 'The field is required.', '->setMessage() changes the default error message string');
} catch (sfValidatorError $e) {
    $t->is($e->getMessage(), 'The field is required.', '->setMessage() changes the default error message string');
$t->diag('->hasOption()');
$t->ok($v->hasOption('required'), '->hasOption() returns true if the validator has the option');
$t->ok(!$v->hasOption('nonexistant'), '->hasOption() returns false if the validator does not have the option');
// ->getOption()
$t->diag('->getOption()');
$t->is($v->getOption('required'), false, '->getOption() returns the value of an option');
$t->is($v->getOption('nonexistant'), null, '->getOption() returns null if the option does not exist');
// ->addOption()
$t->diag('->addOption()');
$v->addOption('foobar');
$v->setOption('foobar', 'foo');
$t->is($v->getOption('foobar'), 'foo', '->addOption() adds a new option to a validator');
// ->getOptions() ->setOptions()
$t->diag('->getOptions() ->setOptions()');
$v->setOptions(array('required' => true, 'trim' => false));
$t->is($v->getOptions(), array('required' => true, 'trim' => false), '->setOptions() changes all options');
// ->getMessages()
$t->diag('->getMessages()');
$t->is($v->getMessages(), array('required' => 'Required.', 'invalid' => 'Invalid.', 'foo' => 'bar'), '->getMessages() returns an array of all error messages');
// ->getMessage()
$t->diag('->getMessage()');
$t->is($v->getMessage('required'), 'Required.', '->getMessage() returns an error message string');
$t->is($v->getMessage('nonexistant'), '', '->getMessage() returns an empty string if the message does not exist');
// ->setMessage()
$t->diag('->setMessage()');
$v->setMessage('required', 'The field is required.');
try {
    $v->clean('');
    $t->isnt($e->getMessage(), 'The field is required.', '->setMessage() changes the default error message string');
} catch (sfValidatorError $e) {
    $t->is($e->getMessage(), 'The field is required.', '->setMessage() changes the default error message string');