Skip to content

Commit

Permalink
Make period_type mandatory for MembershipType
Browse files Browse the repository at this point in the history
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
  • Loading branch information
eileenmcnaughton committed Sep 7, 2020
1 parent 907d604 commit 5748e72
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 28 deletions.
2 changes: 1 addition & 1 deletion CRM/Core/DAO/CustomField.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Core/CustomField.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:1acb9b3538bd3005b99e6af6d9ec062f)
* (GenCodeChecksum:4ded3c0d1a8e34502a5957ee74c4480a)
*/

/**
Expand Down
3 changes: 2 additions & 1 deletion CRM/Member/DAO/MembershipType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Member/MembershipType.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:713057d2c1a6dcb6cbd6449b8934d28c)
* (GenCodeChecksum:7c5220444512f1aa499454e977f27814)
*/

/**
Expand Down Expand Up @@ -376,6 +376,7 @@ public static function &fields() {
'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',
Expand Down
3 changes: 3 additions & 0 deletions CRM/Upgrade/Incremental/sql/5.31.alpha1.mysql.tpl
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
{* file to handle db changes in 5.31.alpha1 during upgrade *}
{* 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.'
3 changes: 3 additions & 0 deletions Civi/Test/Api3TestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,9 @@ public function runApi4Legacy($v3Entity, $v3Action, $v3Params = []) {
$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) {
Expand Down
24 changes: 11 additions & 13 deletions tests/phpunit/CiviTest/CiviUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -704,19 +704,17 @@ public function relationshipTypeDelete($relationshipTypeID) {
* @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');

Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/api/v3/MembershipTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public function testCreateWithoutDomainId($version) {
*
* @param bool $version
*/
public function testMemberTypePeriodiTypeRequired($version) {
public function testMemberTypePeriodTypeRequired($version) {
$this->_apiversion = $version;
$this->callAPIFailure('MembershipType', 'create', [
'domain_id' => 'Default Domain Name',
Expand Down
38 changes: 26 additions & 12 deletions tests/phpunit/api/v3/PaymentProcessorTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ public function testPaymentProcessorTypeCreateWithoutName($version) {

/**
* Create payment processor type.
*
* @dataProvider versionThreeAndFour
*
* @param int $version
*/
public function testPaymentProcessorTypeCreate($version) {
$this->_apiversion = $version;
Expand All @@ -60,7 +63,7 @@ public function testPaymentProcessorTypeCreate($version) {
'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
Expand All @@ -84,17 +87,22 @@ public function testPaymentProcessorTypeCreateExample() {

/**
* 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;
Expand All @@ -110,37 +118,43 @@ public function testPaymentProcessorTypeDeleteWithoutRequired($version) {

/**
* 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']);
}

Expand All @@ -151,7 +165,7 @@ public function testPaymentProcessorTypeUpdateEmpty($version) {
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,
Expand Down
1 change: 1 addition & 0 deletions xml/schema/Member/MembershipType.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
<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>
Expand Down

0 comments on commit 5748e72

Please sign in to comment.