X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=Civi%2FTest%2FApi3TestTrait.php;h=6d5421053dcb75835c34c503a2007fad3a06a64f;hb=2e5067e6f8379e0a7fcfe41d51396776a4a04bf9;hp=79e6e8e53cd7670551dac3794161056e5f8aff05;hpb=b3bf256760734229a5086e77762edafccade990f;p=civicrm-core.git diff --git a/Civi/Test/Api3TestTrait.php b/Civi/Test/Api3TestTrait.php index 79e6e8e53c..6d5421053d 100644 --- a/Civi/Test/Api3TestTrait.php +++ b/Civi/Test/Api3TestTrait.php @@ -23,12 +23,7 @@ trait Api3TestTrait { * @return array */ public function versionThreeAndFour() { - $r = [[3]]; - global $civicrm_root; - if (file_exists("$civicrm_root/Civi/Api4") || file_exists("$civicrm_root/ext/api4")) { - $r[] = [4]; - } - return $r; + return [[3], [4]]; } /** @@ -109,7 +104,7 @@ trait Api3TestTrait { if (!empty($apiResult['trace'])) { $errorMessage .= "\n" . print_r($apiResult['trace'], TRUE); } - $this->assertEmpty(\CRM_Utils_Array::value('is_error', $apiResult), $prefix . $errorMessage); + $this->assertEmpty($apiResult['is_error'] ?? NULL, $prefix . $errorMessage); } /** @@ -289,7 +284,7 @@ trait Api3TestTrait { * @return array|int */ public function civicrm_api($entity, $action, $params = []) { - if (\CRM_Utils_Array::value('version', $params) == 4) { + if (($params['version'] ?? 0) == 4) { return $this->runApi4Legacy($entity, $action, $params); } return civicrm_api($entity, $action, $params); @@ -318,7 +313,7 @@ trait Api3TestTrait { if (!empty($v3Params['filters']['is_current']) || !empty($v3Params['isCurrent'])) { $v4Params['current'] = TRUE; } - $language = !empty($v3Params['options']['language']) ? $v3Params['options']['language'] : \CRM_Utils_Array::value('option.language', $v3Params); + $language = $v3Params['options']['language'] ?? $v3Params['option.language'] ?? NULL; if ($language) { $v4Params['language'] = $language; } @@ -346,12 +341,12 @@ trait Api3TestTrait { if ($v4Entity == 'Setting') { $indexBy = NULL; - $v4Params['domainId'] = \CRM_Utils_Array::value('domain_id', $v3Params); + $v4Params['domainId'] = $v3Params['domain_id'] ?? NULL; if ($v3Action == 'getfields') { if (!empty($v3Params['name'])) { $v3Params['filters']['name'] = $v3Params['name']; } - foreach (\CRM_Utils_Array::value('filters', $v3Params, []) as $filter => $val) { + foreach ($v3Params['filters'] ?? [] as $filter => $val) { $v4Params['where'][] = [$filter, '=', $val]; } } @@ -378,7 +373,7 @@ trait Api3TestTrait { foreach ($v3Fields as $name => $field) { // Resolve v3 aliases - foreach (\CRM_Utils_Array::value('api.aliases', $field, []) as $alias) { + foreach ($field['api.aliases'] ?? [] as $alias) { if (isset($v3Params[$alias])) { $v3Params[$field['name']] = $v3Params[$alias]; unset($v3Params[$alias]); @@ -399,6 +394,14 @@ trait Api3TestTrait { unset($options['return'][$name]); } } + + if ($name === 'option_group_id' && isset($v3Params[$name]) && !is_numeric($v3Params[$name])) { + // This is a per field hack (bad) but we can't solve everything at once + // & a cleverer way turned out to be too much for this round. + // Being in the test class it's tested.... + $v3Params['option_group.name'] = $v3Params['option_group_id']; + unset($v3Params['option_group_id']); + } } switch ($v3Action) { @@ -553,11 +556,12 @@ trait Api3TestTrait { } if ($v3Action == 'getvalue' && $v4Entity == 'Setting') { - return \CRM_Utils_Array::value('value', $result->first()); + return $result->first()['value'] ?? NULL; } if ($v3Action == 'getvalue') { - return \CRM_Utils_Array::value(array_keys($options['return'])[0], $result->first()); + $returnKey = array_keys($options['return'])[0]; + return $result->first()[$returnKey] ?? NULL; } // Mimic api3 behavior when using 'replace' action to delete all @@ -612,7 +616,7 @@ trait Api3TestTrait { 'version' => 4, 'count' => count($result), 'values' => (array) $result, - 'id' => is_object($result) && count($result) == 1 ? \CRM_Utils_Array::value('id', $result->first()) : NULL, + 'id' => is_object($result) && count($result) == 1 ? ($result->first()['id'] ?? NULL) : NULL, ]; } @@ -649,7 +653,7 @@ trait Api3TestTrait { foreach ($params as $name => $param) { if (is_string($param) && strpos($param, '$value.') === 0) { $param = substr($param, 7); - $params[$name] = \CRM_Utils_Array::value($param, $result); + $params[$name] = $result[$param] ?? NULL; } } @@ -685,7 +689,7 @@ trait Api3TestTrait { 'Im' => 'IM', 'Acl' => 'ACL', ]; - return \CRM_Utils_Array::value($api4Name, $map, $api4Name); + return $map[$api4Name] ?? $api4Name; } }