Fix APIv3 test to better handle serialized fields
authorColeman Watts <coleman@civicrm.org>
Sat, 8 Apr 2023 19:40:19 +0000 (15:40 -0400)
committerColeman Watts <coleman@civicrm.org>
Thu, 27 Apr 2023 13:30:45 +0000 (09:30 -0400)
Civi/API/Subscriber/ChainSubscriber.php
tests/phpunit/api/v3/SyntaxConformanceTest.php

index 7be1bfb913c1e200e4a8df8f2398304c6b991238..84b011eed431c3d91c6a91e06704303f300dfb13 100644 (file)
@@ -90,9 +90,11 @@ class ChainSubscriber implements EventSubscriberInterface {
       $result = ['values' => [0 => $oldResult]];
     }
 
+    // Keys which should not be assumed to be chain calls
+    $blacklist = ['api.has_parent', 'api_params'];
     // Scan the params for chain calls.
     foreach ($params as $field => $newparams) {
-      if ((is_array($newparams) || $newparams === 1) && $field <> 'api.has_parent' && substr($field, 0, 3) == 'api') {
+      if ((is_array($newparams) || $newparams === 1) && !in_array($field, $blacklist, TRUE) && substr($field, 0, 3) == 'api') {
         // This param is a chain call, e.g. api.<entity>.<action>
 
         // 'api.participant.delete' => 1 is a valid options - handle 1
index a67b8c9d5cf627dded1fe3f9df67f9b696085058..e580a495ec74b36e973c8b2202f7f7653440fb01 100644 (file)
@@ -1461,6 +1461,9 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
         // FIXME: Why doesn't creating a campaign clear caches?
         civicrm_api3($entityName, 'getfields', ['cache_clear' => 1]);
       }
+      if (!empty($specs['serialize'])) {
+        $entity[$field] = (array) $entity[$field];
+      }
       $updateParams = [
         'id' => $entity['id'],
         $field => $entity[$field] ?? NULL,