Make period_type mandatory for MembershipType
authoreileen <emcnaughton@wikimedia.org>
Mon, 7 Sep 2020 02:03:50 +0000 (14:03 +1200)
committereileen <emcnaughton@wikimedia.org>
Wed, 9 Sep 2020 20:06:52 +0000 (08:06 +1200)
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

CRM/Core/DAO/CustomField.php
CRM/Member/DAO/MembershipType.php
CRM/Upgrade/Incremental/sql/5.31.alpha1.mysql.tpl
Civi/Test/Api3TestTrait.php
tests/phpunit/CiviTest/CiviUnitTestCase.php
tests/phpunit/api/v3/MembershipTypeTest.php
tests/phpunit/api/v3/PaymentProcessorTypeTest.php
xml/schema/Member/MembershipType.xml

index 6cae23bea07644c24a54dfb98f8802bf35e4cf49..698d34a4956dcf58c98788594edcc6003ee43d1c 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Generated from xml/schema/CRM/Core/CustomField.xml
  * DO NOT EDIT.  Generated by CRM_Core_CodeGen
- * (GenCodeChecksum:1acb9b3538bd3005b99e6af6d9ec062f)
+ * (GenCodeChecksum:4ded3c0d1a8e34502a5957ee74c4480a)
  */
 
 /**
index 4b1d6ce509eb7a4ff4eee81e0c9afe5c163b364d..4f5cad0e296afe03c4a5ac7cca986c2cbb1af917 100644 (file)
@@ -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',
index 663ae49a267804eb8f38fbc9a24ce949d4faf97d..e87793f051519cff21821b95923ae1cf8b9bd755 100644 (file)
@@ -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.'
+
index ed3557babe9622f3f507d4d54f38c29cd6f20531..2ce8d75d0e58730d7bd6693a9acf3db21391c11e 100644 (file)
@@ -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) {
index cf2f3fbffb1452d1dea53b0971204970615be395..0930fb4f1e50f38e59a6873bfc92841daf9ba0ac 100644 (file)
@@ -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');
 
index d20a639b6f167a1268d1f91f41b0db94ed0a3bf5..cb25518fc8c4df490c505eebb66a4ac899f25ef8 100644 (file)
@@ -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',
index 13b0362a51143dd4bb6cb7f38ad78d3839e140ce..cd5760a5ac7314c3a7c9c5b4cb01ad5c976191f4 100644 (file)
@@ -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,
index cd528adaf26fc8d599c30550e5c14fc0405259e0..fbae25e8d494a3ffbcd7375dac60ce560f09f22a 100644 (file)
     <title>Membership Type Plan</title>
     <type>varchar</type>
     <length>8</length>
+    <required>true</required>
     <comment>Rolling membership period starts on signup date. Fixed membership periods start on fixed_period_start_day.</comment>
     <html>
       <type>Select</type>