From 9beed6cf5b86c7875ca24e626c3186e2258ae539 Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Sat, 29 Apr 2017 14:58:39 +0530 Subject: [PATCH] CRM-20392: remove cruft code and add unit test --- .../CRM/Contribute/Form/AdditionalPayment.tpl | 32 ++---------- .../CRM/Contribute/Form/ContributionTest.php | 52 ++++++++++++++++++- 2 files changed, 54 insertions(+), 30 deletions(-) diff --git a/templates/CRM/Contribute/Form/AdditionalPayment.tpl b/templates/CRM/Contribute/Form/AdditionalPayment.tpl index 93c93b6211..04da3159fc 100644 --- a/templates/CRM/Contribute/Form/AdditionalPayment.tpl +++ b/templates/CRM/Contribute/Form/AdditionalPayment.tpl @@ -182,37 +182,11 @@ }); function checkEmailDependancies() { - if ($('#is_email_receipt', $form).attr('checked')) { - $('#fromEmail, #notice', $form).show(); - $('#receiptDate', $form).hide(); + if ($('#is_email_receipt', $form).prop('checked')) { + $('#fromEmail', $form).show(); } else { - $('#fromEmail, #notice', $form).hide( ); - $('#receiptDate', $form).show(); - } - } - - // bind first click of accordion header to load crm-accordion-body with snippet - $('#adjust-option-type', $form).hide(); - $('.crm-ajax-accordion .crm-accordion-header', $form).one('click', function() { - loadPanes($(this).attr('id')); - }); - $('.crm-ajax-accordion:not(.collapsed) .crm-accordion-header', $form).each(function(index) { - loadPanes($(this).attr('id')); - }); - // load panes function call for snippet based on id of crm-accordion-header - function loadPanes(id) { - var url = "{/literal}{crmURL p='civicrm/payment/add' q='formType=' h=0}{literal}" + id; - {/literal} - {if $contributionMode} - url += "&mode={$contributionMode}"; - {/if} - {if $qfKey} - url += "&qfKey={$qfKey}"; - {/if} - {literal} - if (!$('div.'+ id, $form).html()) { - CRM.loadPage(url, {target: $('div.' + id, $form)}); + $('#fromEmail', $form).hide( ); } } diff --git a/tests/phpunit/CRM/Contribute/Form/ContributionTest.php b/tests/phpunit/CRM/Contribute/Form/ContributionTest.php index 8706bb1218..1f838839b5 100644 --- a/tests/phpunit/CRM/Contribute/Form/ContributionTest.php +++ b/tests/phpunit/CRM/Contribute/Form/ContributionTest.php @@ -449,7 +449,6 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { 'city' => 'Vancouver', 'location_type_id' => 5, ), 0); - } /** @@ -779,6 +778,57 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 ); } + /** + * Test the submit function that completes the partially paid payment using Credit Card + */ + public function testPartialPaymentWithCreditCard() { + // create a partially paid contribution by using back-office form + $form = new CRM_Contribute_Form_Contribution(); + $form->testSubmit( + array( + 'total_amount' => 50, + 'financial_type_id' => 1, + 'receive_date' => '04/21/2015', + 'receive_date_time' => '11:27PM', + 'contact_id' => $this->_individualId, + 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), + 'check_number' => substr(sha1(rand()), 0, 7), + 'billing_city-5' => 'Vancouver', + 'contribution_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Partially paid'), + ), CRM_Core_Action::ADD + ); + + $contribution = $this->callAPISuccessGetSingle('Contribution', array()); + $this->assertNotEmpty($contribution); + $this->assertEquals('Partially paid', $contribution['contribution_status']); + // pay additional amount by using Credit Card + $form = new CRM_Contribute_Form_AdditionalPayment(); + $form->testSubmit(array( + 'contribution_id' => $contribution['id'], + 'contact_id' => $this->_individualId, + 'total_amount' => 50, + 'currency' => 'USD', + 'financial_type_id' => 1, + 'receive_date' => '04/21/2015', + 'receive_date_time' => '11:27PM', + 'contact_id' => $this->_individualId, + 'payment_instrument_id' => array_search('Credit card', $this->paymentInstruments), + 'payment_processor_id' => $this->paymentProcessorID, + 'credit_card_exp_date' => array('M' => 5, 'Y' => 2025), + 'credit_card_number' => '411111111111111', + 'cvv2' => 234, + 'credit_card_type' => 'Visa', + 'billing_city-5' => 'Vancouver', + 'billing_state_province_id-5' => 1059, + 'billing_postal_code-5' => 1321312, + 'billing_country_id-5' => 1228, + 'trxn_date' => '2017-04-11 13:05:11', + ), 'live'); + $contribution = $this->callAPISuccessGetSingle('Contribution', array()); + $this->assertNotEmpty($contribution); + $this->assertEquals('Completed', $contribution['contribution_status']); + } + /** * Test the submit function for FT with tax. */ -- 2.25.1