Skip to content
Permalink
Browse files

Improve the tests for hasError() as well.

  • Loading branch information...
beporter committed Dec 6, 2015
1 parent 5642564 commit 2bc7f1477e121cfe5ef84ce5782f74cf23f5c36c
Showing with 12 additions and 2 deletions.
  1. +12 −2 tests/TestCase/View/Form/FormContextTest.php
@@ -208,19 +208,29 @@ public function testError()
*/
public function testHasError()
{
$nestedValidator = new Validator();
$nestedValidator
->add('password', 'length', ['rule' => ['minLength', 8]])
->add('confirm', 'length', ['rule' => ['minLength', 8]]);
$form = new Form();
$form->validator()
->add('email', 'format', ['rule' => 'email'])
->add('name', 'length', ['rule' => ['minLength', 10]]);
->add('name', 'length', ['rule' => ['minLength', 10]])
->addNested('pass', $nestedValidator);
$form->validate([
'email' => 'derp',
'name' => 'derp'
'name' => 'derp',
'pass' => [
'password' => 'short',
'confirm' => 'long enough',
],
]);
$context = new FormContext($this->request, ['entity' => $form]);
$this->assertTrue($context->hasError('email'));
$this->assertTrue($context->hasError('name'));
$this->assertFalse($context->hasError('nope'));
$this->assertFalse($context->hasError('nope.nope'));
$this->assertTrue($context->hasError('pass.password'));
}
}

0 comments on commit 2bc7f14

Please sign in to comment.
You can’t perform that action at this time.