From: Jitendra Purohit Date: Fri, 9 Apr 2021 14:40:37 +0000 (+0530) Subject: Fix soft credit on creating membership using backend form X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=3a210c7bf2be47e49b5e361194270f2ae94d6dd4;p=civicrm-core.git Fix soft credit on creating membership using backend form --- diff --git a/CRM/Member/Form/Membership.php b/CRM/Member/Form/Membership.php index a074540ff9..18ec26e81e 100644 --- a/CRM/Member/Form/Membership.php +++ b/CRM/Member/Form/Membership.php @@ -1295,7 +1295,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 e649cd86ec..1c37f7a0d6 100644 --- a/tests/phpunit/CRM/Member/Form/MembershipTest.php +++ b/tests/phpunit/CRM/Member/Form/MembershipTest.php @@ -903,6 +903,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. *