Ejemplo n.º 1
0
    $v = new sfValidatorAnd('string');
    $t->fail('__construct() throws an exception when passing a non supported first argument');
} catch (InvalidArgumentException $e) {
    $t->pass('__construct() throws an exception when passing a non supported first argument');
}
// ->addValidator()
$t->diag('->addValidator()');
$v = new sfValidatorAnd();
$v->addValidator($v1);
$v->addValidator($v2);
$t->is($v->getValidators(), array($v1, $v2), '->addValidator() adds a validator');
// ->clean()
$t->diag('->clean()');
$t->is($v->clean('foo'), 'foo', '->clean() returns the string unmodified');
try {
    $v->setOption('required', true);
    $v->clean(null);
    $t->fail('->clean() throws an sfValidatorError exception if the input value is required');
    $t->skip('', 1);
} catch (sfValidatorError $e) {
    $t->pass('->clean() throws an sfValidatorError exception if the input value is required');
    $t->is($e->getCode(), 'required', '->clean() throws a sfValidatorError');
}
$v2->setOption('max_length', 2);
try {
    $v->clean('foo');
    $t->fail('->clean() throws an sfValidatorError exception if one of the validators fails');
    $t->skip('', 2);
} catch (sfValidatorError $e) {
    $t->pass('->clean() throws an sfValidatorError exception if one of the validators fails');
    $t->is($e[0]->getCode(), 'max_length', '->clean() throws a sfValidatorSchemaError');
Ejemplo n.º 2
0
    $v = new sfValidatorAnd('string');
    $t->fail('__construct() throws an exception when passing a non supported first argument');
} catch (InvalidArgumentException $e) {
    $t->pass('__construct() throws an exception when passing a non supported first argument');
}
// ->addValidator()
$t->diag('->addValidator()');
$v = new sfValidatorAnd();
$v->addValidator($v1);
$v->addValidator($v2);
$t->is($v->getValidators(), array($v1, $v2), '->addValidator() adds a validator');
// ->clean()
$t->diag('->clean()');
$t->is($v->clean('foo'), 'foo', '->clean() returns the string unmodified');
try {
    $v->setOption('required', true);
    $v->clean(null);
    $t->fail('->clean() throws an sfValidatorError exception if the input value is required');
    $t->skip('', 1);
} catch (sfValidatorError $e) {
    $t->pass('->clean() throws an sfValidatorError exception if the input value is required');
    $t->is($e->getCode(), 'required', '->clean() throws a sfValidatorError');
}
$v2->setOption('max_length', 2);
try {
    $v->clean('foo');
    $t->fail('->clean() throws an sfValidatorError exception if one of the validators fails');
    $t->skip('', 2);
} catch (sfValidatorError $e) {
    $t->pass('->clean() throws an sfValidatorError exception if one of the validators fails');
    $t->is($e[0]->getCode(), 'max_length', '->clean() throws a sfValidatorSchemaError');