From: Sandor Semsey Date: Fri, 20 Oct 2023 07:46:02 +0000 (+0200) Subject: CRM_Contact_BAO_Contact::add cast string contact sub types to array X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=000196256efa96ed7ce04ab42330ec3bff3e689b;p=civicrm-core.git CRM_Contact_BAO_Contact::add cast string contact sub types to array --- diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index f05ed07931..a9c772dc41 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -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']); } } diff --git a/tests/phpunit/CRM/Contact/BAO/ContactTest.php b/tests/phpunit/CRM/Contact/BAO/ContactTest.php index 81406f95d9..a30e4365a5 100644 --- a/tests/phpunit/CRM/Contact/BAO/ContactTest.php +++ b/tests/phpunit/CRM/Contact/BAO/ContactTest.php @@ -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.' + ); } /**