Completed
Push — master ( 3cc3b2...768def )
by Vitaliy
01:53
created

RequiredTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 37
rs 10
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