CRM-19585, moved set of code into function anad added test for getLastFinancialItemIds()
authorPradeep Nayak <pradpnayak@gmail.com>
Tue, 3 Jan 2017 13:53:27 +0000 (19:23 +0530)
committerPradeep Nayak <pradpnayak@gmail.com>
Tue, 3 Jan 2017 13:53:27 +0000 (19:23 +0530)
----------------------------------------
* CRM-19585: Sales tax issue
  https://issues.civicrm.org/jira/browse/CRM-19585

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

index d859c61fd4627e6b14a396edced825527e7ae20d..a1e68638dee3d9e6bde95d7308d15e0e57a8437f 100644 (file)
@@ -1088,29 +1088,7 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2";
    * 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'),
-      )
-    );
+    $contribution = $this->createContributionWithTax();
     $params = array(
       'total_amount' => 55,
       'to_financial_account_id' => $financialAccount->financial_account_id,
@@ -1144,4 +1122,47 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2";
     $entityFinancialTrxn = $this->callAPISuccessGetSingle('EntityFinancialTrxn', $eftParams, $trxnTestArray);
   }
 
+  /**
+   * Test for function getLastFinancialItemIds().
+   */
+  public function testgetLastFinancialItemIds() {
+    $contribution = $this->createContributionWithTax();
+    list($ftIds, $taxItems) = CRM_Contribute_BAO_Contribution::getLastFinancialItemIds($contribution['id']);
+    $this->assertEquals(count($ftIds), 1, 'Invalid count.');
+    $this->assertEquals(count($taxItems), 1, 'Invalid count.');
+    foreach ($taxItems as $value) {
+      $this->assertEquals($value['amount'], 10, 'Invalid tax amount.');
+    }
+  }
+
+  /**
+   * Function to create contribution with tax.
+   */
+  public function createContributionWithTax() {
+    $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'),
+      )
+    );
+    return $contribution;
+  }
+
 }