diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 53b6448fb09b..8416ad934100 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -1835,13 +1835,13 @@ public static function transitionComponents($params, $processContributionObject // only pending contribution related object processed. if ($previousContriStatusId && - ($previousContriStatusId != array_search('Pending', $contributionStatuses)) + !in_array($contributionStatuses[$previousContriStatusId], array('Pending', 'Partially paid')) ) { // this is case when we already processed contribution object. return $updateResult; } elseif (!$previousContriStatusId && - $contribution->contribution_status_id != array_search('Pending', $contributionStatuses) + !in_array($contributionStatuses[$contribution->contribution_status_id], array('Pending', 'Partially paid')) ) { // this is case when we are going to process contribution object later. return $updateResult; diff --git a/tests/phpunit/CRM/Member/Form/MembershipTest.php b/tests/phpunit/CRM/Member/Form/MembershipTest.php index 18cf759ed358..084e0a4a2219 100644 --- a/tests/phpunit/CRM/Member/Form/MembershipTest.php +++ b/tests/phpunit/CRM/Member/Form/MembershipTest.php @@ -865,6 +865,46 @@ public function testSubmitPayLaterWithBilling() { )); } + /** + * Test if membership is updated to New after contribution + * is updated from Partially paid to Completed. + */ + public function testSubmitUpdateMembershipFromPartiallyPaid() { + $memStatus = CRM_Member_BAO_Membership::buildOptions('status_id', 'validate'); + + //Perform a pay later membership contribution. + $this->testSubmitPayLaterWithBilling(); + $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId)); + $this->assertEquals($membership['status_id'], array_search('Pending', $memStatus)); + $contribution = $this->callAPISuccessGetSingle('MembershipPayment', array( + 'membership_id' => $membership['id'], + )); + + //Update contribution to Partially paid. + $prevContribution = $this->callAPISuccess('Contribution', 'create', array( + 'id' => $contribution['contribution_id'], + 'contribution_status_id' => 'Partially paid', + )); + $prevContribution = $prevContribution['values'][1]; + + //Complete the contribution from offline form. + $form = new CRM_Contribute_Form_Contribution(); + $submitParams = array( + 'id' => $contribution['contribution_id'], + 'contribution_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed'), + 'price_set_id' => 0, + ); + $fields = array('total_amount', 'net_amount', 'financial_type_id', 'receive_date', 'contact_id', 'payment_instrument_id'); + foreach ($fields as $val) { + $submitParams[$val] = $prevContribution[$val]; + } + $form->testSubmit($submitParams, CRM_Core_Action::UPDATE); + + //Check if Membership is updated to New. + $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId)); + $this->assertEquals($membership['status_id'], array_search('New', $memStatus)); + } + /** * Test the submit function of the membership form. */