Exemple #1
0
    $v->clean(array('left' => 'foo', 'right' => 'bar', 'password' => 'oof', 'password_bis' => 'rab', 'user' => array('left' => 'foo', 'right' => 'bar', 'password' => 'oof', 'password_bis' => 'rab')));
    $t->skip('', 7);
} catch (sfValidatorErrorSchema $e) {
    $t->is(count($e->getNamedErrors()), 2, '->clean() throws an exception with all error messages');
    $t->is(count($e->getGlobalErrors()), 1, '->clean() throws an exception with all error messages');
    $t->is(count($e['user']->getNamedErrors()), 1, '->clean() throws an exception with all error messages');
    $t->is(count($e['user']->getGlobalErrors()), 1, '->clean() throws an exception with all error messages');
    $t->is(isset($e['user']) ? $e['user']->getCode() : '', 'invalid password [invalid]', '->clean() throws an exception with all error messages');
    $t->is(isset($e['user']['password']) ? $e['user']['password']->getCode() : '', 'invalid', '->clean() throws an exception with all error messages');
    $t->is($e->getCode(), 'invalid user [invalid password [invalid]] password [invalid]', '->clean() throws an exception with all error messages');
}
// __clone()
$t->diag('__clone()');
$v = new sfValidatorSchema(array('v1' => $v1, 'v2' => $v2));
$v1 = clone $v;
$f1 = $v1->getFields();
$f = $v->getFields();
$t->is(array_keys($f1), array_keys($f), '__clone() clones embedded validators');
foreach ($f1 as $name => $validator) {
    $t->ok($validator !== $f[$name], '__clone() clones embedded validators');
    $t->ok($validator == $f[$name], '__clone() clones embedded validators');
}
$t->is($v1->getPreValidator(), null, '__clone() clones the pre validator');
$t->is($v1->getPostValidator(), null, '__clone() clones the post validator');
$v->setPreValidator(new sfValidatorString(array('min_length' => 4)));
$v->setPostValidator(new sfValidatorString(array('min_length' => 4)));
$v1 = clone $v;
$t->ok($v1->getPreValidator() !== $v->getPreValidator(), '__clone() clones the pre validator');
$t->ok($v1->getPreValidator() == $v->getPreValidator(), '__clone() clones the pre validator');
$t->ok($v1->getPostValidator() !== $v->getPostValidator(), '__clone() clones the post validator');
$t->ok($v1->getPostValidator() == $v->getPostValidator(), '__clone() clones the post validator');
 /**
  * Recursively loop through the form field and validation schema objects
  * until not schema objects and then get validation rules from them
  *
  * @param   sfFormFieldSchema   $formFieldSchema
  * @param   sfValidatorSchema   $validatorSchema
  * @param   boolean             $reset
  * @param   boolean             $overwrite
  *
  * @throws  Exception
  *
  * @return  void
  */
 protected function _recursiveGenerateFieldsAndValidator(sfFormFieldSchema $formFieldSchema, sfValidatorSchema $validatorSchema)
 {
     foreach ($formFieldSchema as $name => $field) {
         if ($field instanceof sfFormFieldSchema) {
             // check validator schema
             if (!isset($validatorSchema[$name]) || !$validatorSchema[$name] instanceof sfValidatorSchema) {
                 // field can exist without a validator
                 continue;
             }
             $this->_recursiveGenerateFieldsAndValidator($field, $validatorSchema[$name]);
             // handle pre and post validators connected to validation schema
         }
         // check validator
         if (!isset($validatorSchema[$name]) || !$validatorSchema[$name] instanceof sfValidatorBase) {
             // field can exist without a validator
             continue;
         }
         $factory = new sfJqueryValidationValidatorParserFactory($field->renderName(), $field, $validatorSchema[$name]);
         $parser = $factory->getParser();
         foreach ($parser->getRules() as $fieldName => $rules) {
             $this->setFieldRules($fieldName, $rules);
         }
         foreach ($parser->getGroups() as $groupName => $fields) {
             $this->setGroup($groupName, $fields);
         }
         $this->setJavascripts(array_merge($this->getJavascripts(), $parser->getJavascripts()));
         $this->setStylesheets(array_merge($this->getStylesheets(), $parser->getStylesheets()));
     }
     // end foreach
     if ($validatorSchema->getPostValidator()) {
         // handle main pre post validators
         $factory = new sfJqueryValidationValidatorParserFactoryPostValidator($formFieldSchema, $validatorSchema->getPostValidator());
         $parser = $factory->getParser();
     }
 }