7b07ea77 |
1 | <?php |
2 | |
3 | /** |
4 | * Class CRM_Custom_Form_FieldTest |
5 | * @group headless |
6 | */ |
7 | class CRM_Custom_Form_FieldTest extends CiviUnitTestCase { |
8 | |
faba1457 |
9 | public function setUp(): void { |
7b07ea77 |
10 | parent::setUp(); |
11 | } |
12 | |
13 | /** |
14 | * Test the serialize type is determined properly based on form input. |
15 | * |
16 | * @dataProvider serializeDataProvider |
17 | * |
18 | * @param array $input |
19 | * @param int|string $expected |
20 | */ |
21 | public function testDetermineSerializeType(array $input, $expected) { |
22 | $form = new CRM_Custom_Form_Field(); |
23 | $this->assertSame($expected, $form->determineSerializeType($input)); |
24 | } |
25 | |
26 | /** |
27 | * DataProvider for testDetermineSerializeType |
28 | * @return array |
29 | */ |
30 | public function serializeDataProvider():array { |
31 | return [ |
32 | 0 => [ |
33 | [ |
34 | 'data_type' => 'String', |
35 | 'html_type' => 'Text', |
36 | ], |
0b73427c |
37 | 0, |
7b07ea77 |
38 | ], |
39 | 1 => [ |
40 | [ |
41 | 'data_type' => 'String', |
42 | 'html_type' => 'Select', |
43 | ], |
0b73427c |
44 | 0, |
7b07ea77 |
45 | ], |
46 | 2 => [ |
47 | [ |
48 | 'data_type' => 'String', |
49 | 'html_type' => 'Radio', |
50 | ], |
0b73427c |
51 | 0, |
7b07ea77 |
52 | ], |
53 | 3 => [ |
54 | [ |
55 | 'data_type' => 'String', |
56 | 'html_type' => 'CheckBox', |
57 | ], |
58 | CRM_Core_DAO::SERIALIZE_SEPARATOR_BOOKEND, |
59 | ], |
60 | 4 => [ |
61 | [ |
62 | 'data_type' => 'String', |
63 | 'html_type' => 'Autocomplete-Select', |
64 | ], |
0b73427c |
65 | 0, |
7b07ea77 |
66 | ], |
67 | 5 => [ |
68 | [ |
69 | 'data_type' => 'String', |
70 | 'html_type' => 'Text', |
71 | 'serialize' => '1', |
72 | ], |
0b73427c |
73 | 0, |
7b07ea77 |
74 | ], |
75 | 6 => [ |
76 | [ |
77 | 'data_type' => 'String', |
78 | 'html_type' => 'Select', |
79 | 'serialize' => '1', |
80 | ], |
81 | CRM_Core_DAO::SERIALIZE_SEPARATOR_BOOKEND, |
82 | ], |
83 | 7 => [ |
84 | [ |
85 | 'data_type' => 'String', |
86 | 'html_type' => 'Radio', |
87 | 'serialize' => '1', |
88 | ], |
0b73427c |
89 | 0, |
7b07ea77 |
90 | ], |
91 | 8 => [ |
92 | [ |
93 | 'data_type' => 'String', |
94 | 'html_type' => 'CheckBox', |
95 | 'serialize' => '1', |
96 | ], |
97 | CRM_Core_DAO::SERIALIZE_SEPARATOR_BOOKEND, |
98 | ], |
99 | 9 => [ |
100 | [ |
101 | 'data_type' => 'String', |
102 | 'html_type' => 'Autocomplete-Select', |
103 | 'serialize' => '1', |
104 | ], |
105 | CRM_Core_DAO::SERIALIZE_SEPARATOR_BOOKEND, |
106 | ], |
107 | 10 => [ |
108 | [ |
109 | 'data_type' => 'Int', |
110 | 'html_type' => 'Text', |
111 | ], |
0b73427c |
112 | 0, |
7b07ea77 |
113 | ], |
114 | 11 => [ |
115 | [ |
116 | 'data_type' => 'Int', |
117 | 'html_type' => 'Select', |
118 | ], |
0b73427c |
119 | 0, |
7b07ea77 |
120 | ], |
121 | 12 => [ |
122 | [ |
123 | 'data_type' => 'Int', |
124 | 'html_type' => 'Radio', |
125 | ], |
0b73427c |
126 | 0, |
7b07ea77 |
127 | ], |
128 | 13 => [ |
129 | [ |
130 | 'data_type' => 'Int', |
131 | 'html_type' => 'Text', |
132 | 'serialize' => '1', |
133 | ], |
0b73427c |
134 | 0, |
7b07ea77 |
135 | ], |
136 | 14 => [ |
137 | [ |
138 | 'data_type' => 'Int', |
139 | 'html_type' => 'Select', |
140 | 'serialize' => '1', |
141 | ], |
142 | CRM_Core_DAO::SERIALIZE_SEPARATOR_BOOKEND, |
143 | ], |
144 | 15 => [ |
145 | [ |
146 | 'data_type' => 'Int', |
147 | 'html_type' => 'Radio', |
148 | 'serialize' => '1', |
149 | ], |
0b73427c |
150 | 0, |
7b07ea77 |
151 | ], |
152 | 16 => [ |
153 | [ |
154 | 'data_type' => 'Float', |
155 | 'html_type' => 'Text', |
156 | ], |
0b73427c |
157 | 0, |
7b07ea77 |
158 | ], |
159 | 17 => [ |
160 | [ |
161 | 'data_type' => 'Float', |
162 | 'html_type' => 'Select', |
163 | ], |
0b73427c |
164 | 0, |
7b07ea77 |
165 | ], |
166 | 18 => [ |
167 | [ |
168 | 'data_type' => 'Float', |
169 | 'html_type' => 'Radio', |
170 | ], |
0b73427c |
171 | 0, |
7b07ea77 |
172 | ], |
173 | 19 => [ |
174 | [ |
175 | 'data_type' => 'Float', |
176 | 'html_type' => 'Text', |
177 | 'serialize' => '1', |
178 | ], |
0b73427c |
179 | 0, |
7b07ea77 |
180 | ], |
181 | 20 => [ |
182 | [ |
183 | 'data_type' => 'Float', |
184 | 'html_type' => 'Select', |
185 | 'serialize' => '1', |
186 | ], |
187 | CRM_Core_DAO::SERIALIZE_SEPARATOR_BOOKEND, |
188 | ], |
189 | 21 => [ |
190 | [ |
191 | 'data_type' => 'Float', |
192 | 'html_type' => 'Radio', |
193 | 'serialize' => '1', |
194 | ], |
0b73427c |
195 | 0, |
7b07ea77 |
196 | ], |
197 | 22 => [ |
198 | [ |
199 | 'data_type' => 'Money', |
200 | 'html_type' => 'Text', |
201 | ], |
0b73427c |
202 | 0, |
7b07ea77 |
203 | ], |
204 | 23 => [ |
205 | [ |
206 | 'data_type' => 'Money', |
207 | 'html_type' => 'Select', |
208 | ], |
0b73427c |
209 | 0, |
7b07ea77 |
210 | ], |
211 | 24 => [ |
212 | [ |
213 | 'data_type' => 'Money', |
214 | 'html_type' => 'Radio', |
215 | ], |
0b73427c |
216 | 0, |
7b07ea77 |
217 | ], |
218 | 25 => [ |
219 | [ |
220 | 'data_type' => 'Money', |
221 | 'html_type' => 'Text', |
222 | 'serialize' => '1', |
223 | ], |
0b73427c |
224 | 0, |
7b07ea77 |
225 | ], |
226 | 26 => [ |
227 | [ |
228 | 'data_type' => 'Money', |
229 | 'html_type' => 'Select', |
230 | 'serialize' => '1', |
231 | ], |
232 | CRM_Core_DAO::SERIALIZE_SEPARATOR_BOOKEND, |
233 | ], |
234 | 27 => [ |
235 | [ |
236 | 'data_type' => 'Money', |
237 | 'html_type' => 'Radio', |
238 | 'serialize' => '1', |
239 | ], |
0b73427c |
240 | 0, |
7b07ea77 |
241 | ], |
242 | 28 => [ |
243 | [ |
244 | 'data_type' => 'Memo', |
245 | 'html_type' => 'TextArea', |
246 | ], |
0b73427c |
247 | 0, |
7b07ea77 |
248 | ], |
249 | 29 => [ |
250 | [ |
251 | 'data_type' => 'Memo', |
252 | 'html_type' => 'RichTextEditor', |
253 | ], |
0b73427c |
254 | 0, |
7b07ea77 |
255 | ], |
256 | 30 => [ |
257 | [ |
258 | 'data_type' => 'Memo', |
259 | 'html_type' => 'TextArea', |
260 | 'serialize' => '1', |
261 | ], |
0b73427c |
262 | 0, |
7b07ea77 |
263 | ], |
264 | 31 => [ |
265 | [ |
266 | 'data_type' => 'Memo', |
267 | 'html_type' => 'RichTextEditor', |
268 | 'serialize' => '1', |
269 | ], |
0b73427c |
270 | 0, |
7b07ea77 |
271 | ], |
272 | 32 => [ |
273 | [ |
274 | 'data_type' => 'Date', |
275 | 'html_type' => 'Select Date', |
276 | ], |
0b73427c |
277 | 0, |
7b07ea77 |
278 | ], |
279 | 33 => [ |
280 | [ |
281 | 'data_type' => 'Date', |
282 | 'html_type' => 'Select Date', |
283 | 'serialize' => '1', |
284 | ], |
0b73427c |
285 | 0, |
7b07ea77 |
286 | ], |
287 | 34 => [ |
288 | [ |
289 | 'data_type' => 'Boolean', |
290 | 'html_type' => 'Radio', |
291 | ], |
0b73427c |
292 | 0, |
7b07ea77 |
293 | ], |
294 | 35 => [ |
295 | [ |
296 | 'data_type' => 'Boolean', |
297 | 'html_type' => 'Radio', |
298 | 'serialize' => '1', |
299 | ], |
0b73427c |
300 | 0, |
7b07ea77 |
301 | ], |
302 | 36 => [ |
303 | [ |
304 | 'data_type' => 'StateProvince', |
305 | 'html_type' => 'Select', |
306 | ], |
0b73427c |
307 | 0, |
7b07ea77 |
308 | ], |
309 | 37 => [ |
310 | [ |
311 | 'data_type' => 'StateProvince', |
312 | 'html_type' => 'Select', |
313 | 'serialize' => '1', |
314 | ], |
315 | CRM_Core_DAO::SERIALIZE_SEPARATOR_BOOKEND, |
316 | ], |
317 | 38 => [ |
318 | [ |
319 | 'data_type' => 'Country', |
320 | 'html_type' => 'Select', |
321 | ], |
0b73427c |
322 | 0, |
7b07ea77 |
323 | ], |
324 | 39 => [ |
325 | [ |
326 | 'data_type' => 'Country', |
327 | 'html_type' => 'Select', |
328 | 'serialize' => '1', |
329 | ], |
330 | CRM_Core_DAO::SERIALIZE_SEPARATOR_BOOKEND, |
331 | ], |
332 | 40 => [ |
333 | [ |
334 | 'data_type' => 'File', |
335 | 'html_type' => 'File', |
336 | ], |
0b73427c |
337 | 0, |
7b07ea77 |
338 | ], |
339 | 41 => [ |
340 | [ |
341 | 'data_type' => 'File', |
342 | 'html_type' => 'File', |
343 | 'serialize' => '1', |
344 | ], |
0b73427c |
345 | 0, |
7b07ea77 |
346 | ], |
347 | 42 => [ |
348 | [ |
349 | 'data_type' => 'Link', |
350 | 'html_type' => 'Link', |
351 | ], |
0b73427c |
352 | 0, |
7b07ea77 |
353 | ], |
354 | 43 => [ |
355 | [ |
356 | 'data_type' => 'Link', |
357 | 'html_type' => 'Link', |
358 | 'serialize' => '1', |
359 | ], |
0b73427c |
360 | 0, |
7b07ea77 |
361 | ], |
362 | 44 => [ |
363 | [ |
364 | 'data_type' => 'ContactReference', |
365 | 'html_type' => 'Autocomplete-Select', |
366 | ], |
0b73427c |
367 | 0, |
7b07ea77 |
368 | ], |
369 | 45 => [ |
370 | [ |
371 | 'data_type' => 'ContactReference', |
372 | 'html_type' => 'Autocomplete-Select', |
373 | 'serialize' => '1', |
374 | ], |
a61d2ab7 |
375 | CRM_Core_DAO::SERIALIZE_SEPARATOR_BOOKEND, |
7b07ea77 |
376 | ], |
377 | ]; |
378 | } |
379 | |
380 | } |