This repository was archived by the owner on May 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME
More file actions
146 lines (123 loc) · 4.33 KB
/
README
File metadata and controls
146 lines (123 loc) · 4.33 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
## Form tests
sfPHPUnitFormTestCase
// AutoTests fixtures
abstract protected function makeForm();
abstract protected function getFields();
abstract protected function getValidationTestingPlan();
abstract protected function getValidData();
// AutoTests
public function testAutoFields()
public function testAutoRequirements()
public function testAutoValidation()
public function testAutoFormIsValid()
// Utils & Testers
protected function getValidInput()
protected function makeInput(array $input)
protected function cleanInput(array $input)
protected function assertFormFields($expected, sfForm $form, $message = null)
protected function assertFormIsValid(sfForm $form, $message = null)
protected function assertFormHasErrors(sfForm $form, $errorsCount, $message = null)
protected function assertFormError(sfForm $form, $field, $expectedError, $message = null)
protected function checkFormWithPlan(sfForm $form, array $plan, array $input, $errorCode, $message)
protected function makeErrorMess(sfForm $form, $message)
protected function isEmbeddedForm($fieldName)
Example:
class ArticleFormTest extends sfPHPUnitFormTestCase
{
/**
* Skip auto test which saves form
* Default: true
*/
protected $saveForm = false;
/**
* Make form
*/
protected function makeForm()
{
return new ArticleForm();
}
/**
* Return array with all expected form fields with valid valies
*/
protected function getValidData()
{
return array(
'title' => 'Article title',
'slug' => 'slug-code',
'text' => 'Article text',
'author' => array(
'name' => 'Author Name',
),
);
}
/**
* Describe all expected form fields and their requirements
* PostValidator is disabled
*/
protected function getFields()
{
return array(
'title' => array(
'min_length' => 5,
'max_length' => 100,
'trim' => true,
'required' => true,
),
'slug' => array(
'min_length' => array('1234' => false, '12345' => true), // Custom testing plan
'max_length' => 100,
'trim' => true,
'required' => true,
'invalid' => array(
'invalid slug',
),
'success' => array(
'validslug',
'validslug1',
'Valid-Slug1',
),
'transform' => array('SLUG' => 'slug'),
),
'text' => array(
'trim' => true,
'required' => true,
),
'author' => array(
'embed' => 'AuthorForm',
),
'_csrf_token' => array(
'required' => true,
),
);
}
/**
* Custom testing scenarios
*/
protected function getValidationTestingPlan()
{
$validInput = $this->getValidInput();
$someArticle = $this->makeArticle();
return array(
// Уникальность email
'Slug should be unique' => new sfPHPUnitFormValidationItem(
array_merge($validInput, array('slug' => $someArticle->getSlug())),
array(
'email_address' => 'invalid',
)),
);
}
// Do own tests here
/**
* Example
*/
public function testSaveForm()
{
$form = $this->makeForm();
$input = $this->getValidInput();
$input['title'] = 'Some title'
$form->bind($input);
$this->assertFormIsValid($form);
$ob = $form->save();
$this->assertEquals(1, $this->queryFind(get_class($ob), $this->cleanInput($data))->count());
}
}