Fix join syntax conversion for APIv4 in v3 unit tests
authorColeman Watts <coleman@civicrm.org>
Mon, 4 Jan 2021 21:08:14 +0000 (16:08 -0500)
committerColeman Watts <coleman@civicrm.org>
Mon, 4 Jan 2021 21:08:14 +0000 (16:08 -0500)
Civi/Test/Api3TestTrait.php
tests/phpunit/api/v3/ContactTest.php

index f84c4c2f98019c1f2eec7e751394a0595a39cc7e..5be0bc9ae3270511e6872ec18e06dc6309f3b882 100644 (file)
@@ -425,10 +425,9 @@ trait Api3TestTrait {
             $v4Params['select'][] = 'id';
           }
           // Convert join syntax
-          foreach ($v4Params['select'] as &$select) {
+          foreach ($v4Params['select'] as $idx => $select) {
             if (strstr($select, '_id.')) {
-              $joins[$select] = explode('.', str_replace('_id.', '.', $select));
-              $select = str_replace('_id.', '.', $select);
+              $joins[$select] = $v4Params['select'][$idx] = str_replace('_id.', '.', $select);
             }
           }
         }
@@ -598,8 +597,8 @@ trait Api3TestTrait {
         $result[$index][$key] = $this->runApi4LegacyChain($key, $params, $v4Entity, $row, $sequential);
       }
       // Convert join format
-      foreach ($joins as $api3Key => $api4Path) {
-        $result[$index][$api3Key] = \CRM_Utils_Array::pathGet($result[$index], $api4Path);
+      foreach ($joins as $api3Key => $api4Key) {
+        $result[$index][$api3Key] = $result[$index][$api4Key] ?? NULL;
       }
       // Resolve custom field names
       foreach ($custom as $group => $fields) {
index 5178b75a94a51a676e7c6bda7f45f1bee126210b..b7a85306e93a149b0f9d1c8d913fe9eb90a98dc2 100644 (file)
@@ -650,8 +650,7 @@ class api_v3_ContactTest extends CiviUnitTestCase {
       'contact_id' => $contactId,
       'return' => 'contact_id.api_key',
     ]);
-    $field = $this->_apiversion == 4 ? 'contact.api_key' : 'contact_id.api_key';
-    $this->assertEquals('abcd1234', $joinResult[$field]);
+    $this->assertEquals('abcd1234', $joinResult['contact_id.api_key']);
 
     // Restricted return -- because we don't have permission
     $config->userPermissionClass->permissions = ['access CiviCRM', 'view all contacts', 'edit all contacts'];