CRM-20392: remove cruft code and add unit test
authorPradeep Nayak <pradpnayak@gmail.com>
Sat, 29 Apr 2017 09:28:39 +0000 (14:58 +0530)
committerdeb.monish <monish.deb@jmaconsulting.biz>
Mon, 1 May 2017 06:35:17 +0000 (12:05 +0530)
templates/CRM/Contribute/Form/AdditionalPayment.tpl
tests/phpunit/CRM/Contribute/Form/ContributionTest.php

index 93c93b6211cc9b3d1c54f9c6aef4fd5debe0b953..04da3159fc887903710b03a06f8530a609b88d8a 100644 (file)
         });
 
         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( );
           }
         }
 
index 8706bb12182988fa96a95cb510cd87f5ef5fdbd1..1f838839b5e290565af7264690b18d2a5b0858fa 100644 (file)
@@ -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.
    */