From: adriano66 <3438696+adriano66@users.noreply.github.com> Date: Thu, 16 Dec 2021 22:03:16 +0000 (+0100) Subject: dev/core#2524 - Fix missing serialization defaults X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=b6e509278e292627355fa5dc0aacd1a98f7d6a31;p=civicrm-core.git dev/core#2524 - Fix missing serialization defaults This fixes the "'0' is not a valid option for field serialize" exception in APIv3 as 0 is a valid, default value set in the DB This allows passing whole custom field data as a parameter to the custom field update method without getting an exception Co-authored-by: colemanw --- diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index 6cb84d25e2..290676183a 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -81,6 +81,10 @@ class CRM_Core_DAO extends DB_DataObject { QUERY_FORMAT_WILDCARD = 1, QUERY_FORMAT_NO_QUOTES = 2, + /** + * No serialization. + */ + SERIALIZE_NONE = 0, /** * Serialized string separated by and bookended with VALUE_SEPARATOR */ diff --git a/CRM/Core/SelectValues.php b/CRM/Core/SelectValues.php index 31254a4dc7..c591954617 100644 --- a/CRM/Core/SelectValues.php +++ b/CRM/Core/SelectValues.php @@ -1136,6 +1136,7 @@ class CRM_Core_SelectValues { */ public static function fieldSerialization() { return [ + CRM_Core_DAO::SERIALIZE_NONE => 'none', CRM_Core_DAO::SERIALIZE_SEPARATOR_BOOKEND => 'separator_bookend', CRM_Core_DAO::SERIALIZE_SEPARATOR_TRIMMED => 'separator_trimmed', CRM_Core_DAO::SERIALIZE_JSON => 'json', diff --git a/tests/phpunit/CRM/Core/DAOTest.php b/tests/phpunit/CRM/Core/DAOTest.php index f5b871cc7f..5786a146de 100644 --- a/tests/phpunit/CRM/Core/DAOTest.php +++ b/tests/phpunit/CRM/Core/DAOTest.php @@ -407,6 +407,9 @@ class CRM_Core_DAOTest extends CiviUnitTestCase { ]; $daoInfo = new ReflectionClass('CRM_Core_DAO'); foreach ($daoInfo->getConstants() as $constant => $val) { + if ($constant === 'SERIALIZE_NONE') { + continue; + } if ($constant === 'SERIALIZE_JSON' || $constant === 'SERIALIZE_PHP') { $constants[] = [$val, array_merge($simpleData, $complexData)]; } diff --git a/tests/phpunit/api/v3/CustomFieldTest.php b/tests/phpunit/api/v3/CustomFieldTest.php index 88e4ef20c7..7ea591384a 100644 --- a/tests/phpunit/api/v3/CustomFieldTest.php +++ b/tests/phpunit/api/v3/CustomFieldTest.php @@ -73,10 +73,10 @@ class api_v3_CustomFieldTest extends CiviUnitTestCase { ]; $customField = $this->callAPIAndDocument('custom_field', 'create', $params, __FUNCTION__, __FILE__); - $params['id'] = $customField['id']; - $customField = $this->callAPISuccess('custom_field', 'create', $params); + $customField['label'] = 'Name2'; + $customFieldEdited = $this->callAPISuccess('custom_field', 'create', $customField); - $this->assertNotNull($customField['id']); + $this->assertNotNull($customFieldEdited['id']); } /**