/** * Test checking errors. * * @return void */ public function testHasError() { $form = new Form(); $form->validator()->add('email', 'format', ['rule' => 'email'])->add('name', 'length', ['rule' => ['minLength', 10]]); $form->validate(['email' => 'derp', 'name' => 'derp']); $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')); }
/** * Test checking errors. * * @return void */ 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]])->addNested('pass', $nestedValidator); $form->validate(['email' => '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')); }