From 80f4252bd976c53b7993d59ac69a4f39dc370061 Mon Sep 17 00:00:00 2001 From: Jitendra Purohit Date: Fri, 9 Apr 2021 20:10:37 +0530 Subject: [PATCH] Fix soft credit on creating membership using backend form --- CRM/Member/Form/Membership.php | 2 +- .../CRM/Member/Form/MembershipTest.php | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/CRM/Member/Form/Membership.php b/CRM/Member/Form/Membership.php index 5a1c37eff2..7e0bd64505 100644 --- a/CRM/Member/Form/Membership.php +++ b/CRM/Member/Form/Membership.php @@ -1410,7 +1410,7 @@ DESC limit 1"); $membershipParams = array_merge($params, $membershipTypeValues[$lineItemValues['membership_type_id']]); if (!empty($softParams)) { - $membershipParams['soft_credit'] = $softParams; + $params['soft_credit'] = $softParams; } unset($membershipParams['contribution_status_id']); $membershipParams['skipLineItem'] = TRUE; diff --git a/tests/phpunit/CRM/Member/Form/MembershipTest.php b/tests/phpunit/CRM/Member/Form/MembershipTest.php index d3591809b4..5d140290bc 100644 --- a/tests/phpunit/CRM/Member/Form/MembershipTest.php +++ b/tests/phpunit/CRM/Member/Form/MembershipTest.php @@ -887,6 +887,43 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { } } + /** + * Test membership with soft credits. + */ + public function testMembershipSoftCredit() { + $this->_softIndividualId = $this->individualCreate(); + + $form = $this->getForm(); + $form->preProcess(); + $this->createLoggedInUser(); + $params = $this->getBaseSubmitParams(); + unset($params['auto_renew'], $params['is_recur']); + $params['record_contribution'] = TRUE; + $params['soft_credit_type_id'] = $this->callAPISuccessGetValue('OptionValue', [ + 'return' => "value", + 'name' => "Gift", + 'option_group_id' => "soft_credit_type", + ]); + $params['soft_credit_contact_id'] = $this->_softIndividualId; + $form->_contactID = $this->_individualId; + // $form->_mode = 'test'; + $form->testSubmit($params); + // Membership is created on main contact. + $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]); + + // Verify is main contribution is created on soft contact. + $contribution = $this->callAPISuccessGetSingle('Contribution', [ + 'contact_id' => $this->_softIndividualId, + ]); + $this->assertEquals($contribution['soft_credit'][1]['contact_id'], $this->_individualId); + + // Verify if soft credit is created. + $this->callAPISuccessGetSingle('ContributionSoft', [ + 'contact_id' => $this->_individualId, + 'contribution_id' => $contribution['id'], + ]); + } + /** * Test the submit function of the membership form. * -- 2.25.1