Handle new flattened custom field return format
[civicrm-core.git] / Civi / Test / Api3TestTrait.php
CommitLineData
30f5345c
TO
1<?php
2
3namespace Civi\Test;
4
62950ef9
CW
5use Civi\API\Exception\NotImplementedException;
6
30f5345c
TO
7/**
8 * Class Api3TestTrait
9 * @package Civi\Test
10 *
11 * This trait defines a number of helper functions for testing APIv3. Commonly
12 * used helpers include `callAPISuccess()`, `callAPIFailure()`,
13 * `assertAPISuccess()`, and `assertAPIFailure()`.
14 *
15 * This trait is intended for use with PHPUnit-based test cases.
16 */
17trait Api3TestTrait {
18
62950ef9
CW
19 /**
20 * Get the api versions to test.
21 *
22 * @return array
23 */
24 public function versionThreeAndFour() {
25 return [[3], [4]];
26 }
27
30f5345c
TO
28 /**
29 * Api version - easier to override than just a define
34f3bbd9 30 * @var int
30f5345c
TO
31 */
32 protected $_apiversion = 3;
33
34 /**
35 * Check that api returned 'is_error' => 1
36 * else provide full message
37 * @param array $result
38 * @param $expected
39 * @param array $valuesToExclude
40 * @param string $prefix
41 * Extra test to add to message.
42 */
c64f69d9
CW
43 public function assertAPIArrayComparison($result, $expected, $valuesToExclude = [], $prefix = '') {
44 $valuesToExclude = array_merge($valuesToExclude, ['debug', 'xdebug', 'sequential']);
30f5345c
TO
45 foreach ($valuesToExclude as $value) {
46 if (isset($result[$value])) {
47 unset($result[$value]);
48 }
49 if (isset($expected[$value])) {
50 unset($expected[$value]);
51 }
52 }
53 $this->assertEquals($result, $expected, "api result array comparison failed " . $prefix . print_r($result, TRUE) . ' was compared to ' . print_r($expected, TRUE));
54 }
55
56 /**
57 * Check that a deleted item has been deleted.
58 *
59 * @param $entity
60 * @param $id
61 */
62 public function assertAPIDeleted($entity, $id) {
c64f69d9 63 $this->callAPISuccess($entity, 'getcount', ['id' => $id], 0);
30f5345c
TO
64 }
65
66 /**
67 * Check that api returned 'is_error' => 1.
68 *
69 * @param array $apiResult
70 * Api result.
71 * @param string $prefix
72 * Extra test to add to message.
73 * @param null $expectedError
74 */
75 public function assertAPIFailure($apiResult, $prefix = '', $expectedError = NULL) {
76 if (!empty($prefix)) {
77 $prefix .= ': ';
78 }
79 if ($expectedError && !empty($apiResult['is_error'])) {
62950ef9 80 $this->assertContains($expectedError, $apiResult['error_message'], 'api error message not as expected' . $prefix);
30f5345c
TO
81 }
82 $this->assertEquals(1, $apiResult['is_error'], "api call should have failed but it succeeded " . $prefix . (print_r($apiResult, TRUE)));
83 $this->assertNotEmpty($apiResult['error_message']);
84 }
85
86 /**
87 * Check that api returned 'is_error' => 0.
88 *
89 * @param array $apiResult
90 * Api result.
91 * @param string $prefix
92 * Extra test to add to message.
93 */
94 public function assertAPISuccess($apiResult, $prefix = '') {
95 if (!empty($prefix)) {
96 $prefix .= ': ';
97 }
98 $errorMessage = empty($apiResult['error_message']) ? '' : " " . $apiResult['error_message'];
99
100 if (!empty($apiResult['debug_information'])) {
101 $errorMessage .= "\n " . print_r($apiResult['debug_information'], TRUE);
102 }
103 if (!empty($apiResult['trace'])) {
104 $errorMessage .= "\n" . print_r($apiResult['trace'], TRUE);
105 }
62950ef9 106 $this->assertEmpty(\CRM_Utils_Array::value('is_error', $apiResult), $prefix . $errorMessage);
30f5345c
TO
107 }
108
109 /**
110 * This function exists to wrap api functions.
111 * so we can ensure they fail where expected & throw exceptions without litterering the test with checks
112 * @param string $entity
113 * @param string $action
114 * @param array $params
115 * @param string $expectedErrorMessage
116 * Error.
117 * @param null $extraOutput
118 * @return array|int
119 */
120 public function callAPIFailure($entity, $action, $params, $expectedErrorMessage = NULL, $extraOutput = NULL) {
121 if (is_array($params)) {
c64f69d9 122 $params += [
30f5345c 123 'version' => $this->_apiversion,
c64f69d9 124 ];
30f5345c
TO
125 }
126 $result = $this->civicrm_api($entity, $action, $params);
127 $this->assertAPIFailure($result, "We expected a failure for $entity $action but got a success", $expectedErrorMessage);
128 return $result;
129 }
130
131 /**
132 * wrap api functions.
133 * so we can ensure they succeed & throw exceptions without litterering the test with checks
134 *
135 * @param string $entity
136 * @param string $action
137 * @param array $params
138 * @param mixed $checkAgainst
139 * Optional value to check result against, implemented for getvalue,.
140 * getcount, getsingle. Note that for getvalue the type is checked rather than the value
141 * for getsingle the array is compared against an array passed in - the id is not compared (for
142 * better or worse )
143 *
144 * @return array|int
145 */
62950ef9 146 public function callAPISuccess($entity, $action, $params = [], $checkAgainst = NULL) {
c64f69d9 147 $params = array_merge([
30f5345c
TO
148 'version' => $this->_apiversion,
149 'debug' => 1,
c64f69d9 150 ],
30f5345c
TO
151 $params
152 );
153 switch (strtolower($action)) {
154 case 'getvalue':
155 return $this->callAPISuccessGetValue($entity, $params, $checkAgainst);
156
157 case 'getsingle':
158 return $this->callAPISuccessGetSingle($entity, $params, $checkAgainst);
159
160 case 'getcount':
161 return $this->callAPISuccessGetCount($entity, $params, $checkAgainst);
162 }
163 $result = $this->civicrm_api($entity, $action, $params);
164 $this->assertAPISuccess($result, "Failure in api call for $entity $action");
165 return $result;
166 }
167
168 /**
169 * This function exists to wrap api getValue function & check the result
170 * so we can ensure they succeed & throw exceptions without litterering the test with checks
171 * There is a type check in this
023f9e8a 172 *
30f5345c
TO
173 * @param string $entity
174 * @param array $params
023f9e8a 175 * @param int $count
176 *
177 * @throws \CRM_Core_Exception
178 *
30f5345c
TO
179 * @return array|int
180 */
181 public function callAPISuccessGetCount($entity, $params, $count = NULL) {
c64f69d9 182 $params += [
30f5345c
TO
183 'version' => $this->_apiversion,
184 'debug' => 1,
c64f69d9 185 ];
30f5345c
TO
186 $result = $this->civicrm_api($entity, 'getcount', $params);
187 if (!is_int($result) || !empty($result['is_error']) || isset($result['values'])) {
023f9e8a 188 throw new \CRM_Core_Exception('Invalid getcount result : ' . print_r($result, TRUE) . " type :" . gettype($result));
30f5345c
TO
189 }
190 if (is_int($count)) {
191 $this->assertEquals($count, $result, "incorrect count returned from $entity getcount");
192 }
193 return $result;
194 }
195
196 /**
197 * This function exists to wrap api getsingle function & check the result
198 * so we can ensure they succeed & throw exceptions without litterering the test with checks
199 *
200 * @param string $entity
201 * @param array $params
202 * @param array $checkAgainst
203 * Array to compare result against.
204 * - boolean
205 * - integer
206 * - double
207 * - string
208 * - array
209 * - object
210 *
023f9e8a 211 * @throws \CRM_Core_Exception
212 *
30f5345c
TO
213 * @return array|int
214 */
215 public function callAPISuccessGetSingle($entity, $params, $checkAgainst = NULL) {
c64f69d9 216 $params += [
30f5345c 217 'version' => $this->_apiversion,
c64f69d9 218 ];
30f5345c
TO
219 $result = $this->civicrm_api($entity, 'getsingle', $params);
220 if (!is_array($result) || !empty($result['is_error']) || isset($result['values'])) {
023f9e8a 221 $unfilteredResult = $this->civicrm_api($entity, 'get', ['version' => $this->_apiversion]);
222 throw new \CRM_Core_Exception(
cb4e7d31 223 'Invalid getsingle result' . print_r($result, TRUE)
224 . "\n entity: $entity . \n params \n " . print_r($params, TRUE)
34f3bbd9 225 . "\n entities retrieved with blank params \n" . print_r($unfilteredResult, TRUE)
cb4e7d31 226 );
30f5345c
TO
227 }
228 if ($checkAgainst) {
229 // @todo - have gone with the fn that unsets id? should we check id?
230 $this->checkArrayEquals($result, $checkAgainst);
231 }
232 return $result;
233 }
234
235 /**
236 * This function exists to wrap api getValue function & check the result
237 * so we can ensure they succeed & throw exceptions without litterering the test with checks
238 * There is a type check in this
239 *
240 * @param string $entity
241 * @param array $params
242 * @param string $type
243 * Per http://php.net/manual/en/function.gettype.php possible types.
244 * - boolean
245 * - integer
246 * - double
247 * - string
248 * - array
249 * - object
250 *
251 * @return array|int
5214f03b 252 * @throws \CRM_Core_Exception
30f5345c
TO
253 */
254 public function callAPISuccessGetValue($entity, $params, $type = NULL) {
c64f69d9 255 $params += [
30f5345c
TO
256 'version' => $this->_apiversion,
257 'debug' => 1,
c64f69d9 258 ];
30f5345c 259 $result = $this->civicrm_api($entity, 'getvalue', $params);
1bf00882 260 if (is_array($result) && (!empty($result['is_error']) || isset($result['values']))) {
5214f03b 261 throw new \CRM_Core_Exception('Invalid getvalue result' . print_r($result, TRUE));
1bf00882 262 }
30f5345c 263 if ($type) {
5214f03b 264 if ($type === 'integer') {
30f5345c
TO
265 // api seems to return integers as strings
266 $this->assertTrue(is_numeric($result), "expected a numeric value but got " . print_r($result, 1));
267 }
268 else {
269 $this->assertType($type, $result, "returned result should have been of type $type but was ");
270 }
271 }
272 return $result;
273 }
274
275 /**
276 * A stub for the API interface. This can be overriden by subclasses to change how the API is called.
277 *
278 * @param $entity
279 * @param $action
280 * @param array $params
281 * @return array|int
282 */
62950ef9
CW
283 public function civicrm_api($entity, $action, $params = []) {
284 if (\CRM_Utils_Array::value('version', $params) == 4) {
285 return $this->runApi4Legacy($entity, $action, $params);
286 }
30f5345c
TO
287 return civicrm_api($entity, $action, $params);
288 }
289
62950ef9
CW
290 /**
291 * Emulate v3 syntax so we can run api3 tests on v4
292 *
293 * @param $v3Entity
294 * @param $v3Action
295 * @param array $v3Params
296 * @return array|int
297 * @throws \API_Exception
298 * @throws \CiviCRM_API3_Exception
299 * @throws \Exception
300 */
301 public function runApi4Legacy($v3Entity, $v3Action, $v3Params = []) {
302 $v4Entity = self::convertEntityNameToApi4($v3Entity);
303 $v4Action = $v3Action = strtolower($v3Action);
304 $v4Params = ['checkPermissions' => isset($v3Params['check_permissions']) ? (bool) $v3Params['check_permissions'] : FALSE];
305 $sequential = !empty($v3Params['sequential']);
306 $options = \_civicrm_api3_get_options_from_params($v3Params, in_array($v4Entity, ['Contact', 'Participant', 'Event', 'Group', 'Contribution', 'Membership']));
307 $indexBy = in_array($v3Action, ['get', 'create', 'replace']) && !$sequential ? 'id' : NULL;
308 $onlyId = !empty($v3Params['format.only_id']);
309 $onlySuccess = !empty($v3Params['format.is_success']);
3e20c1ac 310 if (!empty($v3Params['filters']['is_current']) || !empty($v3Params['isCurrent'])) {
62950ef9
CW
311 $v4Params['current'] = TRUE;
312 }
3e20c1ac
CW
313 $language = !empty($v3Params['options']['language']) ? $v3Params['options']['language'] : \CRM_Utils_Array::value('option.language', $v3Params);
314 if ($language) {
315 $v4Params['language'] = $language;
316 }
62950ef9
CW
317 $toRemove = ['option.', 'return', 'api.', 'format.'];
318 $chains = [];
319 $custom = [];
320 foreach ($v3Params as $key => $val) {
321 foreach ($toRemove as $remove) {
322 if (strpos($key, $remove) === 0) {
323 if ($remove == 'api.') {
324 $chains[$key] = $val;
325 }
326 unset($v3Params[$key]);
327 }
328 }
329 }
330
331 $v3Fields = civicrm_api3($v3Entity, 'getfields', ['action' => $v3Action])['values'];
332
333 // Fix 'null'
334 foreach ($v3Params as $key => $val) {
335 if ($val === 'null') {
336 $v3Params[$key] = NULL;
337 }
338 }
339
340 if ($v4Entity == 'Setting') {
341 $indexBy = NULL;
342 $v4Params['domainId'] = \CRM_Utils_Array::value('domain_id', $v3Params);
343 if ($v3Action == 'getfields') {
344 if (!empty($v3Params['name'])) {
345 $v3Params['filters']['name'] = $v3Params['name'];
346 }
347 foreach (\CRM_Utils_Array::value('filters', $v3Params, []) as $filter => $val) {
348 $v4Params['where'][] = [$filter, '=', $val];
349 }
350 }
351 if ($v3Action == 'create') {
352 $v4Action = 'set';
353 }
354 if ($v3Action == 'revert') {
355 $v4Params['select'] = (array) $v3Params['name'];
356 }
357 if ($v3Action == 'getvalue') {
358 $options['return'] = [$v3Params['name'] => 1];
359 $v3Params = [];
360 }
361 \CRM_Utils_Array::remove($v3Params, 'domain_id', 'name');
362 }
363
364 \CRM_Utils_Array::remove($v3Params, 'options', 'debug', 'version', 'sort', 'offset', 'rowCount', 'check_permissions', 'sequential', 'filters', 'isCurrent');
365
366 // Work around ugly hack in v3 Domain api
367 if ($v4Entity == 'Domain') {
368 $v3Fields['version'] = ['name' => 'version', 'api.aliases' => ['domain_version']];
369 unset($v3Fields['domain_version']);
370 }
371
372 foreach ($v3Fields as $name => $field) {
373 // Resolve v3 aliases
374 foreach (\CRM_Utils_Array::value('api.aliases', $field, []) as $alias) {
375 if (isset($v3Params[$alias])) {
376 $v3Params[$field['name']] = $v3Params[$alias];
377 unset($v3Params[$alias]);
378 }
379 }
380 // Convert custom field names
381 if (strpos($name, 'custom_') === 0 && is_numeric($name[7])) {
382 // Strictly speaking, using titles instead of names is incorrect, but it works for
383 // unit tests where names and titles are identical and saves an extra db lookup.
384 $custom[$field['groupTitle']][$field['title']] = $name;
385 $v4FieldName = $field['groupTitle'] . '.' . $field['title'];
386 if (isset($v3Params[$name])) {
387 $v3Params[$v4FieldName] = $v3Params[$name];
388 unset($v3Params[$name]);
389 }
390 if (isset($options['return'][$name])) {
391 $options['return'][$v4FieldName] = 1;
392 unset($options['return'][$name]);
393 }
394 }
395 }
396
397 switch ($v3Action) {
398 case 'getcount':
399 $v4Params['select'] = ['row_count'];
400 // No break - keep processing as get
401 case 'getsingle':
402 case 'getvalue':
403 $v4Action = 'get';
404 // No break - keep processing as get
405 case 'get':
406 if ($options['return'] && $v3Action !== 'getcount') {
407 $v4Params['select'] = array_keys($options['return']);
408 }
409 if ($options['limit'] && $v4Entity != 'Setting') {
410 $v4Params['limit'] = $options['limit'];
411 }
412 if ($options['offset']) {
413 $v4Params['offset'] = $options['offset'];
414 }
415 if ($options['sort']) {
416 foreach (explode(',', $options['sort']) as $sort) {
417 list($sortField, $sortDir) = array_pad(explode(' ', trim($sort)), 2, 'ASC');
418 $v4Params['orderBy'][$sortField] = $sortDir;
419 }
420 }
421 break;
422
423 case 'replace':
424 if (empty($v3Params['values'])) {
425 $v4Action = 'delete';
426 }
427 else {
428 $v4Params['records'] = $v3Params['values'];
429 }
430 unset($v3Params['values']);
431 break;
432
433 case 'create':
434 case 'update':
435 if (!empty($v3Params['id'])) {
436 $v4Action = 'update';
437 $v4Params['where'][] = ['id', '=', $v3Params['id']];
438 }
439
440 $v4Params['values'] = $v3Params;
441 unset($v4Params['values']['id']);
442 break;
443
444 case 'delete':
445 if (!empty($v3Params['id'])) {
446 $v4Params['where'][] = ['id', '=', $v3Params['id']];
447 }
448 break;
449
450 case 'getoptions':
451 $indexBy = 0;
452 $v4Action = 'getFields';
453 $v4Params += [
454 'where' => [['name', '=', $v3Params['field']]],
455 'loadOptions' => TRUE,
456 ];
457 break;
458
459 case 'getfields':
460 $v4Action = 'getFields';
461 if (!empty($v3Params['action']) || !empty($v3Params['api_action'])) {
462 $v4Params['action'] = !empty($v3Params['action']) ? $v3Params['action'] : $v3Params['api_action'];
463 }
464 $indexBy = !$sequential ? 'name' : NULL;
465 break;
466 }
467
468 // Ensure this api4 entity/action exists
469 try {
470 $actionInfo = \civicrm_api4($v4Entity, 'getActions', ['checkPermissions' => FALSE, 'where' => [['name', '=', $v4Action]]]);
471 }
472 catch (NotImplementedException $e) {
473 // For now we'll mark the test incomplete if a v4 entity doesn't exit yet
474 $this->markTestIncomplete($e->getMessage());
475 }
476 if (!isset($actionInfo[0])) {
477 throw new \Exception("Api4 $v4Entity $v4Action does not exist.");
478 }
479
480 // Migrate special params like fix_address
481 foreach ($actionInfo[0]['params'] as $v4ParamName => $paramInfo) {
482 // camelCase in api4, lower_case in api3
483 $v3ParamName = strtolower(preg_replace('/(?=[A-Z])/', '_$0', $v4ParamName));
484 if (isset($v3Params[$v3ParamName])) {
485 $v4Params[$v4ParamName] = $v3Params[$v3ParamName];
486 unset($v3Params[$v3ParamName]);
487 if ($paramInfo['type'][0] == 'bool') {
488 $v4Params[$v4ParamName] = (bool) $v4Params[$v4ParamName];
489 }
490 }
491 }
492
493 // Build where clause for 'getcount', 'getsingle', 'getvalue', 'get' & 'replace'
494 if ($v4Action == 'get' || $v3Action == 'replace') {
495 foreach ($v3Params as $key => $val) {
496 $op = '=';
497 if (is_array($val) && count($val) == 1 && array_intersect_key($val, array_flip(\CRM_Core_DAO::acceptedSQLOperators()))) {
498 foreach ($val as $op => $newVal) {
499 $val = $newVal;
500 }
501 }
502 $v4Params['where'][] = [$key, $op, $val];
503 }
504 }
505
506 try {
507 $result = \civicrm_api4($v4Entity, $v4Action, $v4Params, $indexBy);
508 }
509 catch (\Exception $e) {
510 return $onlySuccess ? 0 : [
511 'is_error' => 1,
512 'error_message' => $e->getMessage(),
513 'version' => 4,
514 ];
515 }
516
517 if (($v3Action == 'getsingle' || $v3Action == 'getvalue') && count($result) != 1) {
518 return $onlySuccess ? 0 : [
519 'is_error' => 1,
520 'error_message' => "Expected one $v4Entity but found " . count($result),
521 'count' => count($result),
522 ];
523 }
524
525 if ($onlySuccess) {
526 return 1;
527 }
528
529 if ($v3Action == 'getcount') {
530 return $result->count();
531 }
532
533 if ($onlyId) {
534 return $result->first()['id'];
535 }
536
537 if ($v3Action == 'getvalue' && $v4Entity == 'Setting') {
538 return \CRM_Utils_Array::value('value', $result->first());
539 }
540
541 if ($v3Action == 'getvalue') {
542 return \CRM_Utils_Array::value(array_keys($options['return'])[0], $result->first());
543 }
544
545 // Mimic api3 behavior when using 'replace' action to delete all
546 if ($v3Action == 'replace' && $v4Action == 'delete') {
547 $result->exchangeArray([]);
548 }
549
550 if ($v3Action == 'getoptions') {
551 return [
552 'is_error' => 0,
553 'count' => $result['options'] ? count($result['options']) : 0,
554 'values' => $result['options'] ?: [],
555 'version' => 4,
556 ];
557 }
558
559 // Emulate the weird return format of api3 settings
560 if (($v3Action == 'get' || $v3Action == 'create') && $v4Entity == 'Setting') {
561 $settings = [];
562 foreach ($result as $item) {
563 $settings[$item['domain_id']][$item['name']] = $item['value'];
564 }
565 $result->exchangeArray($sequential ? array_values($settings) : $settings);
566 }
567
568 foreach ($result as $index => $row) {
569 // Run chains
570 foreach ($chains as $key => $params) {
571 $result[$index][$key] = $this->runApi4LegacyChain($key, $params, $v4Entity, $row, $sequential);
572 }
573 // Resolve custom field names
574 foreach ($custom as $group => $fields) {
f74361a9
CW
575 foreach ($fields as $field => $v3FieldName) {
576 if (isset($row["$group.$field"])) {
577 $result[$index][$v3FieldName] = $row["$group.$field"];
578 unset($result[$index]["$group.$field"]);
62950ef9 579 }
62950ef9
CW
580 }
581 }
582 }
583
584 if ($v3Action == 'getsingle') {
585 return $result->first();
586 }
587
588 return [
589 'is_error' => 0,
590 'version' => 4,
591 'count' => count($result),
592 'values' => (array) $result,
593 'id' => is_object($result) && count($result) == 1 ? \CRM_Utils_Array::value('id', $result->first()) : NULL,
594 ];
595 }
596
597 /**
598 * @param string $key
599 * @param mixed $params
600 * @param string $mainEntity
601 * @param array $result
602 * @param bool $sequential
603 * @return array
604 * @throws \API_Exception
605 */
606 protected function runApi4LegacyChain($key, $params, $mainEntity, $result, $sequential) {
607 // Handle an array of multiple calls using recursion
608 if (is_array($params) && isset($params[0]) && is_array($params[0])) {
609 $results = [];
610 foreach ($params as $chain) {
611 $results[] = $this->runApi4LegacyChain($key, $chain, $mainEntity, $result, $sequential);
612 }
613 return $results;
614 }
615
616 // Handle single api call
617 list(, $chainEntity, $chainAction) = explode('.', $key);
618 $lcChainEntity = \_civicrm_api_get_entity_name_from_camel($chainEntity);
619 $chainEntity = self::convertEntityNameToApi4($chainEntity);
620 $lcMainEntity = \_civicrm_api_get_entity_name_from_camel($mainEntity);
621 $params = is_array($params) ? $params : [];
622
623 // Api3 expects this to be inherited
624 $params += ['sequential' => $sequential];
625
626 // Replace $value.field_name
627 foreach ($params as $name => $param) {
628 if (is_string($param) && strpos($param, '$value.') === 0) {
629 $param = substr($param, 7);
630 $params[$name] = \CRM_Utils_Array::value($param, $result);
631 }
632 }
633
634 try {
635 $getFields = civicrm_api4($chainEntity, 'getFields', ['select' => ['name']], 'name');
636 }
637 catch (NotImplementedException $e) {
638 $this->markTestIncomplete($e->getMessage());
639 }
640
641 // Emulate the string-fu guesswork that api3 does
642 if ($chainEntity == $mainEntity && empty($params['id']) && !empty($result['id'])) {
643 $params['id'] = $result['id'];
644 }
645 elseif (empty($params['id']) && !empty($result[$lcChainEntity . '_id'])) {
646 $params['id'] = $result[$lcChainEntity . '_id'];
647 }
648 elseif (!empty($result['id']) && isset($getFields[$lcMainEntity . '_id']) && empty($params[$lcMainEntity . '_id'])) {
649 $params[$lcMainEntity . '_id'] = $result['id'];
650 }
651 return $this->runApi4Legacy($chainEntity, $chainAction, $params);
652 }
653
654 /**
655 * Fix the naming differences between api3 & api4 entities.
656 *
657 * @param string $legacyName
658 * @return string
659 */
660 public static function convertEntityNameToApi4($legacyName) {
661 $api4Name = \CRM_Utils_String::convertStringToCamel($legacyName);
662 $map = [
663 'Im' => 'IM',
664 'Acl' => 'ACL',
665 ];
666 return \CRM_Utils_Array::value($api4Name, $map, $api4Name);
667 }
668
30f5345c 669}