--CRM-13310, fixed api test
authorPradeep Nayak <pradeep.nayak@webaccess.co.in>
Tue, 3 Dec 2013 12:56:28 +0000 (18:26 +0530)
committerPradeep Nayak <pradeep.nayak@webaccess.co.in>
Tue, 3 Dec 2013 12:56:28 +0000 (18:26 +0530)
tests/phpunit/api/v3/ContributionTest.php

index 767d7f7587064bc564048dc692eff89761404500..bdfcb3c92e85351023d7ca3e61dfac3bea8e7e52 100644 (file)
@@ -895,7 +895,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase {
     );
     $contribution = $this->callAPISuccess('contribution', 'update', $newParams);
     $this->assertAPISuccess($contribution);
-    $this->_checkFinancialTrxn($contribution, 'paymentInstrument');
+    $this->_checkFinancialTrxn($contribution, 'paymentInstrument', $instrumentId);
   }
 
   /*
@@ -1444,7 +1444,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase {
    }
  }
 
- function _checkFinancialTrxn($contribution, $context) {
+ function _checkFinancialTrxn($contribution, $context, $instrumentId = NULL) {
    $trxnParams = array(
      'entity_id' =>   $contribution['id'],
      'entity_table' => 'civicrm_contribution',
@@ -1460,12 +1460,6 @@ class api_v3_ContributionTest extends CiviUnitTestCase {
        'from_financial_account_id' => CRM_Contribute_PseudoConstant::financialAccountType($contribution['financial_type_id'], $relationTypeId),
      );
    }
-   elseif ($context == 'paymentInstrument') {
-     $compareParams = array(
-       'from_financial_account_id' => 6,
-       'to_financial_account_id'  =>  7,
-     );
-   }
    elseif ($context == 'refund') {
      $compareParams = array(
        'to_financial_account_id' => 6,
@@ -1480,7 +1474,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase {
        'status_id' => 3,
      );
    }
-   elseif ($context == 'changeFinancial') {
+   elseif ($context == 'changeFinancial' || $context == 'paymentInstrument') {
      $entityParams = array(
        'entity_id' =>   $contribution['id'],
        'entity_table' => 'civicrm_contribution',
@@ -1491,16 +1485,27 @@ class api_v3_ContributionTest extends CiviUnitTestCase {
         'id' => $trxn['financial_trxn_id'],
      );
      $compareParams = array(
-       'to_financial_account_id' => 12,
        'total_amount' => -100,
        'status_id' => 1,
      );
+     if ($context == 'paymentInstrument') {
+       $compareParams += array(
+         'to_financial_account_id' => CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount(4),
+         'payment_instrument_id' => 4,
+       );
+     }
+     else {
+       $compareParams['to_financial_account_id'] = 12;
+     }
      $this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $trxnParams1, $compareParams);
-     $compareParams = array(
-       'to_financial_account_id' => 12,
-       'total_amount' => 100,
-       'status_id' => 1,
-     );
+     $compareParams['total_amount'] = 100;
+     if ($context == 'paymentInstrument') {
+       $compareParams['to_financial_account_id'] = CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount($instrumentId);
+       $compareParams['payment_instrument_id'] = $instrumentId;
+     }
+     else {
+       $compareParams['to_financial_account_id'] = 12;
+     }
    }
 
    $this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $params, $compareParams);