public function configure()
 {
     $this->setWidgets(array('id' => new sfWidgetFormInputHidden(), 'user' => new sfWidgetFormInputText(), 'repository' => new sfWidgetFormInputText()));
     $this->setValidators(array('id' => new sfValidatorPropelChoice(array('model' => 'Plugin', 'column' => 'id', 'required' => false)), 'user' => new sfValidatorString(), 'repository' => new sfValidatorString()));
     $c = new sfValidatorAnd(array(new sfValidatorPropelUnique(array('model' => 'Plugin', 'column' => array('githubuser', 'githubrepo'), 'field' => array('user', 'repository')), array('invalid' => 'This plugin is already in the forge!')), new sfValidatorCallback(array('callback' => array($this, 'doValidate')))));
     $c->addOption('execute-if-passed', true);
     $this->validatorSchema->setPostValidator($c);
 }
Пример #2
0
    $t->is($e instanceof sfValidatorErrorSchema, 'max_length', '->clean() throws a sfValidatorSchemaError');
}
$v->setOption('halt_on_error', true);
try {
    $v->clean('foo');
    $t->fail('->clean() throws an sfValidatorError exception if one of the validators fails');
    $t->skip('', 3);
} catch (sfValidatorError $e) {
    $t->pass('->clean() throws an sfValidatorError exception if one of the validators fails');
    $t->is(count($e), 1, '->clean() only returns the first error if halt_on_error option is true');
    $t->is($e[0]->getCode(), 'max_length', '->clean() throws a sfValidatorSchemaError');
    $t->is($e instanceof sfValidatorErrorSchema, 'max_length', '->clean() throws a sfValidatorSchemaError');
}
try {
    $v->setMessage('invalid', 'Invalid.');
    $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->getCode(), 'invalid', '->clean() throws a sfValidatorError if invalid message is not empty');
    $t->is(!$e instanceof sfValidatorErrorSchema, 'max_length', '->clean() throws a sfValidatorError if invalid message is not empty');
}
// ->asString()
$t->diag('->asString()');
$v1 = new sfValidatorString(array('max_length' => 3));
$v2 = new sfValidatorString(array('min_length' => 3));
$v = new sfValidatorAnd(array($v1, $v2));
$t->is($v->asString(), "(\n  String({ max_length: 3 })\n  and\n  String({ min_length: 3 })\n)", '->asString() returns a string representation of the validator');
$v = new sfValidatorAnd(array($v1, $v2), array(), array('required' => 'This is required.'));
$t->is($v->asString(), "(\n  String({ max_length: 3 })\n  and({}, { required: 'This is required.' })\n  String({ min_length: 3 })\n)", '->asString() returns a string representation of the validator');
Пример #3
0
  $t->is(count($e), 1, '->clean() only returns the first error if halt_on_error option is true');
  $t->is($e[0]->getCode(), 'max_length', '->clean() throws a sfValidatorSchemaError');
  $t->is($e instanceof sfValidatorErrorSchema, 'max_length', '->clean() throws a sfValidatorSchemaError');
}

try
{
  $v->setMessage('invalid', 'Invalid.');
  $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->getCode(), 'invalid', '->clean() throws a sfValidatorError if invalid message is not empty');
  $t->is(!$e instanceof sfValidatorErrorSchema, 'max_length', '->clean() throws a sfValidatorError if invalid message is not empty');
}

// ->asString()
$t->diag('->asString()');
$v1 = new sfValidatorString(array('max_length' => 3));
$v2 = new sfValidatorString(array('min_length' => 3));
$v = new sfValidatorAnd(array($v1, $v2));
$t->is($v->asString(), "(\n  String({ max_length: 3 })\n  and\n  String({ min_length: 3 })\n)"
, '->asString() returns a string representation of the validator');

$v = new sfValidatorAnd(array($v1, $v2), array(), array('required' => 'This is required.'));
$t->is($v->asString(), "(\n  String({ max_length: 3 })\n  and({}, { required: 'This is required.' })\n  String({ min_length: 3 })\n)"
, '->asString() returns a string representation of the validator');
 public function __construct()
 {
     parent::__construct();
     $this->setValidators();
 }