From 000196256efa96ed7ce04ab42330ec3bff3e689b Mon Sep 17 00:00:00 2001 From: Sandor Semsey Date: Fri, 20 Oct 2023 09:46:02 +0200 Subject: [PATCH] CRM_Contact_BAO_Contact::add cast string contact sub types to array --- CRM/Contact/BAO/Contact.php | 2 ++ tests/phpunit/CRM/Contact/BAO/ContactTest.php | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) 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.' + ); } /** -- 2.25.1