Resolve immediate issues with test & add checks for mail content (since that function...
authoreileen <emcnaughton@wikimedia.org>
Thu, 9 Mar 2017 06:10:01 +0000 (19:10 +1300)
committereileen <emcnaughton@wikimedia.org>
Thu, 9 Mar 2017 06:17:39 +0000 (19:17 +1300)
CRM/Contribute/Form/Contribution.php
tests/phpunit/CRM/Contribute/Form/ContributionTest.php

index 441ccff58004dfade1a1685326a3d0092fb36347..b85fe335bfff5892c489d4bee02d745c972a8b82 100644 (file)
@@ -283,10 +283,11 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
       else {
         $lineItem = CRM_Price_BAO_LineItem::getLineItems($this->_id, 'contribution', 1, TRUE, TRUE);
       }
+      // wtf?
       empty($lineItem) ? NULL : $this->_lineItems[] = $lineItem;
     }
 
-    $this->assign('lineItem', empty($this->_lineItems) ? FALSE : $this->_lineItems);
+    $this->assign('lineItem', empty($lineItem) ? FALSE : $lineItem);
 
     // Set title
     if ($this->_mode && $this->_id) {
@@ -1432,7 +1433,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
    * @throws \Exception
    */
   protected function submit($submittedValues, $action, $pledgePaymentID) {
-    $softIDs = array();
+
     $pId = $contribution = $isRelatedId = FALSE;
     $this->_params = $submittedValues;
     $this->beginPostProcess();
@@ -1797,13 +1798,8 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
     }
     $taxRate = array();
     $getTaxDetails = FALSE;
-    if ($action & CRM_Core_Action::ADD) {
-      $line = $lineItem;
-    }
-    elseif ($action & CRM_Core_Action::UPDATE) {
-      $line = $this->_lineItems;
-    }
-    foreach ($line as $key => $value) {
+
+    foreach ($lineItem as $key => $value) {
       foreach ($value as $v) {
         if (isset($taxRate[(string) CRM_Utils_Array::value('tax_rate', $v)])) {
           $taxRate[(string) $v['tax_rate']] = $taxRate[(string) $v['tax_rate']] + CRM_Utils_Array::value('tax_amount', $v);
index dee44237bb8053a02769621d2bf9fc055b3d5acc..83b92d807e8ccdbd381e05c1c1bfcd7e86f269fb 100644 (file)
@@ -851,8 +851,12 @@ Price Field - Price Field 1        1   $ 100.00      $ 100.00
     $this->assertTrue(empty($lineItem['tax_amount']));
   }
 
+  /**
+   * Create a contribution & then edit it via backoffice form, checking tax.
+   *
+   * @throws \Exception
+   */
   public function testReSubmitSaleTax() {
-    // KG I need to do an Edit of a View Contribution
     $this->enableTaxAndInvoicing();
     $this->relationForFinancialTypeWithFinancialAccount($this->_financialTypeId);
     $form = new CRM_Contribute_Form_Contribution();
@@ -875,10 +879,12 @@ Price Field - Price Field 1        1   $ 100.00      $ 100.00
         'return' => array('tax_amount', 'total_amount', 'net_amount', 'financial_type_id', 'receive_date', 'payment_instrument_id'),
       )
     );
+    $this->assertEquals(110, $contribution['total_amount']);
+    $this->assertEquals(10, $contribution['tax_amount']);
 
-    $test = 1;
+    $mut = new CiviMailUtils($this, TRUE);
     $form->testSubmit(array(
-      'contribution_id' => $contribution['id'],
+      'id' => $contribution['id'],
       'total_amount' => $contribution['total_amount'],
       'net_amount' => $contribution['net_amount'],
       'tax_amount' => $contribution['tax_amount'],
@@ -887,6 +893,9 @@ Price Field - Price Field 1        1   $ 100.00      $ 100.00
       'payment_instrument_id' => $contribution['payment_instrument_id'],
       'price_set_id' => 0,
       'check_number' => 12345,
+      'contribution_status_id' => 1,
+      'is_email_receipt' => 1,
+      'from_email_address' => 'demo@example.com',
     ),
       CRM_Core_Action::UPDATE
     );
@@ -895,7 +904,18 @@ Price Field - Price Field 1        1   $ 100.00      $ 100.00
         'contact_id' => $this->_individualId,
       )
     );
+    $strings = array(
+      'Financial Type: Donation',
+      'Amount before Tax : $ 110.00',
+      'Sales Tax 10.00% : $ 11.00',
+      'Total Tax Amount : $ 11.00',
+      'Total Amount : $ 121.00',
+      'Date Received: April 21st, 2015',
+      'Paid By: Check',
+      'Check Number: 12345',
+    );
 
+    $mut->checkMailLog($strings);
     $this->assertEquals(110, $contribution['total_amount']);
     $this->assertEquals(10, $contribution['tax_amount']);
     $this->callAPISuccessGetCount('FinancialTrxn', array(), 1);