CRM-19126 add test to prove that tax_amount gets reset on the complete transaction...
authorSeamus Lee <seamuslee001@gmail.com>
Mon, 1 Aug 2016 10:27:04 +0000 (20:27 +1000)
committerSeamus Lee <seamuslee001@gmail.com>
Mon, 1 Aug 2016 10:28:24 +0000 (20:28 +1000)
tests/phpunit/api/v3/ContributionTest.php

index b2fd05a1bcd418e65b26bb4f700e50fd3d239380..f03f459106e5aa64e3cd5c165726ff5b35bbf693 100644 (file)
@@ -1758,6 +1758,47 @@ class api_v3_ContributionTest extends CiviUnitTestCase {
     $this->assertEquals('99.44', $contribution['net_amount']);
   }
 
+  /**
+   * CRM-19126 Add test to verify when complete transaction is called tax amount is not changed
+   */
+  public function testCheckTaxAmount() {
+    $contact = $this->createLoggedInUser();
+    $financialType = $this->callAPISuccess('financial_type', 'create', array(
+      'name' => 'Test taxable financial Type',
+      'is_reserved' => 0,
+      'is_active' => 1,
+    ));
+    $financialAccount = $this->callAPISuccess('financial_account', 'create', array(
+       'name' => 'Test Tax financial account ',
+       'contact_id' => $contact,
+       'financial_account_type_id' => 2,
+       'is_tax' => 1,
+       'tax_rate' => 5.00,
+       'is_reserved' => 0,
+       'is_active' => 1,
+       'is_default' => 0,
+    ));
+    $financialTypeId = $financialType['id'];
+    $financialAccountId = $financialAccount['id'];
+    $financialAccountParams = array(
+      'entity_table' => 'civicrm_financial_type',
+      'entity_id' => $financialTypeId,
+      'account_relationship' => 10,
+      'financial_account_id' => $financialAccountId,
+    );
+    $financialRelation = CRM_Financial_BAO_FinancialTypeAccount::add($financialAccountParams);
+    $taxRates = CRM_Core_PseudoConstant::getTaxRates();
+    $params = array_merge($this->_params, array('contribution_status_id' => 2, 'financial_type_id' => $financialTypeId));
+    $contribution = $this->callAPISuccess('contribution', 'create', $params);
+    $contribution1 = $this->callAPISuccess('contribution', 'get', array('id' => $contribution['id'], 'return' => 'tax_amount', 'sequential' => 1));
+    $this->callAPISuccess('contribution', 'completetransaction', array(
+       'id' => $contribution['id'],
+       'trxn_id' => '777788888',
+    ));
+    $contribution2 = $this->callAPISuccess('contribution', 'get', array('id' => $contribution['id'], 'return' => 'tax_amount', 'sequential' => 1));
+    $this->assertEquals($contribution1['values'][0]['tax_amount'], $contribution2['values'][0]['tax_amount']);
+  }
+
   /**
    * Test repeat contribution successfully creates line items.
    */