Skip to content

Commit

Permalink
Improve the tests for hasError() as well.
Browse files Browse the repository at this point in the history
  • Loading branch information
beporter committed Dec 6, 2015
1 parent 5642564 commit 2bc7f14
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions tests/TestCase/View/Form/FormContextTest.php
Expand Up @@ -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.