| | 305 | |
|---|
| | 306 | $t->diag('complex postValidator'); |
|---|
| | 307 | $comparator1 = new sfValidatorSchemaCompare('password', sfValidatorSchemaCompare::EQUAL, 'password_bis'); |
|---|
| | 308 | $v = new sfValidatorSchema(array( |
|---|
| | 309 | 'left' => new sfValidatorString(array('min_length' => 2)), |
|---|
| | 310 | 'right' => new sfValidatorString(array('min_length' => 2)), |
|---|
| | 311 | 'password' => new sfValidatorString(array('min_length' => 2)), |
|---|
| | 312 | 'password_bis' => new sfValidatorString(array('min_length' => 2)), |
|---|
| | 313 | )); |
|---|
| | 314 | $v->setPostValidator(new sfValidatorAnd(array($comparator, $comparator1))); |
|---|
| | 315 | try |
|---|
| | 316 | { |
|---|
| | 317 | $v->clean(array('left' => 'foo', 'right' => 'bar', 'password' => 'oof', 'password_bis' => 'rab')); |
|---|
| | 318 | $t->skip('', 3); |
|---|
| | 319 | } |
|---|
| | 320 | catch (sfValidatorErrorSchema $e) |
|---|
| | 321 | { |
|---|
| | 322 | $t->is(count($e->getNamedErrors()), 2, '->clean() throws an exception with all error messages'); |
|---|
| | 323 | $t->is(count($e->getGlobalErrors()), 0, '->clean() throws an exception with all error messages'); |
|---|
| | 324 | $t->is($e->getCode(), 'left [invalid] password [invalid]', '->clean() throws an exception with all error messages'); |
|---|
| | 325 | } |
|---|
| | 326 | |
|---|
| | 327 | $comparator->setOption('throw_global_error', true); |
|---|
| | 328 | try |
|---|
| | 329 | { |
|---|
| | 330 | $v->clean(array('left' => 'foo', 'right' => 'bar', 'password' => 'oof', 'password_bis' => 'rab')); |
|---|
| | 331 | $t->skip('', 3); |
|---|
| | 332 | } |
|---|
| | 333 | catch (sfValidatorErrorSchema $e) |
|---|
| | 334 | { |
|---|
| | 335 | $t->is(count($e->getNamedErrors()), 1, '->clean() throws an exception with all error messages'); |
|---|
| | 336 | $t->is(count($e->getGlobalErrors()), 1, '->clean() throws an exception with all error messages'); |
|---|
| | 337 | $t->is($e->getCode(), 'invalid password [invalid]', '->clean() throws an exception with all error messages'); |
|---|
| | 338 | } |
|---|
| | 339 | |
|---|
| | 340 | $userValidator = new sfValidatorSchema(array( |
|---|
| | 341 | 'left' => new sfValidatorString(array('min_length' => 2)), |
|---|
| | 342 | 'right' => new sfValidatorString(array('min_length' => 2)), |
|---|
| | 343 | 'password' => new sfValidatorString(array('min_length' => 2)), |
|---|
| | 344 | 'password_bis' => new sfValidatorString(array('min_length' => 2)), |
|---|
| | 345 | )); |
|---|
| | 346 | $userValidator->setPostValidator(new sfValidatorAnd(array($comparator, $comparator1))); |
|---|
| | 347 | $v = new sfValidatorSchema(array( |
|---|
| | 348 | 'left' => new sfValidatorString(array('min_length' => 2)), |
|---|
| | 349 | 'right' => new sfValidatorString(array('min_length' => 2)), |
|---|
| | 350 | 'password' => new sfValidatorString(array('min_length' => 2)), |
|---|
| | 351 | 'password_bis' => new sfValidatorString(array('min_length' => 2)), |
|---|
| | 352 | 'user' => $userValidator, |
|---|
| | 353 | )); |
|---|
| | 354 | $v->setPostValidator(new sfValidatorAnd(array($comparator, $comparator1))); |
|---|
| | 355 | try |
|---|
| | 356 | { |
|---|
| | 357 | $v->clean(array('left' => 'foo', 'right' => 'bar', 'password' => 'oof', 'password_bis' => 'rab', 'user' => array('left' => 'foo', 'right' => 'bar', 'password' => 'oof', 'password_bis' => 'rab'))); |
|---|
| | 358 | $t->skip('', 7); |
|---|
| | 359 | } |
|---|
| | 360 | catch (sfValidatorErrorSchema $e) |
|---|
| | 361 | { |
|---|
| | 362 | $t->is(count($e->getNamedErrors()), 2, '->clean() throws an exception with all error messages'); |
|---|
| | 363 | $t->is(count($e->getGlobalErrors()), 1, '->clean() throws an exception with all error messages'); |
|---|
| | 364 | $t->is(count($e['user']->getNamedErrors()), 1, '->clean() throws an exception with all error messages'); |
|---|
| | 365 | $t->is(count($e['user']->getGlobalErrors()), 1, '->clean() throws an exception with all error messages'); |
|---|
| | 366 | $t->is(isset($e['user']) ? $e['user']->getCode() : '', 'invalid password [invalid]', '->clean() throws an exception with all error messages'); |
|---|
| | 367 | $t->is(isset($e['user']['password']) ? $e['user']['password']->getCode() : '', 'invalid', '->clean() throws an exception with all error messages'); |
|---|
| | 368 | $t->is($e->getCode(), 'invalid user [invalid password [invalid]] password [invalid]', '->clean() throws an exception with all error messages'); |
|---|
| | 369 | } |
|---|