diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 0e235f5f1104..c94874f3cfb2 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -1916,6 +1916,9 @@ public static function transitionComponents($params, $processContributionObject //update related Memberships. CRM_Member_BAO_Membership::updateRelatedMemberships($membership->id, $formattedParams); + //CRM-19678: No Membership Renewal Activity is created when a Pay Later is set to Completed + CRM_Activity_BAO_Activity::addActivity($membership, 'Membership Renewal', $membership->contact_id); + $updateResult['membership_end_date'] = CRM_Utils_Date::customFormat($dates['end_date'], '%B %E%f, %Y' ); diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index 31667ac21e03..757073e6fec9 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -1404,6 +1404,7 @@ public function testSubmit($params, $action, $creditCardMode = NULL) { 'id' => $params['id'], )); $this->_id = $params['id']; + $this->_values = $existingContribution; } else { $existingContribution = array(); diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 1fd3c05d1d77..fddc7eff54f9 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -1362,7 +1362,7 @@ public function participantCreate($params) { * @return int * Id Payment Processor */ - public function processorCreate() { + public function processorCreate($params = array()) { $processorParams = array( 'domain_id' => 1, 'name' => 'Dummy', @@ -1377,6 +1377,7 @@ public function processorCreate() { 'sequential' => 1, 'payment_instrument_id' => 'Debit Card', ); + $processorParams = array_merge($processorParams, $params); $processor = $this->callAPISuccess('PaymentProcessor', 'create', $processorParams); return $processor['id']; } diff --git a/tests/phpunit/api/v3/ContributionTest.php b/tests/phpunit/api/v3/ContributionTest.php index 440e8506b8ee..dc17db24c7fa 100644 --- a/tests/phpunit/api/v3/ContributionTest.php +++ b/tests/phpunit/api/v3/ContributionTest.php @@ -2497,6 +2497,65 @@ public function testCompleteTransactionMembershipPriceSet() { $this->cleanUpAfterPriceSets(); } + /** + * Test if renewal activity is create after changing Pending contribution to Completed via offline + */ + public function testPendingToCompleteContribution() { + $contributionPage = $this->createPriceSetWithPage('membership'); + $stateOfGrace = $this->callAPISuccess('MembershipStatus', 'getvalue', array( + 'name' => 'Grace', + 'return' => 'id') + ); + $this->setUpPendingContribution($this->_ids['price_field_value'][0]); + $this->callAPISuccess('membership', 'getsingle', array('id' => $this->_ids['membership'])); + + // change pending contribution to completed + $form = new CRM_Contribute_Form_Contribution(); + $error = FALSE; + $form->_params = array( + 'id' => $this->_ids['contribution'], + 'total_amount' => 20, + 'net_amount' => 20, + 'fee_amount' => 0, + 'financial_type_id' => 1, + 'receive_date' => '04/21/2015', + 'receive_date_time' => '11:27PM', + 'contact_id' => $this->_individualId, + 'contribution_status_id' => 1, + 'billing_middle_name' => '', + 'billing_last_name' => 'Adams', + 'billing_street_address-5' => '790L Lincoln St S', + 'billing_city-5' => 'Maryknoll', + 'billing_state_province_id-5' => 1031, + 'billing_postal_code-5' => 10545, + 'billing_country_id-5' => 1228, + 'frequency_interval' => 1, + 'frequency_unit' => 'month', + 'installments' => '', + 'hidden_AdditionalDetail' => 1, + 'hidden_Premium' => 1, + 'from_email_address' => '"civi45" ', + 'receipt_date' => '', + 'receipt_date_time' => '', + 'payment_processor_id' => $this->paymentProcessorID, + 'currency' => 'USD', + 'contribution_page_id' => $this->_ids['contribution_page'], + 'contribution_mode' => 'membership', + 'source' => 'Membership Signup and Renewal', + ); + try { + $form->testSubmit($form->_params, CRM_Core_Action::UPDATE); + } + catch (Civi\Payment\Exception\PaymentProcessorException $e) { + $error = TRUE; + } + $activity = $this->callAPISuccess('Activity', 'get', array( + 'activity_type_id' => 'Membership Renewal', + 'source_record_id' => $this->_ids['contribution'], + )); + $this->assertEquals(1, $activity['count']); + } + /** * Test membership is renewed when transaction completed. */ @@ -2596,7 +2655,7 @@ public function setUpPendingContribution($priceFieldValueID) { 'domain_id' => 1, 'contact_id' => $contactID, 'receive_date' => date('Ymd'), - 'total_amount' => 100.00, + 'total_amount' => 20.00, 'financial_type_id' => 1, 'payment_instrument_id' => 'Credit Card', 'non_deductible_amount' => 10.00,