From a8496135ed68bb6048be652e8313d1e8cae136e7 Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 30 Jan 2018 11:11:53 +1300 Subject: [PATCH] CRM-21707 increase testing / use of serialization metadata. Add deprecated when bypassed --- CRM/Core/DAO.php | 3 +++ CRM/Member/BAO/MembershipBlock.php | 2 +- CRM/Report/BAO/ReportInstance.php | 2 +- tests/phpunit/api/v3/SyntaxConformanceTest.php | 7 +++++++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index 5ab5d76d52..f821036b16 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -647,6 +647,9 @@ class CRM_Core_DAO extends DB_DataObject { $allNull = FALSE; } else { + if (!$serializeArrays && is_array($pValue) && !empty($value['serialize'])) { + Civi::log()->warning(ts('use copyParams to serialize arrays (' . __CLASS__ . '.' . $name . ')'), ['civi.tag' => 'deprecated']); + } $this->$dbName = $pValue; $allNull = FALSE; } diff --git a/CRM/Member/BAO/MembershipBlock.php b/CRM/Member/BAO/MembershipBlock.php index 921735ba03..eb32779f7b 100644 --- a/CRM/Member/BAO/MembershipBlock.php +++ b/CRM/Member/BAO/MembershipBlock.php @@ -53,7 +53,7 @@ class CRM_Member_BAO_MembershipBlock extends CRM_Member_DAO_MembershipBlock { $hook = empty($params['id']) ? 'create' : 'edit'; CRM_Utils_Hook::pre($hook, 'MembershipBlock', CRM_Utils_Array::value('id', $params), $params); $dao = new CRM_Member_DAO_MembershipBlock(); - $dao->copyValues($params); + $dao->copyValues($params, TRUE); $dao->id = CRM_Utils_Array::value('id', $params); $dao->save(); CRM_Utils_Hook::post($hook, 'MembershipBlock', $dao->id, $dao); diff --git a/CRM/Report/BAO/ReportInstance.php b/CRM/Report/BAO/ReportInstance.php index fd0096a203..33cb7ab1cd 100644 --- a/CRM/Report/BAO/ReportInstance.php +++ b/CRM/Report/BAO/ReportInstance.php @@ -78,7 +78,7 @@ class CRM_Report_BAO_ReportInstance extends CRM_Report_DAO_ReportInstance { } $instance = new CRM_Report_DAO_ReportInstance(); - $instance->copyValues($params); + $instance->copyValues($params, TRUE); if (CRM_Core_Config::singleton()->userFramework == 'Joomla') { $instance->permission = 'null'; diff --git a/tests/phpunit/api/v3/SyntaxConformanceTest.php b/tests/phpunit/api/v3/SyntaxConformanceTest.php index efb57a26d5..7e5e9eb69e 100644 --- a/tests/phpunit/api/v3/SyntaxConformanceTest.php +++ b/tests/phpunit/api/v3/SyntaxConformanceTest.php @@ -1356,6 +1356,9 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { 'id' => $entity['id'], $field => isset($entity[$field]) ? $entity[$field] : NULL, ); + if (!empty($specs['serialize'])) { + $updateParams[$field] = $entity[$field] = (array) $specs['serialize']; + } if (isset($updateParams['financial_type_id']) && in_array($entityName, array('Grant'))) { //api has special handling on these 2 fields for backward compatibility reasons $entity['contribution_type_id'] = $updateParams['financial_type_id']; @@ -1377,6 +1380,10 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { ); $checkEntity = $this->callAPISuccess($entityName, 'getsingle', $checkParams); + if (!empty($specs['serialize']) && !is_array($checkEntity[$field])) { + // Put into serialized format for comparison if 'get' has not returned serialized. + $entity[$field] = CRM_Core_DAO::serializeField($checkEntity[$field], $specs['serialize']); + } $this->assertAPIArrayComparison($entity, $checkEntity, array(), "checking if $fieldName was correctly updated\n" . print_r(array( 'update-params' => $updateParams, -- 2.25.1