Merge pull request #21747 from totten/master-preview
[civicrm-core.git] / Civi / Test / Api3TestTrait.php
index 4fb4c3731fa42ca052d53f007e9d27ef98143f97..65bd2ee2162e5c167d6bc1a56ef70513a13d937c 100644 (file)
@@ -152,8 +152,6 @@ trait Api3TestTrait {
    *   better or worse )
    *
    * @return array|int
-   *
-   * @throws \CRM_Core_Exception
    */
   public function callAPISuccess($entity, $action, $params = [], $checkAgainst = NULL) {
     $params = array_merge([
@@ -218,18 +216,19 @@ trait Api3TestTrait {
    *   - array
    *   - object
    *
-   * @throws \CRM_Core_Exception
-   *
    * @return array|int
    */
   public function callAPISuccessGetSingle($entity, $params, $checkAgainst = NULL) {
     $params += [
       'version' => $this->_apiversion,
     ];
+    if (!empty($this->isGetSafe) && !isset($params['return'])) {
+      $params['return'] = 'id';
+    }
     $result = $this->civicrm_api($entity, 'getsingle', $params);
     if (!is_array($result) || !empty($result['is_error']) || isset($result['values'])) {
       $unfilteredResult = $this->civicrm_api($entity, 'get', ['version' => $this->_apiversion]);
-      throw new \CRM_Core_Exception(
+      $this->fail(
         'Invalid getsingle result' . print_r($result, TRUE)
         . "\n entity: $entity . \n params \n " . print_r($params, TRUE)
         . "\n entities retrieved with blank params \n" . print_r($unfilteredResult, TRUE)
@@ -314,14 +313,15 @@ trait Api3TestTrait {
     $onlyId = !empty($v3Params['format.only_id']);
     $onlySuccess = !empty($v3Params['format.is_success']);
     if (!empty($v3Params['filters']['is_current']) || !empty($v3Params['isCurrent'])) {
-      $v4Params['current'] = TRUE;
+      $v3Params['is_current'] = 1;
+      unset($v3Params['filters']['is_current'], $v3Params['isCurrent']);
     }
     $language = $v3Params['options']['language'] ?? $v3Params['option.language'] ?? NULL;
     if ($language) {
       $v4Params['language'] = $language;
     }
     $toRemove = ['option.', 'return', 'api.', 'format.'];
-    $chains = $joins = $custom = [];
+    $chains = $custom = [];
     foreach ($v3Params as $key => $val) {
       foreach ($toRemove as $remove) {
         if (strpos($key, $remove) === 0) {
@@ -402,7 +402,7 @@ trait Api3TestTrait {
         // 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'];
+        $v3Params['option_group_id.name'] = $v3Params['option_group_id'];
         unset($v3Params['option_group_id']);
       }
       if (isset($field['pseudoconstant'], $v3Params[$name]) && $field['type'] === \CRM_Utils_Type::T_INT && !is_numeric($v3Params[$name]) && is_string($v3Params[$name])) {
@@ -425,12 +425,6 @@ trait Api3TestTrait {
           if ($v4Entity != 'Setting' && !in_array('id', $v4Params['select'])) {
             $v4Params['select'][] = 'id';
           }
-          // Convert join syntax
-          foreach ($v4Params['select'] as $idx => $select) {
-            if (strstr($select, '_id.')) {
-              $joins[$select] = $v4Params['select'][$idx] = str_replace('_id.', '.', $select);
-            }
-          }
         }
         if ($options['limit'] && $v4Entity != 'Setting') {
           $v4Params['limit'] = $options['limit'];
@@ -597,10 +591,6 @@ trait Api3TestTrait {
       foreach ($chains as $key => $params) {
         $result[$index][$key] = $this->runApi4LegacyChain($key, $params, $v4Entity, $row, $sequential);
       }
-      // Convert join format
-      foreach ($joins as $api3Key => $api4Key) {
-        $result[$index][$api3Key] = $result[$index][$api4Key] ?? NULL;
-      }
       // Resolve custom field names
       foreach ($custom as $group => $fields) {
         foreach ($fields as $field => $v3FieldName) {