Exemplo n.º 1
0
<?php

/*
 * This file is part of the symfony package.
 * (c) Fabien Potencier <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once __DIR__ . '/../../bootstrap/unit.php';
$t = new lime_test(12);
$v = new sfValidatorString();
// ->clean()
$t->diag('->clean()');
$t->is($v->clean('foo'), 'foo', '->clean() returns the string unmodified');
$v->setOption('required', false);
$t->ok($v->clean(null) === '', '->clean() converts the value to a string');
$t->ok($v->clean(1) === '1', '->clean() converts the value to a string');
$v->setOption('max_length', 2);
$t->is($v->clean('fo'), 'fo', '->clean() checks the maximum length allowed');
try {
    $v->clean('foo');
    $t->fail('"max_length" option set the maximum length of the string');
    $t->skip('', 1);
} catch (sfValidatorError $e) {
    $t->pass('"max_length" option set the maximum length of the string');
    $t->is($e->getCode(), 'max_length', '->clean() throws a sfValidatorError');
}
$v->setMessage('max_length', 'Too long');
try {
    $v->clean('foo');