Completed
Push — master ( 79393d...66e031 )
by Shcherbak
03:26
created

RequiredTest::testSimpleValidation()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 30
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 30
rs 8.8571
nc 1
cc 1
eloc 20
nop 0
1
<?php
2
3
  namespace Tests\Fiv\Form\Validator;
4
5
  use Fiv\Form\Form;
6
  use Fiv\Form\FormData;
7
  use Fiv\Form\Validator\Required;
8
  use PHPUnit_Framework_TestCase;
9
10
  /**
11
   *
12
   */
13
  class RequiredTest extends PHPUnit_Framework_TestCase {
14
15
16
    public function testSimpleValidation() {
17
      $validator = new Required();
18
      $validator->setError('Test error message');
19
20
      $form = new Form();
21
      $form->input('login')
22
        ->addValidator($validator);
23
24
      $form->handle(new FormData('post', [
25
        $form->getUid() => 1,
26
        'login' => 'testLogin',
27
      ]));
28
29
      $this->assertTrue($form->isValid());
30
      $this->assertEmpty($validator->getErrors());
31
32
      $form->handle(new FormData('post', [
33
        $form->getUid() => 1,
34
        'login' => '',
35
      ]));
36
37
      $this->assertFalse($form->isValid());
38
      $this->assertEquals('Test error message', $validator->getFirstError());
39
40
      $form->handle(new FormData('post', [
41
        $form->getUid() => 1,
42
        'login' => '0',
43
      ]));
44
      $this->assertTrue($form->isValid());
45
    }
46
47
  }
48