}
}
elseif (is_array($value) && !empty($field['serialize'])) {
+ if (!empty($field['pseudoconstant'])) {
+ // Pseudoconstant implies 1-1 option matching; duplicates would not make sense
+ $value = array_unique($value);
+ }
$this->$dbName = CRM_Core_DAO::serializeField($value, $field['serialize']);
$allNull = FALSE;
}
$this->contactDelete($contactId);
}
+ /**
+ * Test case for add( ) with duplicated sub contact types.
+ *
+ * @throws \CRM_Core_Exception
+ */
+ public function testAddWithDuplicatedSubContactType(): void {
+ // Sub contact-type as array
+ $sub_contact_type = ['Staff', 'Parent', 'Staff'];
+ $params = [
+ 'first_name' => 'Duplicated sub contact-type as array',
+ 'contact_type' => 'Individual',
+ 'contact_sub_type' => $sub_contact_type,
+ ];
+ $contact = CRM_Contact_BAO_Contact::add($params);
+ $this->assertSame(
+ CRM_Core_DAO::serializeField((array_unique($sub_contact_type)), $contact->fields()['contact_sub_type']['serialize']),
+ $contact->contact_sub_type,
+ 'Contact sub-type not deduplicated.'
+ );
+
+ // Sub contact-type as string
+ $sub_contact_type = 'Staff';
+ $params = [
+ 'first_name' => 'Sub contact-type as string',
+ 'contact_type' => 'Individual',
+ '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.');
+ }
+
/**
* Test case for create.
*