From: eileen Date: Mon, 7 Sep 2020 02:03:50 +0000 (+1200) Subject: Make period_type mandatory for MembershipType X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=0524826d4001746250211eb772f6412c5266311a;p=civicrm-core.git Make period_type mandatory for MembershipType We have a test ensuring period_type is mandatory at the api level. However, it isn't for api v4 - the error is a different issue (handling of pseudoconstants when mapping v3 to v4). This fixes that separate issue & declares required to re-fix for v4 --- diff --git a/CRM/Core/DAO/CustomField.php b/CRM/Core/DAO/CustomField.php index 6cae23bea0..698d34a495 100644 --- a/CRM/Core/DAO/CustomField.php +++ b/CRM/Core/DAO/CustomField.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Core/CustomField.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:1acb9b3538bd3005b99e6af6d9ec062f) + * (GenCodeChecksum:4ded3c0d1a8e34502a5957ee74c4480a) */ /** diff --git a/CRM/Member/DAO/MembershipType.php b/CRM/Member/DAO/MembershipType.php index 4b1d6ce509..4f5cad0e29 100644 --- a/CRM/Member/DAO/MembershipType.php +++ b/CRM/Member/DAO/MembershipType.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Member/MembershipType.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:713057d2c1a6dcb6cbd6449b8934d28c) + * (GenCodeChecksum:7c5220444512f1aa499454e977f27814) */ /** @@ -376,6 +376,7 @@ class CRM_Member_DAO_MembershipType extends CRM_Core_DAO { 'type' => CRM_Utils_Type::T_STRING, 'title' => ts('Membership Type Plan'), 'description' => ts('Rolling membership period starts on signup date. Fixed membership periods start on fixed_period_start_day.'), + 'required' => TRUE, 'maxlength' => 8, 'size' => CRM_Utils_Type::EIGHT, 'where' => 'civicrm_membership_type.period_type', diff --git a/CRM/Upgrade/Incremental/sql/5.31.alpha1.mysql.tpl b/CRM/Upgrade/Incremental/sql/5.31.alpha1.mysql.tpl index 663ae49a26..e87793f051 100644 --- a/CRM/Upgrade/Incremental/sql/5.31.alpha1.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/5.31.alpha1.mysql.tpl @@ -3,3 +3,8 @@ {* Remove Country & State special select fields *} UPDATE civicrm_custom_field SET html_type = 'Select' WHERE html_type IN ('Select Country', 'Select State/Province'); + +{* make period_type required - it already is so the update is precautionary *} +UPDATE civicrm_membership_type SET period_type = 'rolling' WHERE period_type IS NULL; +ALTER TABLE civicrm_membership_type MODIFY `period_type` varchar(8) NOT NULL COMMENT 'Rolling membership period starts on signup date. Fixed membership periods start on fixed_period_start_day.' + diff --git a/Civi/Test/Api3TestTrait.php b/Civi/Test/Api3TestTrait.php index ed3557babe..2ce8d75d0e 100644 --- a/Civi/Test/Api3TestTrait.php +++ b/Civi/Test/Api3TestTrait.php @@ -405,6 +405,9 @@ trait Api3TestTrait { $v3Params['option_group.name'] = $v3Params['option_group_id']; unset($v3Params['option_group_id']); } + if (isset($field['pseudoconstant'], $v3Params[$name]) && $field['type'] === \CRM_Utils_Type::T_INT && !is_numeric($v3Params[$name])) { + $v3Params[$name] = \CRM_Core_PseudoConstant::getKey(\CRM_Core_DAO_AllCoreTables::getFullName($v3Entity), $name, $v3Params[$name]); + } } switch ($v3Action) { diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index cf2f3fbffb..0930fb4f1e 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -727,19 +727,17 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { * @return mixed * @throws \CRM_Core_Exception */ - public function paymentProcessorTypeCreate($params = NULL) { - if (is_null($params)) { - $params = [ - 'name' => 'API_Test_PP', - 'title' => 'API Test Payment Processor', - 'class_name' => 'CRM_Core_Payment_APITest', - 'billing_mode' => 'form', - 'is_recur' => 0, - 'is_reserved' => 1, - 'is_active' => 1, - ]; - } - $result = $this->callAPISuccess('payment_processor_type', 'create', $params); + public function paymentProcessorTypeCreate($params = []) { + $params = array_merge([ + 'name' => 'API_Test_PP', + 'title' => 'API Test Payment Processor', + 'class_name' => 'CRM_Core_Payment_APITest', + 'billing_mode' => 'form', + 'is_recur' => 0, + 'is_reserved' => 1, + 'is_active' => 1, + ], $params); + $result = $this->callAPISuccess('PaymentProcessorType', 'create', $params); CRM_Core_PseudoConstant::flush('paymentProcessorType'); diff --git a/tests/phpunit/api/v3/MembershipTypeTest.php b/tests/phpunit/api/v3/MembershipTypeTest.php index d20a639b6f..cb25518fc8 100644 --- a/tests/phpunit/api/v3/MembershipTypeTest.php +++ b/tests/phpunit/api/v3/MembershipTypeTest.php @@ -171,7 +171,7 @@ class api_v3_MembershipTypeTest extends CiviUnitTestCase { * * @param bool $version */ - public function testMemberTypePeriodiTypeRequired($version) { + public function testMemberTypePeriodTypeRequired($version) { $this->_apiversion = $version; $this->callAPIFailure('MembershipType', 'create', [ 'domain_id' => 'Default Domain Name', diff --git a/tests/phpunit/api/v3/PaymentProcessorTypeTest.php b/tests/phpunit/api/v3/PaymentProcessorTypeTest.php index 13b0362a51..cd5760a5ac 100644 --- a/tests/phpunit/api/v3/PaymentProcessorTypeTest.php +++ b/tests/phpunit/api/v3/PaymentProcessorTypeTest.php @@ -48,7 +48,10 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { /** * Create payment processor type. + * * @dataProvider versionThreeAndFour + * + * @param int $version */ public function testPaymentProcessorTypeCreate($version) { $this->_apiversion = $version; @@ -60,7 +63,7 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { 'billing_mode' => 'form', 'is_recur' => 0, ]; - $result = $this->callAPIAndDocument('payment_processor_type', 'create', $params, __FUNCTION__, __FILE__); + $result = $this->callAPIAndDocument('PaymentProcessorType', 'create', $params, __FUNCTION__, __FILE__); $this->assertNotNull($result['values'][0]['id']); // mutate $params to match expected return value @@ -84,17 +87,22 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { /** * Check with empty array. + * * @dataProvider versionThreeAndFour + * + * @param int $version */ public function testPaymentProcessorTypeDeleteEmpty($version) { $this->_apiversion = $version; - $params = []; - $result = $this->callAPIFailure('payment_processor_type', 'delete', $params); + $this->callAPIFailure('PaymentProcessorType', 'delete', []); } /** * Check if required fields are not passed. + * * @dataProvider versionThreeAndFour + * + * @param int $version */ public function testPaymentProcessorTypeDeleteWithoutRequired($version) { $this->_apiversion = $version; @@ -110,37 +118,43 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { /** * Check with incorrect required fields. + * * @dataProvider versionThreeAndFour + * + * @param int $version */ public function testPaymentProcessorTypeDeleteWithIncorrectData($version) { $this->_apiversion = $version; - $result = $this->callAPIFailure('payment_processor_type', 'delete', ['id' => 'abcd']); + $this->callAPIFailure('payment_processor_type', 'delete', ['id' => 'abcd']); } /** * Check payment processor type delete. + * * @dataProvider versionThreeAndFour + * + * @param $version + * + * @throws \CRM_Core_Exception */ public function testPaymentProcessorTypeDelete($version) { $this->_apiversion = $version; - $payProcType = $this->paymentProcessorTypeCreate(); - $params = [ - 'id' => $payProcType, - ]; - - $result = $this->callAPIAndDocument('payment_processor_type', 'delete', $params, __FUNCTION__, __FILE__); + $this->callAPIAndDocument('PaymentProcessorType', 'delete', ['id' => $this->paymentProcessorTypeCreate()], __FUNCTION__, __FILE__); } ///////////////// civicrm_payment_processor_type_update /** * Check with empty array. + * * @dataProvider versionThreeAndFour + * + * @param int $version */ public function testPaymentProcessorTypeUpdateEmpty($version) { $this->_apiversion = $version; $params = []; - $result = $this->callAPIFailure('payment_processor_type', 'create', $params); + $result = $this->callAPIFailure('PaymentProcessorType', 'create', $params); $this->assertContains('name, title, class_name, billing_mode', $result['error_message']); } @@ -151,7 +165,7 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { public function testPaymentProcessorTypeUpdate($version) { $this->_apiversion = $version; // create sample payment processor type. - $this->_ppTypeID = $this->paymentProcessorTypeCreate(NULL); + $this->_ppTypeID = $this->paymentProcessorTypeCreate(); $params = [ 'id' => $this->_ppTypeID, diff --git a/xml/schema/Member/MembershipType.xml b/xml/schema/Member/MembershipType.xml index cd528adaf2..fbae25e8d4 100644 --- a/xml/schema/Member/MembershipType.xml +++ b/xml/schema/Member/MembershipType.xml @@ -145,6 +145,7 @@ Membership Type Plan varchar 8 + true Rolling membership period starts on signup date. Fixed membership periods start on fixed_period_start_day. Select