tests/phpunit/** - Remove unnecessary "require_once" statements
[civicrm-core.git] / tests / phpunit / CRM / Core / BAO / FinancialTrxnTest.php
index c93236bd0db00c104ccea46141153fc12c201b37..cd60b6b42f1fd7f7f39a526bf8394e8a86f2da45 100644 (file)
@@ -25,8 +25,6 @@
  +--------------------------------------------------------------------+
  */
 
-require_once 'CiviTest/CiviUnitTestCase.php';
-
 /**
  * Class CRM_Core_BAO_FinancialTrxnTest
  */
@@ -66,4 +64,49 @@ class CRM_Core_BAO_FinancialTrxnTest extends CiviUnitTestCase {
     $this->assertEquals($result, 10, 'Verify financial trxn total_amount.');
   }
 
+  /**
+   * Test getTotalPayments function.
+   */
+  public function testGetTotalPayments() {
+    $contactId = $this->individualCreate();
+
+    $params = array(
+      'contact_id' => $contactId,
+      'currency' => 'USD',
+      'financial_type_id' => 1,
+      'contribution_status_id' => 2,
+      'payment_instrument_id' => 1,
+      'source' => 'STUDENT',
+      'is_pay_later' => 1,
+      'receive_date' => '20080522000000',
+      'receipt_date' => '20080522000000',
+      'non_deductible_amount' => 0.00,
+      'total_amount' => 200.00,
+      'fee_amount' => 5,
+      'net_amount' => 195,
+      'trxn_id' => '22ereerwwe4444yy',
+      'invoice_id' => '86ed39e9e9yy6ef6541621ce0eafe7eb81',
+      'thankyou_date' => '20080522',
+    );
+
+    $contribution = CRM_Contribute_BAO_Contribution::create($params);
+
+    $this->assertEquals($params['trxn_id'], $contribution->trxn_id);
+    $this->assertEquals($contactId, $contribution->contact_id);
+
+    $totalPaymentAmount = CRM_Core_BAO_FinancialTrxn::getTotalPayments($contribution->id);
+    $this->assertEquals(0, $totalPaymentAmount, 'Amount not matching.');
+    //update contribution amount
+    $params['id'] = $contribution->id;
+    $params['contribution_status_id'] = 1;
+
+    $contribution = CRM_Contribute_BAO_Contribution::create($params);
+
+    $this->assertEquals($params['trxn_id'], $contribution->trxn_id);
+    $this->assertEquals($params['contribution_status_id'], $contribution->contribution_status_id);
+
+    $totalPaymentAmount = CRM_Core_BAO_FinancialTrxn::getTotalPayments($contribution->id);
+    $this->assertEquals('200.00', $totalPaymentAmount, 'Amount not matching.');
+  }
+
 }