CRM_Contact_BAO_Contact::add cast string contact sub types to array
authorSandor Semsey <sandor@es-progress.hu>
Fri, 20 Oct 2023 07:46:02 +0000 (09:46 +0200)
committerSandor Semsey <sandor@es-progress.hu>
Fri, 20 Oct 2023 08:59:30 +0000 (10:59 +0200)
CRM/Contact/BAO/Contact.php
tests/phpunit/CRM/Contact/BAO/ContactTest.php

index f05ed0793163ddbdce376ad8a016faf6dbf9dbaa..a9c772dc4157cc2c97fc43d4dbe12167d6ad40f9 100644 (file)
@@ -119,6 +119,8 @@ class CRM_Contact_BAO_Contact extends CRM_Contact_DAO_Contact implements Civi\Co
           // CRM-7925
           throw new CRM_Core_Exception(ts('The Contact Sub Type does not match the Contact type for this record'));
         }
+        // Cast to array as serialization in CRM_Core_DAO::copyValues() will happen only if it is an array.
+        $params['contact_sub_type'] = (array) ($params['contact_sub_type']);
       }
     }
 
index 81406f95d9ab00287f53b58158922f97f440fa38..a30e4365a5ed53c2b4a81c4e28995bb3019c675a 100644 (file)
@@ -258,7 +258,11 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase {
       'contact_sub_type' => $sub_contact_type,
     ];
     $contact = CRM_Contact_BAO_Contact::add($params);
-    $this->assertSame($sub_contact_type, $contact->contact_sub_type, 'Wrong contact sub-type saved.');
+    $this->assertSame(
+      CRM_Core_DAO::serializeField($sub_contact_type, $contact->fields()['contact_sub_type']['serialize']),
+      $contact->contact_sub_type,
+      'Wrong contact sub-type saved.'
+    );
   }
 
   /**