1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Backpack\CRUD\Tests\Unit\CrudPanel; |
4
|
|
|
|
5
|
|
|
class CrudPanelFieldsTest extends BaseCrudPanelTest |
6
|
|
|
{ |
7
|
|
|
private $oneTextFieldArray = [ |
|
|
|
|
8
|
|
|
'name' => 'field1', |
9
|
|
|
'label' => 'Field1', |
10
|
|
|
'type' => 'text', |
11
|
|
|
]; |
12
|
|
|
|
13
|
|
|
private $expectedOneTextFieldArray = [ |
14
|
|
|
'field1' => [ |
15
|
|
|
'name' => 'field1', |
16
|
|
|
'label' => 'Field1', |
17
|
|
|
'type' => 'text', |
18
|
|
|
], |
19
|
|
|
]; |
20
|
|
|
|
21
|
|
|
private $unknownFieldTypeArray = [ |
22
|
|
|
'name' => 'field1', |
23
|
|
|
'type' => 'unknownType', |
24
|
|
|
]; |
25
|
|
|
|
26
|
|
|
private $invalidTwoFieldsArray = [ |
27
|
|
|
[ |
28
|
|
|
'keyOne' => 'field1', |
29
|
|
|
'keyTwo' => 'Field1', |
30
|
|
|
], |
31
|
|
|
[ |
32
|
|
|
'otherKey' => 'field2', |
33
|
|
|
], |
34
|
|
|
]; |
35
|
|
|
|
36
|
|
|
private $twoTextFieldsArray = [ |
37
|
|
|
[ |
38
|
|
|
'name' => 'field1', |
39
|
|
|
'label' => 'Field1', |
40
|
|
|
'type' => 'text', |
41
|
|
|
], |
42
|
|
|
[ |
43
|
|
|
'name' => 'field2', |
44
|
|
|
'label' => 'Field2', |
45
|
|
|
], |
46
|
|
|
]; |
47
|
|
|
|
48
|
|
|
private $expectedTwoTextFieldsArray = [ |
49
|
|
|
'field1' => [ |
50
|
|
|
'name' => 'field1', |
51
|
|
|
'label' => 'Field1', |
52
|
|
|
'type' => 'text', |
53
|
|
|
], |
54
|
|
|
'field2' => [ |
55
|
|
|
'name' => 'field2', |
56
|
|
|
'label' => 'Field2', |
57
|
|
|
'type' => 'text', |
58
|
|
|
], |
59
|
|
|
]; |
60
|
|
|
|
61
|
|
|
private $threeTextFieldsArray = [ |
62
|
|
|
[ |
63
|
|
|
'name' => 'field1', |
64
|
|
|
'label' => 'Field1', |
65
|
|
|
'type' => 'text', |
66
|
|
|
], |
67
|
|
|
[ |
68
|
|
|
'name' => 'field2', |
69
|
|
|
'label' => 'Field2', |
70
|
|
|
], |
71
|
|
|
[ |
72
|
|
|
'name' => 'field3', |
73
|
|
|
], |
74
|
|
|
]; |
75
|
|
|
|
76
|
|
|
private $expectedThreeTextFieldsArray = [ |
77
|
|
|
'field1' => [ |
78
|
|
|
'name' => 'field1', |
79
|
|
|
'label' => 'Field1', |
80
|
|
|
'type' => 'text', |
81
|
|
|
], |
82
|
|
|
'field2' => [ |
83
|
|
|
'name' => 'field2', |
84
|
|
|
'label' => 'Field2', |
85
|
|
|
'type' => 'text', |
86
|
|
|
], |
87
|
|
|
'field3' => [ |
88
|
|
|
'name' => 'field3', |
89
|
|
|
'label' => 'Field3', |
90
|
|
|
'type' => 'text', |
91
|
|
|
], |
92
|
|
|
]; |
93
|
|
|
|
94
|
|
|
private $multipleFieldTypesArray = [ |
95
|
|
|
[ |
96
|
|
|
'name' => 'field1', |
97
|
|
|
'label' => 'Field1', |
98
|
|
|
], |
99
|
|
|
[ |
100
|
|
|
'name' => 'field2', |
101
|
|
|
'type' => 'address', |
102
|
|
|
], |
103
|
|
|
[ |
104
|
|
|
'name' => 'field3', |
105
|
|
|
'type' => 'address', |
106
|
|
|
], |
107
|
|
|
[ |
108
|
|
|
'name' => 'field4', |
109
|
|
|
'type' => 'checkbox', |
110
|
|
|
], |
111
|
|
|
[ |
112
|
|
|
'name' => 'field5', |
113
|
|
|
'type' => 'date', |
114
|
|
|
], |
115
|
|
|
[ |
116
|
|
|
'name' => 'field6', |
117
|
|
|
'type' => 'email', |
118
|
|
|
], |
119
|
|
|
[ |
120
|
|
|
'name' => 'field7', |
121
|
|
|
'type' => 'hidden', |
122
|
|
|
], |
123
|
|
|
[ |
124
|
|
|
'name' => 'field8', |
125
|
|
|
'type' => 'password', |
126
|
|
|
], |
127
|
|
|
[ |
128
|
|
|
'name' => 'field9', |
129
|
|
|
'type' => 'select2', |
130
|
|
|
], |
131
|
|
|
[ |
132
|
|
|
'name' => 'field10', |
133
|
|
|
'type' => 'select2_multiple', |
134
|
|
|
], |
135
|
|
|
[ |
136
|
|
|
'name' => 'field11', |
137
|
|
|
'type' => 'table', |
138
|
|
|
], |
139
|
|
|
[ |
140
|
|
|
'name' => 'field12', |
141
|
|
|
'type' => 'url', |
142
|
|
|
], |
143
|
|
|
]; |
144
|
|
|
|
145
|
|
|
private $expectedMultipleFieldTypesArray = [ |
146
|
|
|
'field1' => [ |
147
|
|
|
'name' => 'field1', |
148
|
|
|
'label' => 'Field1', |
149
|
|
|
'type' => 'text', |
150
|
|
|
], |
151
|
|
|
'field2' => [ |
152
|
|
|
'name' => 'field2', |
153
|
|
|
'type' => 'address', |
154
|
|
|
'label' => 'Field2', |
155
|
|
|
], |
156
|
|
|
'field3' => [ |
157
|
|
|
'name' => 'field3', |
158
|
|
|
'type' => 'address', |
159
|
|
|
'label' => 'Field3', |
160
|
|
|
], |
161
|
|
|
'field4' => [ |
162
|
|
|
'name' => 'field4', |
163
|
|
|
'type' => 'checkbox', |
164
|
|
|
'label' => 'Field4', |
165
|
|
|
], |
166
|
|
|
'field5' => [ |
167
|
|
|
'name' => 'field5', |
168
|
|
|
'type' => 'date', |
169
|
|
|
'label' => 'Field5', |
170
|
|
|
], |
171
|
|
|
'field6' => [ |
172
|
|
|
'name' => 'field6', |
173
|
|
|
'type' => 'email', |
174
|
|
|
'label' => 'Field6', |
175
|
|
|
], |
176
|
|
|
'field7' => [ |
177
|
|
|
'name' => 'field7', |
178
|
|
|
'type' => 'hidden', |
179
|
|
|
'label' => 'Field7', |
180
|
|
|
], |
181
|
|
|
'field8' => [ |
182
|
|
|
'name' => 'field8', |
183
|
|
|
'type' => 'password', |
184
|
|
|
'label' => 'Field8', |
185
|
|
|
], |
186
|
|
|
'field9' => [ |
187
|
|
|
'name' => 'field9', |
188
|
|
|
'type' => 'select2', |
189
|
|
|
'label' => 'Field9', |
190
|
|
|
], |
191
|
|
|
'field10' => [ |
192
|
|
|
'name' => 'field10', |
193
|
|
|
'type' => 'select2_multiple', |
194
|
|
|
'label' => 'Field10', |
195
|
|
|
], |
196
|
|
|
'field11' => [ |
197
|
|
|
'name' => 'field11', |
198
|
|
|
'type' => 'table', |
199
|
|
|
'label' => 'Field11', |
200
|
|
|
], |
201
|
|
|
'field12' => [ |
202
|
|
|
'name' => 'field12', |
203
|
|
|
'type' => 'url', |
204
|
|
|
'label' => 'Field12', |
205
|
|
|
], |
206
|
|
|
]; |
207
|
|
|
|
208
|
|
View Code Duplication |
public function testAddFieldByName() |
|
|
|
|
209
|
|
|
{ |
210
|
|
|
$this->crudPanel->addField('field1'); |
211
|
|
|
|
212
|
|
|
$this->assertEquals(1, count($this->crudPanel->create_fields)); |
213
|
|
|
$this->assertEquals(1, count($this->crudPanel->update_fields)); |
214
|
|
|
$this->assertEquals($this->expectedOneTextFieldArray, $this->crudPanel->create_fields); |
215
|
|
|
$this->assertEquals($this->expectedOneTextFieldArray, $this->crudPanel->update_fields); |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
public function testAddFieldsByName() |
219
|
|
|
{ |
220
|
|
|
$this->crudPanel->addFields(['field1', 'field2', 'field3']); |
221
|
|
|
|
222
|
|
|
$this->assertEquals(3, count($this->crudPanel->create_fields)); |
223
|
|
|
$this->assertEquals(3, count($this->crudPanel->update_fields)); |
224
|
|
|
$this->assertEquals($this->expectedThreeTextFieldsArray, $this->crudPanel->create_fields); |
225
|
|
|
$this->assertEquals($this->expectedThreeTextFieldsArray, $this->crudPanel->update_fields); |
226
|
|
|
} |
227
|
|
|
|
228
|
|
View Code Duplication |
public function testAddFieldsAsArray() |
|
|
|
|
229
|
|
|
{ |
230
|
|
|
$this->crudPanel->addFields($this->threeTextFieldsArray); |
231
|
|
|
|
232
|
|
|
$this->assertEquals(3, count($this->crudPanel->create_fields)); |
233
|
|
|
$this->assertEquals(3, count($this->crudPanel->update_fields)); |
234
|
|
|
$this->assertEquals($this->expectedThreeTextFieldsArray, $this->crudPanel->create_fields); |
235
|
|
|
$this->assertEquals($this->expectedThreeTextFieldsArray, $this->crudPanel->update_fields); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
View Code Duplication |
public function testAddFieldsDifferentTypes() |
|
|
|
|
239
|
|
|
{ |
240
|
|
|
$this->crudPanel->addFields($this->multipleFieldTypesArray); |
241
|
|
|
|
242
|
|
|
$this->assertEquals(12, count($this->crudPanel->create_fields)); |
243
|
|
|
$this->assertEquals(12, count($this->crudPanel->update_fields)); |
244
|
|
|
$this->assertEquals($this->expectedMultipleFieldTypesArray, $this->crudPanel->create_fields); |
245
|
|
|
$this->assertEquals($this->expectedMultipleFieldTypesArray, $this->crudPanel->update_fields); |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
public function testAddFieldsInvalidArray() |
249
|
|
|
{ |
250
|
|
|
$this->setExpectedException(\ErrorException::class); |
251
|
|
|
|
252
|
|
|
$this->crudPanel->addFields($this->invalidTwoFieldsArray); |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
public function testAddFieldWithInvalidType() |
256
|
|
|
{ |
257
|
|
|
$this->markTestIncomplete('Not correctly implemented'); |
258
|
|
|
|
259
|
|
|
// TODO: should we validate field types and throw an error if they're not in the pre-defined list of fields or |
260
|
|
|
// in the list of custom field? |
261
|
|
|
$this->crudPanel->addFields($this->unknownFieldTypeArray); |
262
|
|
|
} |
263
|
|
|
|
264
|
|
View Code Duplication |
public function testAddFieldsForCreateForm() |
|
|
|
|
265
|
|
|
{ |
266
|
|
|
$this->crudPanel->addFields($this->threeTextFieldsArray, 'create'); |
267
|
|
|
|
268
|
|
|
$this->assertEquals(3, count($this->crudPanel->create_fields)); |
269
|
|
|
$this->assertEquals($this->expectedThreeTextFieldsArray, $this->crudPanel->create_fields); |
270
|
|
|
$this->assertEmpty($this->crudPanel->update_fields); |
271
|
|
|
} |
272
|
|
|
|
273
|
|
View Code Duplication |
public function testAddFieldsForUpdateForm() |
|
|
|
|
274
|
|
|
{ |
275
|
|
|
$this->crudPanel->addFields($this->threeTextFieldsArray, 'update'); |
276
|
|
|
|
277
|
|
|
$this->assertEquals(3, count($this->crudPanel->update_fields)); |
278
|
|
|
$this->assertEquals($this->expectedThreeTextFieldsArray, $this->crudPanel->update_fields); |
279
|
|
|
$this->assertEmpty($this->crudPanel->create_fields); |
280
|
|
|
} |
281
|
|
|
|
282
|
|
View Code Duplication |
public function testBeforeField() |
|
|
|
|
283
|
|
|
{ |
284
|
|
|
$this->crudPanel->addFields($this->threeTextFieldsArray); |
285
|
|
|
|
286
|
|
|
$this->crudPanel->beforeField('field2'); |
287
|
|
|
|
288
|
|
|
$createKeys = array_keys($this->crudPanel->create_fields); |
289
|
|
|
$this->assertEquals($this->expectedThreeTextFieldsArray['field3'], $this->crudPanel->create_fields[$createKeys[1]]); |
|
|
|
|
290
|
|
|
$this->assertEquals(['field1', 'field3', 'field2'], $createKeys); |
291
|
|
|
|
292
|
|
|
$updateKeys = array_keys($this->crudPanel->update_fields); |
293
|
|
|
$this->assertEquals($this->expectedThreeTextFieldsArray['field3'], $this->crudPanel->update_fields[$updateKeys[1]]); |
|
|
|
|
294
|
|
|
$this->assertEquals(['field1', 'field3', 'field2'], $updateKeys); |
295
|
|
|
} |
296
|
|
|
|
297
|
|
View Code Duplication |
public function testBeforeFieldFirstField() |
|
|
|
|
298
|
|
|
{ |
299
|
|
|
$this->crudPanel->addFields($this->threeTextFieldsArray); |
300
|
|
|
|
301
|
|
|
$this->crudPanel->beforeField('field1'); |
302
|
|
|
|
303
|
|
|
$createKeys = array_keys($this->crudPanel->create_fields); |
304
|
|
|
$this->assertEquals($this->expectedThreeTextFieldsArray['field3'], $this->crudPanel->create_fields[$createKeys[0]]); |
|
|
|
|
305
|
|
|
$this->assertEquals(['field3', 'field1', 'field2'], $createKeys); |
306
|
|
|
|
307
|
|
|
$updateKeys = array_keys($this->crudPanel->update_fields); |
308
|
|
|
$this->assertEquals($this->expectedThreeTextFieldsArray['field3'], $this->crudPanel->update_fields[$updateKeys[0]]); |
|
|
|
|
309
|
|
|
$this->assertEquals(['field3', 'field1', 'field2'], $updateKeys); |
310
|
|
|
} |
311
|
|
|
|
312
|
|
View Code Duplication |
public function testBeforeFieldLastField() |
|
|
|
|
313
|
|
|
{ |
314
|
|
|
$this->crudPanel->addFields($this->threeTextFieldsArray); |
315
|
|
|
|
316
|
|
|
$this->crudPanel->beforeField('field3'); |
317
|
|
|
|
318
|
|
|
$createKeys = array_keys($this->crudPanel->create_fields); |
319
|
|
|
$this->assertEquals($this->expectedThreeTextFieldsArray['field3'], $this->crudPanel->create_fields[$createKeys[2]]); |
|
|
|
|
320
|
|
|
$this->assertEquals(['field1', 'field2', 'field3'], $createKeys); |
321
|
|
|
|
322
|
|
|
$updateKeys = array_keys($this->crudPanel->update_fields); |
323
|
|
|
$this->assertEquals($this->expectedThreeTextFieldsArray['field3'], $this->crudPanel->update_fields[$updateKeys[2]]); |
|
|
|
|
324
|
|
|
$this->assertEquals(['field1', 'field2', 'field3'], $updateKeys); |
325
|
|
|
} |
326
|
|
|
|
327
|
|
View Code Duplication |
public function testBeforeFieldCreateForm() |
|
|
|
|
328
|
|
|
{ |
329
|
|
|
$this->crudPanel->addFields($this->threeTextFieldsArray); |
330
|
|
|
|
331
|
|
|
$this->crudPanel->beforeField('field1', 'create'); |
332
|
|
|
|
333
|
|
|
$createKeys = array_keys($this->crudPanel->create_fields); |
334
|
|
|
$this->assertEquals($this->expectedThreeTextFieldsArray['field3'], $this->crudPanel->create_fields[$createKeys[0]]); |
|
|
|
|
335
|
|
|
$this->assertEquals(['field3', 'field1', 'field2'], $createKeys); |
336
|
|
|
|
337
|
|
|
$updateKeys = array_keys($this->crudPanel->update_fields); |
338
|
|
|
$this->assertEquals($this->expectedThreeTextFieldsArray['field3'], $this->crudPanel->update_fields[$updateKeys[2]]); |
|
|
|
|
339
|
|
|
$this->assertEquals(['field1', 'field2', 'field3'], $updateKeys); |
340
|
|
|
} |
341
|
|
|
|
342
|
|
View Code Duplication |
public function testBeforeFieldUpdateForm() |
|
|
|
|
343
|
|
|
{ |
344
|
|
|
$this->crudPanel->addFields($this->threeTextFieldsArray); |
345
|
|
|
|
346
|
|
|
$this->crudPanel->beforeField('field1', 'update'); |
347
|
|
|
|
348
|
|
|
$createKeys = array_keys($this->crudPanel->create_fields); |
349
|
|
|
$this->assertEquals($this->expectedThreeTextFieldsArray['field3'], $this->crudPanel->create_fields[$createKeys[2]]); |
|
|
|
|
350
|
|
|
$this->assertEquals(['field1', 'field2', 'field3'], $createKeys); |
351
|
|
|
|
352
|
|
|
$updateKeys = array_keys($this->crudPanel->update_fields); |
353
|
|
|
$this->assertEquals($this->expectedThreeTextFieldsArray['field3'], $this->crudPanel->update_fields[$updateKeys[0]]); |
|
|
|
|
354
|
|
|
$this->assertEquals(['field3', 'field1', 'field2'], $updateKeys); |
355
|
|
|
} |
356
|
|
|
|
357
|
|
View Code Duplication |
public function testBeforeFieldForDifferentFieldsInCreateAndUpdate() |
|
|
|
|
358
|
|
|
{ |
359
|
|
|
$this->crudPanel->addFields($this->threeTextFieldsArray, 'create'); |
360
|
|
|
$this->crudPanel->addFields($this->twoTextFieldsArray, 'update'); |
361
|
|
|
|
362
|
|
|
$this->crudPanel->beforeField('field1'); |
363
|
|
|
|
364
|
|
|
$createKeys = array_keys($this->crudPanel->create_fields); |
365
|
|
|
$this->assertEquals($this->expectedThreeTextFieldsArray['field3'], $this->crudPanel->create_fields[$createKeys[0]]); |
|
|
|
|
366
|
|
|
$this->assertEquals(['field3', 'field1', 'field2'], $createKeys); |
367
|
|
|
|
368
|
|
|
$updateKeys = array_keys($this->crudPanel->update_fields); |
369
|
|
|
$this->assertEquals($this->expectedTwoTextFieldsArray['field2'], $this->crudPanel->update_fields[$updateKeys[0]]); |
|
|
|
|
370
|
|
|
$this->assertEquals(['field2', 'field1'], $updateKeys); |
371
|
|
|
} |
372
|
|
|
|
373
|
|
View Code Duplication |
public function testBeforeUnknownField() |
|
|
|
|
374
|
|
|
{ |
375
|
|
|
$this->crudPanel->addFields($this->threeTextFieldsArray); |
376
|
|
|
|
377
|
|
|
$this->crudPanel->beforeField('field4'); |
378
|
|
|
|
379
|
|
|
$this->assertEquals(3, count($this->crudPanel->create_fields)); |
380
|
|
|
$this->assertEquals(3, count($this->crudPanel->update_fields)); |
381
|
|
|
$this->assertEquals(array_keys($this->expectedThreeTextFieldsArray), array_keys($this->crudPanel->create_fields)); |
|
|
|
|
382
|
|
|
$this->assertEquals(array_keys($this->expectedThreeTextFieldsArray), array_keys($this->crudPanel->update_fields)); |
|
|
|
|
383
|
|
|
} |
384
|
|
|
|
385
|
|
View Code Duplication |
public function testAfterField() |
|
|
|
|
386
|
|
|
{ |
387
|
|
|
$this->crudPanel->addFields($this->threeTextFieldsArray); |
388
|
|
|
|
389
|
|
|
$this->crudPanel->afterField('field1'); |
390
|
|
|
|
391
|
|
|
$createKeys = array_keys($this->crudPanel->create_fields); |
392
|
|
|
$this->assertEquals($this->expectedThreeTextFieldsArray['field3'], $this->crudPanel->create_fields[$createKeys[1]]); |
|
|
|
|
393
|
|
|
$this->assertEquals(['field1', 'field3', 'field2'], $createKeys); |
394
|
|
|
|
395
|
|
|
$updateKeys = array_keys($this->crudPanel->update_fields); |
396
|
|
|
$this->assertEquals($this->expectedThreeTextFieldsArray['field3'], $this->crudPanel->update_fields[$updateKeys[1]]); |
|
|
|
|
397
|
|
|
$this->assertEquals(['field1', 'field3', 'field2'], $updateKeys); |
398
|
|
|
} |
399
|
|
|
|
400
|
|
View Code Duplication |
public function testAfterFieldLastField() |
|
|
|
|
401
|
|
|
{ |
402
|
|
|
$this->crudPanel->addFields($this->threeTextFieldsArray); |
403
|
|
|
|
404
|
|
|
$this->crudPanel->afterField('field3'); |
405
|
|
|
|
406
|
|
|
$createKeys = array_keys($this->crudPanel->create_fields); |
407
|
|
|
$this->assertEquals($this->expectedThreeTextFieldsArray['field3'], $this->crudPanel->create_fields[$createKeys[2]]); |
|
|
|
|
408
|
|
|
$this->assertEquals(['field1', 'field2', 'field3'], $createKeys); |
409
|
|
|
|
410
|
|
|
$updateKeys = array_keys($this->crudPanel->update_fields); |
411
|
|
|
$this->assertEquals($this->expectedThreeTextFieldsArray['field3'], $this->crudPanel->update_fields[$updateKeys[2]]); |
|
|
|
|
412
|
|
|
$this->assertEquals(['field1', 'field2', 'field3'], $updateKeys); |
413
|
|
|
} |
414
|
|
|
|
415
|
|
View Code Duplication |
public function testAfterFieldCreateForm() |
|
|
|
|
416
|
|
|
{ |
417
|
|
|
$this->crudPanel->addFields($this->threeTextFieldsArray); |
418
|
|
|
|
419
|
|
|
$this->crudPanel->afterField('field1', 'create'); |
420
|
|
|
|
421
|
|
|
$createKeys = array_keys($this->crudPanel->create_fields); |
422
|
|
|
$this->assertEquals($this->expectedThreeTextFieldsArray['field3'], $this->crudPanel->create_fields[$createKeys[1]]); |
|
|
|
|
423
|
|
|
$this->assertEquals(['field1', 'field3', 'field2'], $createKeys); |
424
|
|
|
|
425
|
|
|
$updateKeys = array_keys($this->crudPanel->update_fields); |
426
|
|
|
$this->assertEquals($this->expectedThreeTextFieldsArray['field3'], $this->crudPanel->update_fields[$updateKeys[2]]); |
|
|
|
|
427
|
|
|
$this->assertEquals(['field1', 'field2', 'field3'], $updateKeys); |
428
|
|
|
} |
429
|
|
|
|
430
|
|
View Code Duplication |
public function testAfterFieldUpdateForm() |
|
|
|
|
431
|
|
|
{ |
432
|
|
|
$this->crudPanel->addFields($this->threeTextFieldsArray); |
433
|
|
|
|
434
|
|
|
$this->crudPanel->afterField('field1', 'update'); |
435
|
|
|
|
436
|
|
|
$createKeys = array_keys($this->crudPanel->create_fields); |
437
|
|
|
$this->assertEquals($this->expectedThreeTextFieldsArray['field3'], $this->crudPanel->create_fields[$createKeys[2]]); |
|
|
|
|
438
|
|
|
$this->assertEquals(['field1', 'field2', 'field3'], $createKeys); |
439
|
|
|
|
440
|
|
|
$updateKeys = array_keys($this->crudPanel->update_fields); |
441
|
|
|
$this->assertEquals($this->expectedThreeTextFieldsArray['field3'], $this->crudPanel->update_fields[$updateKeys[1]]); |
|
|
|
|
442
|
|
|
$this->assertEquals(['field1', 'field3', 'field2'], $updateKeys); |
443
|
|
|
} |
444
|
|
|
|
445
|
|
View Code Duplication |
public function testAfterFieldForDifferentFieldsInCreateAndUpdate() |
|
|
|
|
446
|
|
|
{ |
447
|
|
|
$this->crudPanel->addFields($this->threeTextFieldsArray, 'create'); |
448
|
|
|
$this->crudPanel->addFields($this->twoTextFieldsArray, 'update'); |
449
|
|
|
|
450
|
|
|
$this->crudPanel->afterField('field1'); |
451
|
|
|
|
452
|
|
|
$createKeys = array_keys($this->crudPanel->create_fields); |
453
|
|
|
$this->assertEquals($this->expectedThreeTextFieldsArray['field3'], $this->crudPanel->create_fields[$createKeys[1]]); |
|
|
|
|
454
|
|
|
$this->assertEquals(['field1', 'field3', 'field2'], $createKeys); |
455
|
|
|
|
456
|
|
|
$updateKeys = array_keys($this->crudPanel->update_fields); |
457
|
|
|
$this->assertEquals($this->expectedTwoTextFieldsArray['field2'], $this->crudPanel->update_fields[$updateKeys[1]]); |
|
|
|
|
458
|
|
|
$this->assertEquals(['field1', 'field2'], $updateKeys); |
459
|
|
|
} |
460
|
|
|
|
461
|
|
View Code Duplication |
public function testAfterUnknownField() |
|
|
|
|
462
|
|
|
{ |
463
|
|
|
$this->crudPanel->addFields($this->threeTextFieldsArray); |
464
|
|
|
|
465
|
|
|
$this->crudPanel->afterField('field4'); |
466
|
|
|
|
467
|
|
|
$this->assertEquals(3, count($this->crudPanel->create_fields)); |
468
|
|
|
$this->assertEquals(3, count($this->crudPanel->update_fields)); |
469
|
|
|
$this->assertEquals(array_keys($this->expectedThreeTextFieldsArray), array_keys($this->crudPanel->create_fields)); |
|
|
|
|
470
|
|
|
$this->assertEquals(array_keys($this->expectedThreeTextFieldsArray), array_keys($this->crudPanel->update_fields)); |
|
|
|
|
471
|
|
|
} |
472
|
|
|
|
473
|
|
|
public function testRemoveFieldsByName() |
474
|
|
|
{ |
475
|
|
|
$this->crudPanel->addFields($this->threeTextFieldsArray); |
476
|
|
|
|
477
|
|
|
$this->crudPanel->removeFields(['field1']); |
478
|
|
|
|
479
|
|
|
$this->assertEquals(2, count($this->crudPanel->create_fields)); |
480
|
|
|
$this->assertEquals(2, count($this->crudPanel->update_fields)); |
481
|
|
|
$this->assertEquals(['field2', 'field3'], array_keys($this->crudPanel->create_fields)); |
482
|
|
|
$this->assertEquals(['field2', 'field3'], array_keys($this->crudPanel->update_fields)); |
483
|
|
|
} |
484
|
|
|
|
485
|
|
View Code Duplication |
public function testRemoveFieldsByNameInvalidArray() |
|
|
|
|
486
|
|
|
{ |
487
|
|
|
$this->markTestIncomplete('Not correctly implemented'); |
488
|
|
|
|
489
|
|
|
$this->crudPanel->addFields($this->threeTextFieldsArray); |
490
|
|
|
|
491
|
|
|
// TODO: this should not work because the method specifically asks for an array of field keys, but it does |
492
|
|
|
// because the removeField method will actually work with arrays instead of a string |
493
|
|
|
$this->crudPanel->removeFields($this->twoTextFieldsArray); |
494
|
|
|
|
495
|
|
|
$this->assertEquals(3, count($this->crudPanel->create_fields)); |
496
|
|
|
$this->assertEquals(3, count($this->crudPanel->update_fields)); |
497
|
|
|
$this->assertEquals(array_keys($this->expectedThreeTextFieldsArray), array_keys($this->crudPanel->create_fields)); |
|
|
|
|
498
|
|
|
$this->assertEquals(array_keys($this->expectedThreeTextFieldsArray), array_keys($this->crudPanel->update_fields)); |
|
|
|
|
499
|
|
|
} |
500
|
|
|
|
501
|
|
View Code Duplication |
public function testRemoveFieldsFromCreateForm() |
|
|
|
|
502
|
|
|
{ |
503
|
|
|
$this->crudPanel->addFields($this->threeTextFieldsArray); |
504
|
|
|
|
505
|
|
|
$this->crudPanel->removeFields(['field1'], 'create'); |
506
|
|
|
|
507
|
|
|
$this->assertEquals(2, count($this->crudPanel->create_fields)); |
508
|
|
|
$this->assertEquals(3, count($this->crudPanel->update_fields)); |
509
|
|
|
$this->assertEquals(['field2', 'field3'], array_keys($this->crudPanel->create_fields)); |
510
|
|
|
$this->assertEquals(array_keys($this->expectedThreeTextFieldsArray), array_keys($this->crudPanel->update_fields)); |
|
|
|
|
511
|
|
|
} |
512
|
|
|
|
513
|
|
View Code Duplication |
public function testRemoveFieldsFromUpdateForm() |
|
|
|
|
514
|
|
|
{ |
515
|
|
|
$this->crudPanel->addFields($this->threeTextFieldsArray); |
516
|
|
|
|
517
|
|
|
$this->crudPanel->removeFields(['field1'], 'update'); |
518
|
|
|
|
519
|
|
|
$this->assertEquals(3, count($this->crudPanel->create_fields)); |
520
|
|
|
$this->assertEquals(2, count($this->crudPanel->update_fields)); |
521
|
|
|
$this->assertEquals(array_keys($this->expectedThreeTextFieldsArray), array_keys($this->crudPanel->create_fields)); |
|
|
|
|
522
|
|
|
$this->assertEquals(['field2', 'field3'], array_keys($this->crudPanel->update_fields)); |
523
|
|
|
} |
524
|
|
|
|
525
|
|
View Code Duplication |
public function testRemoveUnknownFields() |
|
|
|
|
526
|
|
|
{ |
527
|
|
|
$this->crudPanel->addFields($this->threeTextFieldsArray); |
528
|
|
|
|
529
|
|
|
$this->crudPanel->removeFields(['field4']); |
530
|
|
|
|
531
|
|
|
$this->assertEquals(3, count($this->crudPanel->create_fields)); |
532
|
|
|
$this->assertEquals(3, count($this->crudPanel->update_fields)); |
533
|
|
|
$this->assertEquals(array_keys($this->expectedThreeTextFieldsArray), array_keys($this->crudPanel->create_fields)); |
|
|
|
|
534
|
|
|
$this->assertEquals(array_keys($this->expectedThreeTextFieldsArray), array_keys($this->crudPanel->update_fields)); |
|
|
|
|
535
|
|
|
} |
536
|
|
|
|
537
|
|
|
public function testCheckIfFieldIsFirstOfItsType() |
538
|
|
|
{ |
539
|
|
|
$isFirstAddressFieldFirst = $this->crudPanel->checkIfFieldIsFirstOfItsType($this->multipleFieldTypesArray[1], $this->expectedMultipleFieldTypesArray); |
|
|
|
|
540
|
|
|
$isSecondAddressFieldFirst = $this->crudPanel->checkIfFieldIsFirstOfItsType($this->multipleFieldTypesArray[2], $this->expectedMultipleFieldTypesArray); |
|
|
|
|
541
|
|
|
|
542
|
|
|
$this->assertTrue($isFirstAddressFieldFirst); |
543
|
|
|
$this->assertFalse($isSecondAddressFieldFirst); |
544
|
|
|
} |
545
|
|
|
|
546
|
|
|
public function testCheckIfUnknownFieldIsFirstOfItsType() |
547
|
|
|
{ |
548
|
|
|
$isUnknownFieldFirst = $this->crudPanel->checkIfFieldIsFirstOfItsType($this->unknownFieldTypeArray, $this->expectedMultipleFieldTypesArray); |
|
|
|
|
549
|
|
|
|
550
|
|
|
$this->assertFalse($isUnknownFieldFirst); |
551
|
|
|
} |
552
|
|
|
|
553
|
|
|
public function testCheckIfInvalidFieldIsFirstOfItsType() |
554
|
|
|
{ |
555
|
|
|
$this->setExpectedException(\ErrorException::class); |
556
|
|
|
|
557
|
|
|
$this->crudPanel->checkIfFieldIsFirstOfItsType($this->invalidTwoFieldsArray[0], $this->expectedMultipleFieldTypesArray); |
|
|
|
|
558
|
|
|
} |
559
|
|
|
|
560
|
|
|
public function testDecodeJsonCastedAttributes() |
561
|
|
|
{ |
562
|
|
|
$this->markTestIncomplete(); |
563
|
|
|
|
564
|
|
|
// TODO: the decode JSON method should not be in fields trait and should not be exposed in the public API. |
565
|
|
|
} |
566
|
|
|
} |
567
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.