From: deb.monish Date: Thu, 19 Oct 2017 09:05:36 +0000 (+0530) Subject: added unittest X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=e3fceb1a30f9c71d01a350352f25a2347c758ea1;p=civicrm-core.git added unittest --- diff --git a/CRM/Contribute/BAO/Contribution/Utils.php b/CRM/Contribute/BAO/Contribution/Utils.php index c245f95a17..f8f5f1e8c1 100644 --- a/CRM/Contribute/BAO/Contribution/Utils.php +++ b/CRM/Contribute/BAO/Contribution/Utils.php @@ -143,7 +143,7 @@ class CRM_Contribute_BAO_Contribution_Utils { $paymentParams['item_name'] = $form->_params['description']; - $paymentParams['qfKey'] = $form->controller->_key; + $paymentParams['qfKey'] = empty($paymentParams['qfKey']) ? $form->controller->_key : $paymentParams['qfKey']; if ($paymentParams['skipLineItem']) { // We are not processing the line item here because we are processing a membership. // Do not continue with contribution processing in this function. diff --git a/tests/phpunit/CRM/Contribute/Form/Contribution/ConfirmTest.php b/tests/phpunit/CRM/Contribute/Form/Contribution/ConfirmTest.php new file mode 100644 index 0000000000..d56cc61cd0 --- /dev/null +++ b/tests/phpunit/CRM/Contribute/Form/Contribution/ConfirmTest.php @@ -0,0 +1,155 @@ +quickCleanUpFinancialEntities(); + } + + /** + * CRM-21200: Test that making online payment for pending contribution doesn't overwite the contribution details + */ + public function testPaynowPayment() { + $contactID = $this->individualCreate(); + $paymentProcessorID = $this->paymentProcessorCreate(array('payment_processor_type_id' => 'Dummy')); + + // create a contribution page which is later used to make pay-later contribution + $result = $this->callAPISuccess('ContributionPage', 'create', array( + 'title' => 'Test Contribution Page', + 'financial_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'financial_type_id', 'Campaign Contribution'), + 'currency' => 'USD', + 'financial_account_id' => 1, + 'payment_processor' => $paymentProcessorID, + 'is_active' => 1, + 'is_allow_other_amount' => 1, + 'min_amount' => 20, + 'max_amount' => 2000, + )); + $contributionPageID1 = $result['id']; + // create pending contribution + $contribution = $this->callAPISuccess('Contribution', 'create', array( + 'contact_id' => $contactID, + 'financial_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'financial_type_id', 'Campaign Contribution'), + 'currency' => 'USD', + 'total_amount' => 100.00, + 'contribution_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending'), + 'contribution_page_id' => $contributionPageID1, + 'source' => 'backoffice pending contribution', + )); + + // create a contribution page which is later used to make online payment for pending contribution + $result = $this->callAPISuccess('ContributionPage', 'create', array( + 'title' => 'Test Contribution Page', + 'financial_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'financial_type_id', 'Campaign Contribution'), + 'currency' => 'USD', + 'financial_account_id' => 1, + 'payment_processor' => $paymentProcessorID, + 'is_active' => 1, + 'is_allow_other_amount' => 1, + 'min_amount' => 10, + 'max_amount' => 1000, + )); + $form = new CRM_Contribute_Form_Contribution_Confirm(); + $contributionPageID2 = $result['id']; + $form->_id = $contributionPageID2; + $form->_values = $result['values'][$contributionPageID2]; + $form->_paymentProcessor = array( + 'id' => $paymentProcessorID, + 'billing_mode' => CRM_Core_Payment::BILLING_MODE_FORM, + 'object' => Civi\Payment\System::singleton()->getById($paymentProcessorID), + 'is_recur' => FALSE, + 'payment_instrument_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', 'Credit card'), + ); + $form->_params = array( + 'qfKey' => 'donotcare', + 'contribution_id' => $contribution['id'], + 'credit_card_number' => 4111111111111111, + 'cvv2' => 234, + 'credit_card_exp_date' => array( + 'M' => 2, + 'Y' => 2021, + ), + 'credit_card_type' => 'Visa', + 'email-5' => 'test@test.com', + 'total_amount' => 100.00, + 'payment_processor_id' => $paymentProcessorID, + 'amount' => 100, + 'tax_amount' => 0.00, + 'year' => 2021, + 'month' => 2, + 'currencyID' => 'USD', + 'is_pay_later' => 0, + 'invoiceID' => '6e443672a9bb2198cc12f076aed70e7a', + 'is_quick_config' => 1, + 'description' => $contribution['values'][$contribution['id']]['source'], + 'skipLineItem' => 0, + ); + + $result = CRM_Contribute_BAO_Contribution_Utils::processConfirm($form, + $form->_params, + $contactID, + $form->_values['financial_type_id'], + 0, FALSE + ); + // Based on the processed contribution, complete transaction which update the contribution status based on payment result. + if (!empty($result['contribution'])) { + $this->callAPISuccess('contribution', 'completetransaction', array( + 'id' => $result['contribution']->id, + 'trxn_date' => date('Y-m-d'), + 'payment_processor_id' => $paymentProcessorID, + )); + } + + $contribution = $this->callAPISuccessGetSingle('Contribution', array( + 'id' => $form->_params['contribution_id'], + 'return' => array( + 'contribution_page_id', + 'contribution_status', + 'contribution_source', + ), + )); + + // check that contribution page ID isn't changed + $this->assertEquals($contributionPageID1, $contribution['contribution_page_id']); + // check that paid later information is present in contribution's source + $this->assertRegExp("/Paid later via page ID: $contributionPageID2/", $contribution['contribution_source']); + // check that contribution status is changed to 'Completed' from 'Pending' + $this->assertEquals('Completed', $contribution['contribution_status']); + } + +}