Merge pull request #17641 from MegaphoneJon/core-1590
[civicrm-core.git] / tests / phpunit / api / v3 / CustomFieldTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 * Test APIv3 civicrm_create_custom_group
14 *
15 * @package CiviCRM
16 * @group headless
17 */
18 class api_v3_CustomFieldTest extends CiviUnitTestCase {
19
20 /**
21 * Clean up after test.
22 *
23 * @throws \CRM_Core_Exception
24 */
25 public function tearDown() {
26 $this->quickCleanup([
27 'civicrm_contact',
28 'civicrm_file',
29 'civicrm_entity_file',
30 ], TRUE);
31 parent::tearDown();
32 }
33
34 /**
35 * Check with no label.
36 */
37 public function testCustomFieldCreateWithoutLabel() {
38 $customGroup = $this->customGroupCreate(['extends' => 'Individual', 'title' => 'text_test_group']);
39 $params = [
40 'custom_group_id' => $customGroup['id'],
41 'name' => 'test_textfield2',
42 'html_type' => 'Text',
43 'data_type' => 'String',
44 'default_value' => 'abc',
45 'weight' => 4,
46 'is_required' => 1,
47 'is_searchable' => 0,
48 'is_active' => 1,
49 ];
50
51 $customField = $this->callAPIFailure('custom_field', 'create', $params);
52 $this->assertEquals($customField['error_message'], 'Mandatory key(s) missing from params array: label');
53 }
54
55 /**
56 * Check with edit.
57 */
58 public function testCustomFieldCreateWithEdit() {
59 $customGroup = $this->customGroupCreate(['extends' => 'Individual', 'title' => 'text_test_group']);
60 $params = [
61 'custom_group_id' => $customGroup['id'],
62 'name' => 'test_textfield2',
63 'label' => 'Name1',
64 'html_type' => 'Text',
65 'data_type' => 'String',
66 'default_value' => 'abc',
67 'weight' => 4,
68 'is_required' => 1,
69 'is_searchable' => 0,
70 'is_active' => 1,
71 ];
72
73 $customField = $this->callAPIAndDocument('custom_field', 'create', $params, __FUNCTION__, __FILE__);
74 $params['id'] = $customField['id'];
75 $customField = $this->callAPISuccess('custom_field', 'create', $params);
76
77 $this->assertNotNull($customField['id']);
78 }
79
80 /**
81 * Check without groupId.
82 */
83 public function testCustomFieldCreateWithoutGroupID() {
84 $fieldParams = [
85 'name' => 'test_textfield1',
86 'label' => 'Name',
87 'html_type' => 'Text',
88 'data_type' => 'String',
89 'default_value' => 'abc',
90 'weight' => 4,
91 'is_required' => 1,
92 'is_searchable' => 0,
93 'is_active' => 1,
94
95 ];
96
97 $customField = $this->callAPIFailure('custom_field', 'create', $fieldParams);
98 $this->assertEquals($customField['error_message'], 'Mandatory key(s) missing from params array: custom_group_id');
99 }
100
101 /**
102 * Check for Each data type: loop through available form input types
103 */
104 public function testCustomFieldCreateAllAvailableFormInputs() {
105 $gid = $this->customGroupCreate(['extends' => 'Individual', 'title' => 'testAllFormInputs']);
106
107 $dtype = CRM_Core_BAO_CustomField::dataType();
108 $htype = CRM_Custom_Form_Field::$_dataToHTML;
109
110 // Legacy html types returned by v3
111 foreach ($htype as &$item) {
112 if (isset($item['StateProvince'])) {
113 $item['StateProvince'] = 'Select State/Province';
114 }
115 if (isset($item['Country'])) {
116 $item['Country'] = 'Select Country';
117 }
118 }
119
120 $n = 0;
121 foreach ($dtype as $dkey => $dvalue) {
122 foreach ($htype[$n] as $hkey => $hvalue) {
123 //echo $dkey."][".$hvalue."\n";
124 $this->_loopingCustomFieldCreateTest($this->_buildParams($gid['id'], $hvalue, $dkey));
125 }
126 $n++;
127 }
128 }
129
130 /*
131 * Can't figure out the point of this?
132 */
133
134 /**
135 * @param array $params
136 */
137 public function _loopingCustomFieldCreateTest($params) {
138 $customField = $this->callAPISuccess('custom_field', 'create', $params);
139 $this->assertNotNull($customField['id']);
140 $this->getAndCheck($params, $customField['id'], 'CustomField');
141 }
142
143 /**
144 * @param int $gid
145 * @param $htype
146 * @param $dtype
147 *
148 * @return array
149 */
150 public function _buildParams($gid, $htype, $dtype) {
151 $params = $this->_buildBasicParams($gid, $htype, $dtype);
152 /* //Not Working for any type. Maybe redundant with testCustomFieldCreateWithOptionValues()
153 if ($htype == 'Multi-Select')
154 $params = array_merge($params, array(
155 'option_label' => array( 'Label1','Label2'),
156 'option_value' => array( 'val1', 'val2' ),
157 'option_weight' => array( 1, 2),
158 'option_status' => array( 1, 1),
159 ));
160 */
161
162 return $params;
163 }
164
165 /**
166 * @param int $gid
167 * @param $htype
168 * @param $dtype
169 *
170 * @return array
171 */
172 public function _buildBasicParams($gid, $htype, $dtype) {
173 return [
174 'custom_group_id' => $gid,
175 'label' => $dtype . $htype,
176 'html_type' => $htype,
177 'data_type' => $dtype,
178 'weight' => 4,
179 'is_required' => 0,
180 'is_searchable' => 0,
181 'is_active' => 1,
182
183 ];
184 }
185
186 /**
187 * Test using example code.
188 */
189 /*function testCustomFieldCreateExample( )
190 {
191
192 $customGroup = $this->customGroupCreate('Individual','date_test_group',3);
193 require_once 'api/v3/examples/CustomField/Create.ex.php';
194 $result = custom_field_create_example();
195 $expectedResult = custom_field_create_expectedresult();
196 $this->assertEquals($result,$expectedResult);
197 }*/
198
199 /**
200 * Check with data type - Options with option_values
201 */
202 public function testCustomFieldCreateWithEmptyOptionGroup() {
203 $customGroup = $this->customGroupCreate(['extends' => 'Contact', 'title' => 'select_test_group']);
204 $params = [
205 'custom_group_id' => $customGroup['id'],
206 'label' => 'Country',
207 'html_type' => 'Select',
208 'data_type' => 'String',
209 'weight' => 4,
210 'is_required' => 1,
211 'is_searchable' => 0,
212 'is_active' => 1,
213 ];
214
215 $customField = $this->callAPISuccess('custom_field', 'create', $params);
216 $this->assertNotNull($customField['id']);
217 $optionGroupID = $this->callAPISuccess('custom_field', 'getvalue', [
218 'id' => $customField['id'],
219 'return' => 'option_group_id',
220 ]);
221
222 $this->assertTrue(is_numeric($optionGroupID) && ($optionGroupID > 0));
223 $optionGroup = $this->callAPISuccess('option_group', 'getsingle', [
224 'id' => $optionGroupID,
225 ]);
226 $this->assertEquals($optionGroup['title'], 'Country');
227 $optionValueCount = $this->callAPISuccess('option_value', 'getcount', [
228 'option_group_id' => $optionGroupID,
229 ]);
230 $this->assertEquals(0, $optionValueCount);
231 }
232
233 /**
234 * Check with non-ascii labels
235 */
236 public function testCustomFieldCreateWithNonAsciiLabel() {
237 $customGroup = $this->customGroupCreate(['extends' => 'Contact', 'title' => 'select_test_group']);
238 $params = [
239 'custom_group_id' => $customGroup['id'],
240 'label' => 'ôôôô',
241 'html_type' => 'Select',
242 'data_type' => 'String',
243 'weight' => 4,
244 'is_required' => 1,
245 'is_searchable' => 0,
246 'is_active' => 1,
247 ];
248 $customField = $this->callAPISuccess('custom_field', 'create', $params);
249 $this->assertNotNull($customField['id']);
250 $params['label'] = 'ààà';
251 $customField = $this->callAPISuccess('custom_field', 'create', $params);
252 $this->assertNotNull($customField['id']);
253 }
254
255 /**
256 * Test custom field with existing option group.
257 */
258 public function testCustomFieldExistingOptionGroup() {
259 $customGroup = $this->customGroupCreate(['extends' => 'Organization', 'title' => 'test_group']);
260 $params = [
261 'custom_group_id' => $customGroup['id'],
262 // Just to say something:
263 'label' => 'Organization Gender',
264 'html_type' => 'Select',
265 'data_type' => 'Int',
266 'weight' => 4,
267 'is_required' => 1,
268 'is_searchable' => 0,
269 'is_active' => 1,
270 // Option group id 3: gender
271 'option_group_id' => 3,
272 ];
273
274 $customField = $this->callAPISuccess('custom_field', 'create', $params);
275 $this->assertNotNull($customField['id']);
276 $optionGroupID = $this->callAPISuccess('custom_field', 'getvalue', [
277 'id' => $customField['id'],
278 'return' => 'option_group_id',
279 ]);
280
281 $this->assertEquals($optionGroupID, 3);
282 }
283
284 /**
285 * Test adding an optionGroup to an existing field doesn't cause a fatal error.
286 *
287 * (this was happening due to a check running despite no existing option_group_id)
288 *
289 * @throws \CiviCRM_API3_Exception
290 */
291 public function testUpdateCustomFieldAddOptionGroup() {
292 $customGroup = $this->customGroupCreate(['extends' => 'Organization', 'title' => 'test_group']);
293 $params = [
294 'custom_group_id' => $customGroup['id'],
295 'label' => 'Organization Gender',
296 'html_type' => 'Text',
297 'data_type' => 'Int',
298 ];
299
300 $customField = $this->callAPISuccess('custom_field', 'create', $params);
301 $this->callAPISuccess('CustomField', 'create', [
302 'option_group_id' => civicrm_api3('OptionGroup', 'getvalue', ['options' => ['limit' => 1], 'return' => 'id']),
303 'id' => $customField['id'],
304 'html_type' => 'Select',
305 ]);
306 }
307
308 /**
309 * Test custom field get works & return param works
310 */
311 public function testCustomFieldGetReturnOptions() {
312 $customGroup = $this->customGroupCreate(['extends' => 'Individual', 'title' => 'test_group']);
313 $customField = $this->customFieldCreate(['custom_group_id' => $customGroup['id']]);
314
315 $result = $this->callAPISuccess('custom_field', 'getsingle', [
316 'id' => $customField['id'],
317 'return' => 'data_type',
318 ]);
319 $this->assertTrue(array_key_exists('data_type', $result));
320 $this->assertFalse(array_key_exists('custom_group_id', $result));
321 }
322
323 /**
324 * Test custom field get works & return param works
325 */
326 public function testCustomFieldGetReturnArray() {
327 $customGroup = $this->customGroupCreate(['extends' => 'Individual', 'title' => 'test_group']);
328 $customField = $this->customFieldCreate(['custom_group_id' => $customGroup['id']]);
329
330 $result = $this->callAPISuccess('custom_field', 'getsingle', [
331 'id' => $customField['id'],
332 'return' => ['data_type'],
333 ]);
334 $this->assertTrue(array_key_exists('data_type', $result));
335 $this->assertFalse(array_key_exists('custom_group_id', $result));
336 }
337
338 /**
339 * Test custom field get works & return param works
340 */
341 public function testCustomFieldGetReturnTwoOptions() {
342 $customGroup = $this->customGroupCreate(['extends' => 'Individual', 'test_group']);
343 $customField = $this->customFieldCreate(['custom_group_id' => $customGroup['id']]);
344
345 $result = $this->callAPISuccess('custom_field', 'getsingle', [
346 'id' => $customField['id'],
347 'return' => 'data_type, custom_group_id',
348 ]);
349 $this->assertTrue(array_key_exists('data_type', $result));
350 $this->assertTrue(array_key_exists('custom_group_id', $result));
351 $this->assertFalse(array_key_exists('label', $result));
352 }
353
354 public function testCustomFieldCreateWithOptionValues() {
355 $customGroup = $this->customGroupCreate(['extends' => 'Contact', 'title' => 'select_test_group']);
356
357 $option_values = [
358 [
359 'weight' => 1,
360 'label' => 'Label1',
361 'value' => 1,
362 'is_active' => 1,
363 ],
364 [
365 'weight' => 2,
366 'label' => 'Label2',
367 'value' => 2,
368 'is_active' => 1,
369 ],
370 ];
371
372 $params = [
373 'custom_group_id' => $customGroup['id'],
374 'label' => 'Our special field',
375 'html_type' => 'Select',
376 'data_type' => 'String',
377 'weight' => 4,
378 'is_required' => 1,
379 'is_searchable' => 0,
380 'is_active' => 1,
381 'option_values' => $option_values,
382
383 ];
384
385 $customField = $this->callAPISuccess('custom_field', 'create', $params);
386
387 $this->assertAPISuccess($customField);
388 $this->assertNotNull($customField['id']);
389 $getFieldsParams = [
390 'options' => ['get_options' => 'custom_' . $customField['id']],
391 'action' => 'create',
392 ];
393 $description = "Demonstrates retrieving metadata with custom field options.";
394 $subfile = "GetFieldsOptions";
395 $fields = $this->callAPIAndDocument('contact', 'getfields', $getFieldsParams, __FUNCTION__, 'ContactTest.php', $description, $subfile);
396 $this->assertArrayHasKey('options', $fields['values']['custom_' . $customField['id']]);
397 $this->assertEquals('Label1', $fields['values']['custom_' . $customField['id']]['options'][1]);
398 $getOptionsArray = [
399 'field' => 'custom_' . $customField['id'],
400 ];
401 $description = "Demonstrates retrieving options for a custom field.";
402 $subfile = "GetOptions";
403 $result = $this->callAPIAndDocument('contact', 'getoptions', $getOptionsArray, __FUNCTION__, 'ContactTest.php', $description, '');
404 $this->assertEquals('Label1', $result['values'][1]);
405 }
406
407 ///////////////// civicrm_custom_field_delete methods
408
409 /**
410 * Check without Field ID.
411 */
412 public function testCustomFieldDeleteWithoutFieldID() {
413 $params = [];
414 $customField = $this->callAPIFailure('custom_field', 'delete', $params,
415 'Mandatory key(s) missing from params array: id');
416 }
417
418 /**
419 * Check without valid array.
420 */
421 public function testCustomFieldDelete() {
422 $customGroup = $this->customGroupCreate(['extends' => 'Individual', 'title' => 'test_group']);
423 $customField = $this->customFieldCreate(['custom_group_id' => $customGroup['id']]);
424 $this->assertNotNull($customField['id']);
425
426 $params = [
427 'id' => $customField['id'],
428 ];
429 $result = $this->callAPIAndDocument('custom_field', 'delete', $params, __FUNCTION__, __FILE__);
430
431 $this->assertAPISuccess($result);
432 }
433
434 /**
435 * Check for Option Value.
436 */
437 public function testCustomFieldOptionValueDelete() {
438 $customGroup = $this->customGroupCreate(['extends' => 'Contact', 'title' => 'ABC']);
439 $customOptionValueFields = $this->customFieldOptionValueCreate($customGroup, 'fieldABC');
440 $params = [
441 'id' => $customOptionValueFields,
442 ];
443
444 $customField = $this->callAPISuccess('custom_field', 'delete', $customOptionValueFields);
445 }
446
447 /**
448 * If there's one custom group for "Contact" and one for "Activity", then "Contact.getfields"
449 * and "Activity.getfields" should return only their respective fields (not the other's fields),
450 * and unrelated entities should return no custom fields.
451 */
452 public function testGetfields_CrossEntityPollution() {
453 $auxEntities = ['Email', 'Address', 'LocBlock', 'Membership', 'ContributionPage', 'ReportInstance'];
454 $allEntities = array_merge(['Contact', 'Activity'], $auxEntities);
455
456 // Baseline - getfields doesn't reporting any customfields for any entities
457 foreach ($allEntities as $entity) {
458 $this->assertEquals(
459 [],
460 $this->getCustomFieldKeys($this->callAPISuccess($entity, 'getfields', [])),
461 "Baseline custom fields for $entity should be empty"
462 );
463 }
464
465 // Add some fields
466 $contactGroup = $this->customGroupCreate(['extends' => 'Contact', 'title' => 'test_group_c']);
467 $contactField = $this->customFieldCreate([
468 'custom_group_id' => $contactGroup['id'],
469 'label' => 'For Contacts',
470 ]);
471 $indivGroup = $this->customGroupCreate(['extends' => 'Individual', 'title' => 'test_group_i']);
472 $indivField = $this->customFieldCreate(['custom_group_id' => $indivGroup['id'], 'label' => 'For Individuals']);
473 $activityGroup = $this->customGroupCreate(['extends' => 'Activity', 'title' => 'test_group_a']);
474 $activityField = $this->customFieldCreate([
475 'custom_group_id' => $activityGroup['id'],
476 'label' => 'For Activities',
477 ]);
478
479 // Check getfields
480 $this->assertEquals(
481 ['custom_' . $contactField['id'], 'custom_' . $indivField['id']],
482 $this->getCustomFieldKeys($this->callAPISuccess('Contact', 'getfields', [])),
483 'Contact custom fields'
484 );
485 $this->assertEquals(
486 ['custom_' . $contactField['id'], 'custom_' . $indivField['id']],
487 $this->getCustomFieldKeys($this->callAPISuccess('Individual', 'getfields', [])),
488 'Individual custom fields'
489 );
490 $this->assertEquals(
491 ['custom_' . $contactField['id']],
492 $this->getCustomFieldKeys($this->callAPISuccess('Organization', 'getfields', [])),
493 'Organization custom fields'
494 );
495 $this->assertEquals(
496 ['custom_' . $activityField['id']],
497 $this->getCustomFieldKeys($this->callAPISuccess('Activity', 'getfields', [])),
498 'Activity custom fields'
499 );
500 foreach ($auxEntities as $entity) {
501 $this->assertEquals(
502 [],
503 $this->getCustomFieldKeys($this->callAPISuccess($entity, 'getfields', [])),
504 "Custom fields for $entity should be empty"
505 );
506 }
507 }
508
509 /**
510 * Test setting and getting a custom file field value.
511 *
512 * Uses the "attachment" api for setting value.
513 */
514 public function testCustomFileField() {
515 $customGroup = $this->customGroupCreate(['title' => 'attachment_test_group']);
516 $params = [
517 'custom_group_id' => $customGroup['id'],
518 'name' => 'test_file_attachment',
519 'label' => 'test_file_attachment',
520 'html_type' => 'File',
521 'data_type' => 'File',
522 'is_active' => 1,
523 ];
524 $customField = $this->callAPISuccess('custom_field', 'create', $params);
525 $cfId = 'custom_' . $customField['id'];
526
527 $cid = $this->individualCreate();
528
529 $attachment = $this->callAPISuccess('attachment', 'create', [
530 'name' => CRM_Utils_String::createRandom(5, CRM_Utils_String::ALPHANUMERIC) . '_testCustomFileField.txt',
531 'mime_type' => 'text/plain',
532 'content' => 'My test content',
533 'field_name' => $cfId,
534 'entity_id' => $cid,
535 ]);
536 $this->assertAttachmentExistence(TRUE, $attachment);
537
538 $result = $this->callAPISuccess('contact', 'getsingle', [
539 'id' => $cid,
540 'return' => $cfId,
541 ]);
542
543 $this->assertEquals($attachment['id'], $result[$cfId]);
544 }
545
546 public function testUpdateCustomField() {
547 $customGroup = $this->customGroupCreate(['extends' => 'Individual']);
548 $params = ['id' => $customGroup['id'], 'is_active' => 0];
549 $result = $this->callAPISuccess('CustomGroup', 'create', $params);
550 $result = array_shift($result['values']);
551
552 $this->assertEquals(0, $result['is_active']);
553
554 $this->customGroupDelete($customGroup['id']);
555 }
556
557 public function testCustomFieldCreateWithOptionGroupName() {
558 $customGroup = $this->customGroupCreate(['extends' => 'Individual', 'title' => 'test_custom_group']);
559 $params = [
560 'custom_group_id' => $customGroup['id'],
561 'name' => 'Activity type',
562 'label' => 'Activity type',
563 'data_type' => 'String',
564 'html_type' => 'Select',
565 'option_group_id' => 'activity_type',
566 ];
567 $result = $this->callAPISuccess('CustomField', 'create', $params);
568 }
569
570 /**
571 * @param $getFieldsResult
572 *
573 * @return array
574 */
575 public function getCustomFieldKeys($getFieldsResult) {
576 $isCustom = function ($key) {
577 return preg_match('/^custom_/', $key);
578 };
579 $r = array_values(array_filter(array_keys($getFieldsResult['values']), $isCustom));
580 sort($r);
581 return $r;
582 }
583
584 public function testMakeSearchableContactReferenceFieldUnsearchable() {
585 $customGroup = $this->customGroupCreate([
586 'name' => 'testCustomGroup',
587 'title' => 'testCustomGroup',
588 'extends' => 'Individual',
589 ]);
590 $params = [
591 'name' => 'testCustomField',
592 'label' => 'testCustomField',
593 'custom_group_id' => 'testCustomGroup',
594 'data_type' => 'ContactReference',
595 'html_type' => 'Autocomplete-Select',
596 'is_searchable' => '1',
597 ];
598 $result = $this->callAPISuccess('CustomField', 'create', $params);
599 $params = [
600 'id' => $result['id'],
601 'is_searchable' => 0,
602 ];
603 $result = $this->callAPISuccess('CustomField', 'create', $params);
604 }
605
606 /**
607 * Test disabling a searchable contact reference field.
608 */
609 public function testDisableSearchableContactReferenceField() {
610 $customGroup = $this->customGroupCreate([
611 'name' => 'testCustomGroup',
612 'title' => 'testCustomGroup',
613 'extends' => 'Individual',
614 ]);
615 $params = [
616 'name' => 'testCustomField',
617 'label' => 'testCustomField',
618 'custom_group_id' => 'testCustomGroup',
619 'data_type' => 'ContactReference',
620 'html_type' => 'Autocomplete-Select',
621 'is_searchable' => '1',
622 ];
623 $result = $this->callAPISuccess('CustomField', 'create', $params);
624 $params = [
625 'id' => $result['id'],
626 'is_active' => 0,
627 ];
628 $this->callAPISuccess('CustomField', 'create', $params);
629 }
630
631 public function testLegacyHtmlType() {
632 $customGroup = $this->customGroupCreate([
633 'name' => 'testCustomGroup',
634 'title' => 'testCustomGroup',
635 'extends' => 'Individual',
636 ]);
637 $f1 = $this->callAPISuccess('CustomField', 'create', [
638 'label' => 'SingleSelect',
639 'custom_group_id' => 'testCustomGroup',
640 'data_type' => 'String',
641 'html_type' => 'Select',
642 'option_values' => [1 => 'One', 2 => 'Two'],
643 ]);
644 $f2 = $this->callAPISuccess('CustomField', 'create', [
645 'label' => 'CheckBoxes',
646 'custom_group_id' => 'testCustomGroup',
647 'data_type' => 'String',
648 'html_type' => 'CheckBox',
649 'option_values' => [1 => 'One', 2 => 'Two'],
650 ]);
651 $f3 = $this->callAPISuccess('CustomField', 'create', [
652 'label' => 'MultiSelect',
653 'custom_group_id' => 'testCustomGroup',
654 'data_type' => 'String',
655 'html_type' => 'Multi-Select',
656 'option_values' => [1 => 'One', 2 => 'Two'],
657 ]);
658
659 $result = $this->callAPISuccess('CustomField', 'get', [
660 'custom_group_id' => 'testCustomGroup',
661 'html_type' => 'Multi-Select',
662 'sequential' => 1,
663 ]);
664 $this->assertCount(1, $result['values']);
665 $this->assertEquals('MultiSelect', $result['values'][0]['label']);
666
667 $result = $this->callAPISuccess('CustomField', 'get', [
668 'custom_group_id' => 'testCustomGroup',
669 'html_type' => ['IN' => ['Multi-Select', 'CheckBox']],
670 'sequential' => 1,
671 ]);
672 $this->assertCount(2, $result['values']);
673
674 $result = $this->callAPISuccess('CustomField', 'get', [
675 'custom_group_id' => 'testCustomGroup',
676 'html_type' => 'Select',
677 'sequential' => 1,
678 ]);
679 $this->assertCount(1, $result['values']);
680 $this->assertEquals('SingleSelect', $result['values'][0]['label']);
681
682 $result = $this->callAPISuccess('CustomField', 'get', [
683 'custom_group_id' => 'testCustomGroup',
684 'html_type' => ['IN' => ['Select']],
685 'sequential' => 1,
686 ]);
687 $this->assertCount(1, $result['values']);
688 $this->assertEquals('SingleSelect', $result['values'][0]['label']);
689 }
690
691 public function testLegacyStateCountryTypes() {
692 $customGroup = $this->customGroupCreate([
693 'name' => 'testCustomGroup',
694 'title' => 'testCustomGroup',
695 'extends' => 'Individual',
696 ]);
697 $f1 = $this->callAPISuccess('CustomField', 'create', [
698 'label' => 'CountrySelect',
699 'custom_group_id' => 'testCustomGroup',
700 'data_type' => 'Country',
701 'html_type' => 'Select Country',
702 ]);
703 $f2 = $this->callAPISuccess('CustomField', 'create', [
704 'label' => 'StateSelect',
705 'custom_group_id' => 'testCustomGroup',
706 'data_type' => 'StateProvince',
707 'html_type' => 'Select State/Province',
708 ]);
709 $f3 = $this->callAPISuccess('CustomField', 'create', [
710 'label' => 'MultiSelectSP',
711 'custom_group_id' => 'testCustomGroup',
712 'data_type' => 'StateProvince',
713 'html_type' => 'Multi-Select State/Province',
714 ]);
715 $f4 = $this->callAPISuccess('CustomField', 'create', [
716 'label' => 'MultiSelectCountry',
717 'custom_group_id' => 'testCustomGroup',
718 'data_type' => 'Country',
719 'html_type' => 'Select Country',
720 'serialize' => 1,
721 ]);
722
723 $result = $this->callAPISuccess('CustomField', 'get', [
724 'custom_group_id' => 'testCustomGroup',
725 'html_type' => 'Multi-Select State/Province',
726 'sequential' => 1,
727 ]);
728 $this->assertCount(1, $result['values']);
729 $this->assertEquals('MultiSelectSP', $result['values'][0]['label']);
730 $this->assertEquals('Multi-Select State/Province', $result['values'][0]['html_type']);
731 $this->assertEquals('1', $result['values'][0]['serialize']);
732
733 $result = $this->callAPISuccess('CustomField', 'get', [
734 'custom_group_id' => 'testCustomGroup',
735 'html_type' => 'Multi-Select Country',
736 'sequential' => 1,
737 ]);
738 $this->assertCount(1, $result['values']);
739 $this->assertEquals('MultiSelectCountry', $result['values'][0]['label']);
740 $this->assertEquals('Multi-Select Country', $result['values'][0]['html_type']);
741 $this->assertEquals('1', $result['values'][0]['serialize']);
742
743 $result = $this->callAPISuccess('CustomField', 'get', [
744 'custom_group_id' => 'testCustomGroup',
745 'html_type' => 'Select Country',
746 'sequential' => 1,
747 ]);
748 $this->assertCount(1, $result['values']);
749 $this->assertEquals('CountrySelect', $result['values'][0]['label']);
750 $this->assertEquals('Select Country', $result['values'][0]['html_type']);
751 $this->assertEquals('0', $result['values'][0]['serialize']);
752
753 $result = $this->callAPISuccess('CustomField', 'get', [
754 'custom_group_id' => 'testCustomGroup',
755 'html_type' => 'Select State/Province',
756 'sequential' => 1,
757 ]);
758 $this->assertCount(1, $result['values']);
759 $this->assertEquals('StateSelect', $result['values'][0]['label']);
760 $this->assertEquals('Select State/Province', $result['values'][0]['html_type']);
761 $this->assertEquals('0', $result['values'][0]['serialize']);
762 }
763
764 }