From a0552fd52b83783360c8b91922abf9f95d5957b3 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Fri, 20 Aug 2021 14:48:11 +1200 Subject: [PATCH] dev/rc#14 handle api calls post schema change --- api/v3/utils.php | 4 ++++ tests/phpunit/api/v3/MembershipTypeTest.php | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/api/v3/utils.php b/api/v3/utils.php index d3d6c882a71c..3a940ac389b8 100644 --- a/api/v3/utils.php +++ b/api/v3/utils.php @@ -2059,6 +2059,10 @@ function _civicrm_api3_swap_out_aliases(&$apiRequest, $fields) { */ function _civicrm_api3_validate_integer(&$params, $fieldName, &$fieldInfo, $entity) { list($fieldValue, $op) = _civicrm_api3_field_value_check($params, $fieldName); + if ($fieldName === 'auto_renew' && $fieldValue === TRUE) { + // https://lab.civicrm.org/dev/rc/-/issues/14 + $fieldValue = 1; + } if (strpos($op, 'NULL') !== FALSE || strpos($op, 'EMPTY') !== FALSE) { return; } diff --git a/tests/phpunit/api/v3/MembershipTypeTest.php b/tests/phpunit/api/v3/MembershipTypeTest.php index 4ffc4b1437f4..d1eb1671066a 100644 --- a/tests/phpunit/api/v3/MembershipTypeTest.php +++ b/tests/phpunit/api/v3/MembershipTypeTest.php @@ -184,6 +184,24 @@ public function testMemberTypePeriodTypeRequired($version) { ]); } + /** + * Test that auto renew = TRUE still works post schema change. + * + * https://lab.civicrm.org/dev/rc/-/issues/14 + */ + public function testCreateMembershipTypeAutoRenewBool(): void { + $this->callAPISuccess('MembershipType', 'create', [ + 'member_of_contact_id' => 1, + 'financial_type_id' => 'Member Dues', + 'duration_unit' => 'year', + 'duration_interval' => 1, + 'period_type' => 'rolling', + 'minimum_fee' => 1, + 'name' => 'gen', + 'auto_renew' => TRUE, + ]); + } + /** * Test update. *