This repository has been archived by the owner on Dec 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FormAbstractTest.php
92 lines (83 loc) · 2.52 KB
/
FormAbstractTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
namespace Bupy7\Form\Tests;
use PHPUnit_Framework_TestCase;
use Bupy7\Form\Tests\Asset\SignInForm;
use Bupy7\Form\Tests\Asset\SignInFilter;
use Bupy7\Form\Tests\Asset\EmptyForm;
/**
* @author Vasilij Belosludcev <https://github.com/bupy7>
* @since 1.0.0
*/
class FormAstractTest extends PHPUnit_Framework_TestCase
{
/**
* Testing inputs data.
*/
public function testInputs()
{
// valid
$signInForm = new SignInForm;
$signInForm->setValues([
'email' => 'test@gmail.com',
'password' => '12q34e56t78',
]);
$this->assertTrue($signInForm->isValid());
// invalid
$signInForm = new SignInForm;
$signInForm->setValues([
'email' => 'test@gmail.never',
'password' => '',
]);
$this->assertFalse($signInForm->isValid());
$errors = $signInForm->getErrors();
$this->assertTrue(!empty($errors));
}
/**
* Testing outputs data.
*/
public function testOutputs()
{
// valid
$signInForm = new SignInForm;
$signInForm->setValues([
'email' => 'test@gmail.com',
'password' => ' 12q34e56t78 ',
]);
$this->assertTrue($signInForm->isValid());
$values = $signInForm->getValues();
$this->assertEquals('12q34e56t78', $values['password']);
$values = $signInForm->getValues(false);
$this->assertEquals(' 12q34e56t78 ', $values['password']);
// invalid
$signInForm = new SignInForm;
$signInForm->setValues([
'email' => 'test@gmail.co2m',
'password' => ' 12q34e56t78 ',
]);
$this->assertFalse($signInForm->isValid());
$values = $signInForm->getValues();
$this->assertEquals('12q34e56t78', $values['password']);
$values = $signInForm->getValues(false);
$this->assertEquals(' 12q34e56t78 ', $values['password']);
}
/**
* Testing instance of input filter.
*/
public function testInstanceInputFilter()
{
$signInForm = new SignInForm;
$signInForm->setInputFilter(new SignInFilter);
$this->assertInstanceOf(SignInFilter::class, $signInForm->getInputFilter());
$signInForm->setValues([]);
$this->assertFalse($signInForm->isValid());
}
/**
* Testing empty inputs.
*/
public function testEmptyInputs()
{
$emptyForm = new EmptyForm;
$emptyForm->setValues([]);
$this->assertTrue($emptyForm->isValid());
}
}