CRM-19585, added test for createProportionalEntry()
authorPradeep Nayak <pradpnayak@gmail.com>
Tue, 3 Jan 2017 13:33:39 +0000 (19:03 +0530)
committerPradeep Nayak <pradpnayak@gmail.com>
Tue, 3 Jan 2017 13:33:39 +0000 (19:03 +0530)
----------------------------------------
* CRM-19585: Sales tax issue
  https://issues.civicrm.org/jira/browse/CRM-19585

tests/phpunit/CRM/Contribute/BAO/ContributionTest.php

index c2b0545f5a8e14296176fb7d9249e5cde193b3a4..d859c61fd4627e6b14a396edced825527e7ae20d 100644 (file)
@@ -1084,4 +1084,64 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2";
     $this->assertTrue(($salesTaxFinancialAccount == $expectedResult), 'Function returned wrong values.');
   }
 
+  /**
+   * Test for function createProportionalEntry().
+   */
+  public function testcreateProportionalEntry() {
+    $contactId = $this->individualCreate();
+    $this->enableTaxAndInvoicing();
+    $financialType = $this->createFinancialType();
+    $financialAccount = $this->relationForFinancialTypeWithFinancialAccount($financialType['id']);
+    $form = new CRM_Contribute_Form_Contribution();
+
+    $form->testSubmit(array(
+       'total_amount' => 100,
+        'financial_type_id' => $financialType['id'],
+        'receive_date' => '04/21/2015',
+        'receive_date_time' => '11:27PM',
+        'contact_id' => $contactId,
+        'contribution_status_id' => 1,
+        'price_set_id' => 0,
+      ),
+      CRM_Core_Action::ADD
+    );
+    $contribution = $this->callAPISuccessGetSingle('Contribution',
+      array(
+        'contact_id' => $contactId,
+        'return' => array('tax_amount', 'total_amount'),
+      )
+    );
+    $params = array(
+      'total_amount' => 55,
+      'to_financial_account_id' => $financialAccount->financial_account_id,
+      'payment_instrument_id' => 1,
+      'trxn_date' => date('Ymd'),
+      'status_id' => 1,
+    );
+    $financialTrxn = $this->callAPISuccess('FinancialTrxn', 'create', $params);
+    $params = array(
+      'amount' => 50,
+      'entity_table' => 'civicrm_contribution',
+      'entity_id' => $contribution['id'],
+      'financial_trxn_id' => $financialTrxn['id'],
+    );
+    $this->callAPISuccess('EntityFinancialTrxn', 'create', $params);
+    $entityParams = array(
+      'contribution_total_amount' => $contribution['total_amount'],
+      'trxn_total_amount' => 55,
+      'line_item_amount' => 100,
+    );
+    $previousLineItem = CRM_Financial_BAO_FinancialItem::getPreviousFinancialItem($contribution['id']);
+    $eftParams = array(
+      'entity_table' => 'civicrm_financial_item',
+      'entity_id' => $previousLineItem->id,
+      'financial_trxn_id' => $financialTrxn['id'],
+    );
+    CRM_Contribute_BAO_Contribution::createProportionalEntry($entityParams, $eftParams);
+    $trxnTestArray = array_merge($eftParams, array(
+      'amount' => 50,
+    ));
+    $entityFinancialTrxn = $this->callAPISuccessGetSingle('EntityFinancialTrxn', $eftParams, $trxnTestArray);
+  }
+
 }