CRM-19585, added test
authorPradeep Nayak <pradpnayak@gmail.com>
Wed, 28 Dec 2016 23:20:16 +0000 (04:50 +0530)
committerPradeep Nayak <pradpnayak@gmail.com>
Wed, 28 Dec 2016 23:21:09 +0000 (04:51 +0530)
----------------------------------------
* CRM-19585: Sales tax issue
  https://issues.civicrm.org/jira/browse/CRM-19585

tests/phpunit/CRM/Contribute/Form/ContributionTest.php
tests/phpunit/CiviTest/CiviUnitTestCase.php

index 6face9658257b5ea058e5745c54d0e22c52f501f..e903d82463a1923490d90b66b93cc5ff3021b08c 100644 (file)
@@ -775,4 +775,39 @@ Price Field - Price Field 1        1   $ 100.00      $ 100.00
     );
   }
 
+  /**
+   * Test the submit function for FT with tax.
+   */
+  public function testSubmitSaleTax() {
+    $this->enableTaxAndInvoicing();
+    $this->relationForFinancialTypeWithFinancialAccount($this->_financialTypeId);
+    $form = new CRM_Contribute_Form_Contribution();
+
+    $form->testSubmit(array(
+       'total_amount' => 100,
+        'financial_type_id' => $this->_financialTypeId,
+        'receive_date' => '04/21/2015',
+        'receive_date_time' => '11:27PM',
+        'contact_id' => $this->_individualId,
+        'payment_instrument_id' => array_search('Check', $this->paymentInstruments),
+        'contribution_status_id' => 1,
+        'price_set_id' => 0,
+      ),
+      CRM_Core_Action::ADD
+    );
+    $contribution = $this->callAPISuccessGetSingle('Contribution',
+      array(
+        'contact_id' => $this->_individualId,
+        'return' => array('tax_amount', 'total_amount'),
+      )
+    );
+    $this->assertEquals(110, $contribution['total_amount']);
+    $this->assertEquals(10, $contribution['tax_amount']);
+    $this->callAPISuccessGetCount('FinancialTrxn', array(), 1);
+    $this->callAPISuccessGetCount('FinancialItem', array(), 2);
+    $lineItem = $this->callAPISuccessGetSingle('LineItem', array('contribution_id' => $contribution['id']));
+    $this->assertEquals(100, $lineItem['line_total']);
+    $this->assertEquals(10, $lineItem['tax_amount']);
+  }
+
 }
index bb661a2ef878ad63192ccac68d3424d75a4876a3..296dc5ec7d3b4994586cb0bf66dbe11c2b0c7fc8 100644 (file)
@@ -3650,6 +3650,32 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
     return Civi::settings()->set('contribution_invoice_settings', $contributeSetting);
   }
 
+  /**
+   * Add Sales Tax relation for financial type with financial account.
+   *
+   * @param int $financialTypeId
+   *
+   * @return obj
+   */
+  protected function relationForFinancialTypeWithFinancialAccount($financialTypeId) {
+    $params = array(
+      'name' => 'Sales tax account ' . substr(sha1(rand()), 0, 4),
+      'financial_account_type_id' => key(CRM_Core_PseudoConstant::accountOptionValues('financial_account_type', NULL, " AND v.name LIKE 'Liability' ")),
+      'is_deductible' => 1,
+      'is_tax' => 1,
+      'tax_rate' => 10,
+      'is_active' => 1,
+    );
+    $account = CRM_Financial_BAO_FinancialAccount::add($params);
+    $entityParams = array(
+      'entity_table' => 'civicrm_financial_type',
+      'account_relationship' => key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Sales Tax Account is' ")),
+      'entity_id' => $financialTypeId,
+      'financial_account_id' => $account->id,
+    );
+    return CRM_Financial_BAO_FinancialTypeAccount::add($entityParams);
+  }
+
   /**
    * Create price set with contribution test for test setup.
    *