|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace kwTests; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use CommonTestClass; |
|
7
|
|
|
use kalanis\kw_connect\arrays\Connector; |
|
8
|
|
|
use kalanis\kw_connect\core\Interfaces\IFilterFactory; |
|
9
|
|
|
use kalanis\kw_forms\Adapters\ArrayAdapter; |
|
10
|
|
|
use kalanis\kw_forms\Exceptions\FormsException; |
|
11
|
|
|
use kalanis\kw_forms\Form; |
|
12
|
|
|
use kalanis\kw_table\core\TableException; |
|
13
|
|
|
use kalanis\kw_table\form_kw\Fields; |
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
class FieldsTest extends CommonTestClass |
|
17
|
|
|
{ |
|
18
|
|
|
public function testExactBasic(): void |
|
19
|
|
|
{ |
|
20
|
|
|
$form = new Form('testing'); |
|
21
|
|
|
$lib = new Fields\TextExact(); |
|
22
|
|
|
$this->assertEquals(IFilterFactory::ACTION_EXACT, $lib->getFilterAction()); |
|
23
|
|
|
$lib->setDataSourceConnector(new Connector($this->basicData())); |
|
24
|
|
|
|
|
25
|
|
|
$this->assertEmpty($lib->getForm()); |
|
26
|
|
|
$lib->setForm($form); |
|
27
|
|
|
$this->assertEquals($form, $lib->getForm()); |
|
28
|
|
|
|
|
29
|
|
|
$this->assertEquals('', $lib->getAlias()); |
|
30
|
|
|
$lib->setAlias('test'); |
|
31
|
|
|
$this->assertEquals('test', $lib->getAlias()); |
|
32
|
|
|
|
|
33
|
|
|
$lib->setAttributes(['foo' => 'bar', 'baz' => 'fuu']); |
|
34
|
|
|
$lib->addAttribute('uhu', 'huh'); |
|
35
|
|
|
$lib->add(); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testContains(): void |
|
39
|
|
|
{ |
|
40
|
|
|
$form = new Form('testing'); |
|
41
|
|
|
$lib = new Fields\TextContains(); |
|
42
|
|
|
$lib->setAlias('test'); |
|
43
|
|
|
$lib->setForm($form); |
|
44
|
|
|
$this->assertEquals(IFilterFactory::ACTION_CONTAINS, $lib->getFilterAction()); |
|
45
|
|
|
$lib->add(); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function testOptions(): void |
|
49
|
|
|
{ |
|
50
|
|
|
$form = new Form('testing'); |
|
51
|
|
|
$lib = new Fields\Options(); |
|
52
|
|
|
$lib->setAlias('test'); |
|
53
|
|
|
$lib->setForm($form); |
|
54
|
|
|
$lib->setEmptyItem('nope'); |
|
55
|
|
|
$lib->setOptions(['abc', 'def', 'ghi']); |
|
56
|
|
|
$this->assertEquals(IFilterFactory::ACTION_EXACT, $lib->getFilterAction()); |
|
57
|
|
|
$lib->add(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function testOptionsFilled(): void |
|
61
|
|
|
{ |
|
62
|
|
|
$form = new Form('testing'); |
|
63
|
|
|
$lib = new Fields\OptionsFilledField(['abc', 'def', 'ghi']); |
|
64
|
|
|
$lib->setAlias('test'); |
|
65
|
|
|
$lib->setForm($form); |
|
66
|
|
|
$this->assertEquals(IFilterFactory::ACTION_EXACT, $lib->getFilterAction()); |
|
67
|
|
|
$lib->add(); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function testNumToW(): void |
|
71
|
|
|
{ |
|
72
|
|
|
$form = new Form('testing'); |
|
73
|
|
|
$lib = new Fields\NumToWith(); |
|
74
|
|
|
$lib->setAlias('test'); |
|
75
|
|
|
$lib->setForm($form); |
|
76
|
|
|
$this->assertEquals(IFilterFactory::ACTION_TO_WITH, $lib->getFilterAction()); |
|
77
|
|
|
$lib->add(); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function testNumTo(): void |
|
81
|
|
|
{ |
|
82
|
|
|
$form = new Form('testing'); |
|
83
|
|
|
$lib = new Fields\NumTo(); |
|
84
|
|
|
$lib->setAlias('test'); |
|
85
|
|
|
$lib->setForm($form); |
|
86
|
|
|
$this->assertEquals(IFilterFactory::ACTION_TO, $lib->getFilterAction()); |
|
87
|
|
|
$lib->add(); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function testNumFromW(): void |
|
91
|
|
|
{ |
|
92
|
|
|
$form = new Form('testing'); |
|
93
|
|
|
$lib = new Fields\NumFromWith(); |
|
94
|
|
|
$lib->setAlias('test'); |
|
95
|
|
|
$lib->setForm($form); |
|
96
|
|
|
$this->assertEquals(IFilterFactory::ACTION_FROM_WITH, $lib->getFilterAction()); |
|
97
|
|
|
$lib->add(); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
public function testNumFrom(): void |
|
101
|
|
|
{ |
|
102
|
|
|
$form = new Form('testing'); |
|
103
|
|
|
$lib = new Fields\NumFrom(); |
|
104
|
|
|
$lib->setAlias('test'); |
|
105
|
|
|
$lib->setForm($form); |
|
106
|
|
|
$this->assertEquals(IFilterFactory::ACTION_FROM, $lib->getFilterAction()); |
|
107
|
|
|
$lib->add(); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public function testMultiSelect(): void |
|
111
|
|
|
{ |
|
112
|
|
|
$form = new Form('testing'); |
|
113
|
|
|
$lib = new Fields\MultiSelect('foo'); |
|
114
|
|
|
$lib->setAlias('test'); |
|
115
|
|
|
$lib->setForm($form); |
|
116
|
|
|
$this->assertEquals(IFilterFactory::ACTION_EXACT, $lib->getFilterAction()); |
|
117
|
|
|
$lib->add(); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
public function testCallback(): void |
|
121
|
|
|
{ |
|
122
|
|
|
$form = new Form('testing'); |
|
123
|
|
|
$lib = new Fields\InputCallback([$this, 'callbackOut']); |
|
124
|
|
|
$lib->setAlias('test'); |
|
125
|
|
|
$lib->setForm($form); |
|
126
|
|
|
$this->assertEquals(IFilterFactory::ACTION_EXACT, $lib->getFilterAction()); |
|
127
|
|
|
$lib->add(); |
|
128
|
|
|
$this->assertEquals('prepared', $lib->renderContent()); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
public function callbackOut(): string |
|
132
|
|
|
{ |
|
133
|
|
|
return 'prepared'; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
public function testRange(): void |
|
137
|
|
|
{ |
|
138
|
|
|
$form = new Form('testing'); |
|
139
|
|
|
$lib = new Fields\DateRange(); |
|
140
|
|
|
$lib->setAlias('test'); |
|
141
|
|
|
$lib->setForm($form); |
|
142
|
|
|
$this->assertEquals(IFilterFactory::ACTION_RANGE, $lib->getFilterAction()); |
|
143
|
|
|
$lib->add(); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
public function testPicker(): void |
|
147
|
|
|
{ |
|
148
|
|
|
$form = new Form('testing'); |
|
149
|
|
|
$lib = new Fields\DateTimePicker(); |
|
150
|
|
|
$lib->setAlias('test'); |
|
151
|
|
|
$lib->setForm($form); |
|
152
|
|
|
$this->assertEquals(IFilterFactory::ACTION_EXACT, $lib->getFilterAction()); |
|
153
|
|
|
$lib->add(); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* @throws TableException |
|
158
|
|
|
* @throws FormsException |
|
159
|
|
|
*/ |
|
160
|
|
|
public function testMultiple(): void |
|
161
|
|
|
{ |
|
162
|
|
|
$form = new Form('testing'); |
|
163
|
|
|
$form->setMethod('GET'); |
|
164
|
|
|
$form->setInputs(new ArrayAdapter([ |
|
165
|
|
|
'test_0' => 232, |
|
166
|
|
|
'test_1' => 642, |
|
167
|
|
|
])); |
|
168
|
|
|
|
|
169
|
|
|
$lib = new Fields\Multiple([ |
|
170
|
|
|
new Fields\MultipleValue(new Fields\NumFrom(), 'From'), |
|
171
|
|
|
new Fields\MultipleValue(new Fields\NumToWith(), 'To') |
|
172
|
|
|
]); |
|
173
|
|
|
$lib->setAlias('test'); |
|
174
|
|
|
$lib->setForm($form); |
|
175
|
|
|
$lib->setDataSourceConnector(new Connector($this->basicData())); |
|
176
|
|
|
$this->assertEquals(IFilterFactory::ACTION_MULTIPLE, $lib->getFilterAction()); |
|
177
|
|
|
$lib->add(); |
|
178
|
|
|
|
|
179
|
|
|
$form->process(); |
|
180
|
|
|
$lib->renderContent(); |
|
181
|
|
|
$this->assertEquals([ |
|
182
|
|
|
[IFilterFactory::ACTION_FROM, 232], |
|
183
|
|
|
[IFilterFactory::ACTION_TO_WITH, 642], |
|
184
|
|
|
], $lib->getPairs()); |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* @throws TableException |
|
189
|
|
|
* @throws FormsException |
|
190
|
|
|
*/ |
|
191
|
|
|
public function testMultipleDifferentAliases(): void |
|
192
|
|
|
{ |
|
193
|
|
|
$form = new Form('testing'); |
|
194
|
|
|
$form->setMethod('GET'); |
|
195
|
|
|
$form->setInputs(new ArrayAdapter([ |
|
196
|
|
|
'test_anon' => 232, |
|
197
|
|
|
'fillin' => 642, |
|
198
|
|
|
])); |
|
199
|
|
|
|
|
200
|
|
|
$lib = new Fields\Multiple([ |
|
201
|
|
|
new Fields\MultipleValue(new Fields\NumFrom(), 'From'), |
|
202
|
|
|
new Fields\MultipleValue(new Fields\NumToWith(), 'To', 'fillin') |
|
203
|
|
|
]); |
|
204
|
|
|
$lib->setForm($form); |
|
205
|
|
|
$lib->setDataSourceConnector(new Connector($this->basicData())); |
|
206
|
|
|
$this->assertEquals(IFilterFactory::ACTION_MULTIPLE, $lib->getFilterAction()); |
|
207
|
|
|
$lib->add(); |
|
208
|
|
|
|
|
209
|
|
|
$form->process(); |
|
210
|
|
|
$lib->renderContent(); |
|
211
|
|
|
$this->assertEquals([ |
|
212
|
|
|
[IFilterFactory::ACTION_TO_WITH, 642], |
|
213
|
|
|
], $lib->getPairs()); |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
/** |
|
217
|
|
|
* @throws TableException |
|
218
|
|
|
*/ |
|
219
|
|
|
public function testMultipleFailField(): void |
|
220
|
|
|
{ |
|
221
|
|
|
$this->expectException(TableException::class); |
|
222
|
|
|
new Fields\Multiple([ |
|
223
|
|
|
new Fields\NumFrom(), |
|
224
|
|
|
]); |
|
225
|
|
|
} |
|
226
|
|
|
} |
|
227
|
|
|
|