Test fixes, towards CRM-17647
authoreileen <emcnaughton@wikimedia.org>
Tue, 23 Jan 2018 05:21:51 +0000 (18:21 +1300)
committereileen <emcnaughton@wikimedia.org>
Tue, 23 Jan 2018 05:21:51 +0000 (18:21 +1300)
Test fixes towards never calling Contribution::Create without skipCleanMoney

tests/phpunit/CRM/Core/BAO/FinancialTrxnTest.php
tests/phpunit/CRM/Event/BAO/AdditionalPaymentTest.php
tests/phpunit/CRM/Event/BAO/ChangeFeeSelectionTest.php
tests/phpunit/CRM/Financial/BAO/FinancialItemTest.php
tests/phpunit/CiviTest/CiviUnitTestCase.php

index aa354f26f794f300bb0f61a3f7b3db8cb9fa1dd9..8b10072a30166b3450cfd0701c759b08c178f69c 100644 (file)
@@ -90,23 +90,18 @@ class CRM_Core_BAO_FinancialTrxnTest extends CiviUnitTestCase {
       'thankyou_date' => '20080522',
     );
 
-    $contribution = CRM_Contribute_BAO_Contribution::create($params);
+    $contribution = $this->callAPISuccess('Contribution', 'create', $params);
+    $contribution = $contribution['values'][$contribution['id']];
 
-    $this->assertEquals($params['trxn_id'], $contribution->trxn_id);
-    $this->assertEquals($contactId, $contribution->contact_id);
-
-    $totalPaymentAmount = CRM_Core_BAO_FinancialTrxn::getTotalPayments($contribution->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);
+    $params['id'] = $contribution['id'];
+    $params['contribution_status_id'] = 1;
 
-    $this->assertEquals($params['trxn_id'], $contribution->trxn_id);
-    $this->assertEquals($params['contribution_status_id'], $contribution->contribution_status_id);
+    $contribution = $this->callAPISuccess('Contribution', 'create', $params);
 
-    $totalPaymentAmount = CRM_Core_BAO_FinancialTrxn::getTotalPayments($contribution->id);
+    $totalPaymentAmount = CRM_Core_BAO_FinancialTrxn::getTotalPayments($contribution['id']);
     $this->assertEquals('200.00', $totalPaymentAmount, 'Amount not matching.');
   }
 
@@ -158,15 +153,16 @@ class CRM_Core_BAO_FinancialTrxnTest extends CiviUnitTestCase {
         ),
       ),
     );
-    $contribution = CRM_Contribute_BAO_Contribution::create($params);
-    $lineItems[1] = CRM_Price_BAO_LineItem::getLineItemsByContributionID($contribution->id);
+    $contribution = $this->callAPISuccess('Contribution', 'create', $params);
+    $lineItems[1] = CRM_Price_BAO_LineItem::getLineItemsByContributionID($contribution['id']);
     $lineItemId = key($lineItems[1]);
     $lineItems[1][$lineItemId]['financial_item_id'] = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_financial_item WHERE entity_table = 'civicrm_line_item' AND entity_id = {$lineItemId}");
     // Get financial trxns for contribution
     $trxn = $this->callAPISuccess("FinancialTrxn", "get", array('total_amount' => 622));
     $this->assertEquals(date('Ymd', strtotime($trxn['values'][$trxn['id']]['trxn_date'])), date('Ymd', strtotime('2016-01-20')));
-    $contribution->revenue_recognition_date = date('Ymd', strtotime("+1 month"));
-    CRM_Core_BAO_FinancialTrxn::createDeferredTrxn($lineItems, $contribution);
+    $contributionObj = $this->getContributionObject($contribution['id']);
+    $contributionObj->revenue_recognition_date = date('Ymd', strtotime("+1 month"));
+    CRM_Core_BAO_FinancialTrxn::createDeferredTrxn($lineItems, $contributionObj);
     $trxn = $this->callAPISuccess("FinancialTrxn", "get", array('total_amount' => 622, 'id' => array("NOT IN" => array($trxn['id']))));
     $this->assertEquals(date('Ymd', strtotime($trxn['values'][$trxn['id']]['trxn_date'])), date('Ymd', strtotime("+1 month")));
   }
@@ -182,8 +178,8 @@ class CRM_Core_BAO_FinancialTrxnTest extends CiviUnitTestCase {
       'total_amount' => 100,
       'financial_type_id' => 1,
     );
-    $contribution = CRM_Contribute_BAO_Contribution::create($params);
-    $lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution->id, 'DESC');
+    $contribution = $this->callAPISuccess('Contribution', 'create', $params);
+    $lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC');
     $financialTrxn = $this->callAPISuccessGetSingle(
       'FinancialTrxn',
       array(
@@ -196,7 +192,7 @@ class CRM_Core_BAO_FinancialTrxnTest extends CiviUnitTestCase {
     $params = array(
       'card_type_id' => 2,
       'pan_truncation' => 4567,
-      'id' => $contribution->id,
+      'id' => $contribution['id'],
     );
     $this->callAPISuccess("Contribution", "create", $params);
     $financialTrxn = $this->callAPISuccessGetSingle(
@@ -221,8 +217,8 @@ class CRM_Core_BAO_FinancialTrxnTest extends CiviUnitTestCase {
       'total_amount' => 100,
       'financial_type_id' => 1,
     );
-    $contribution = CRM_Contribute_BAO_Contribution::create($params);
-    $lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution->id, 'DESC');
+    $contribution = $this->callAPISuccess('Contribution', 'create', $params);
+    $lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC');
     $financialTrxn = $this->callAPISuccessGetSingle(
       'FinancialTrxn',
       array(
@@ -232,7 +228,7 @@ class CRM_Core_BAO_FinancialTrxnTest extends CiviUnitTestCase {
     );
     $this->assertEquals(CRM_Utils_Array::value('card_type_id', $financialTrxn), NULL);
     $this->assertEquals(CRM_Utils_Array::value('pan_truncation', $financialTrxn), NULL);
-    CRM_Core_BAO_FinancialTrxn::updateCreditCardDetails($contribution->id, 4567, 2);
+    CRM_Core_BAO_FinancialTrxn::updateCreditCardDetails($contribution['id'], 4567, 2);
     $financialTrxn = $this->callAPISuccessGetSingle(
       'FinancialTrxn',
       array(
index e015a86720ff88ca8ea0d19130a863e764e75e8b..50c2944eefbdd090af8f9cc772a60a622d000bf3 100644 (file)
@@ -91,7 +91,6 @@ class CRM_Event_BAO_AdditionalPaymentTest extends CiviUnitTestCase {
       'total_amount' => $actualPaidAmt,
       'source' => 'Fall Fundraiser Dinner: Offline registration',
       'currency' => 'USD',
-      'non_deductible_amount' => 'null',
       'receipt_date' => date('Y-m-d') . " 00:00:00",
       'contact_id' => $this->_contactId,
       'financial_type_id' => 4,
@@ -103,8 +102,8 @@ class CRM_Event_BAO_AdditionalPaymentTest extends CiviUnitTestCase {
       'partial_amount_to_pay' => $actualPaidAmt,
     );
 
-    $contribution = CRM_Contribute_BAO_Contribution::create($contributionParams);
-    $contributionId = $contribution->id;
+    $contribution = $this->callAPISuccess('Contribution', 'create', $contributionParams);
+    $contributionId = $contribution['id'];
     $participant = $this->callAPISuccessGetSingle('participant', array('id' => $participant['id']));
 
     // add participant payment entry
@@ -125,11 +124,11 @@ class CRM_Event_BAO_AdditionalPaymentTest extends CiviUnitTestCase {
       $params, $lineItem
     );
     $lineItemVal[$priceSetId] = $lineItem;
-    CRM_Price_BAO_LineItem::processPriceSet($participant['id'], $lineItemVal, $contribution, 'civicrm_participant');
+    CRM_Price_BAO_LineItem::processPriceSet($participant['id'], $lineItemVal, $this->getContributionObject($contributionId), 'civicrm_participant');
 
     return array(
       'participant' => $participant,
-      'contribution' => $contribution,
+      'contribution' => $contribution['values'][$contribution['id']],
       'lineItem' => $templineItems,
       'params' => $tempParams,
       'feeBlock' => $feeBlock,
@@ -155,7 +154,7 @@ class CRM_Event_BAO_AdditionalPaymentTest extends CiviUnitTestCase {
 
     // status checking
     $this->assertEquals($participant['participant_status_id'], 14, 'Status record is not proper for participant');
-    $this->assertEquals($contribution->contribution_status_id, 8, 'Status record is not proper for contribution');
+    $this->assertEquals($result['contribution']['contribution_status_id'], 8, 'Status record is not proper for contribution');
   }
 
   /**
@@ -165,6 +164,7 @@ class CRM_Event_BAO_AdditionalPaymentTest extends CiviUnitTestCase {
     $feeAmt = 100;
     $amtPaid = 80;
     $result = $this->addParticipantWithPayment($feeAmt, $amtPaid);
+    $contributionID = $result['contribution']['id'];
     extract($result);
 
     //Complete the partial payment.
@@ -172,15 +172,15 @@ class CRM_Event_BAO_AdditionalPaymentTest extends CiviUnitTestCase {
       'total_amount' => 20,
       'payment_instrument_id' => 3,
     );
-    CRM_Contribute_BAO_Contribution::recordAdditionalPayment($contribution->id, $submittedValues, 'owed', $participant['id']);
+    CRM_Contribute_BAO_Contribution::recordAdditionalPayment($contributionID, $submittedValues, 'owed', $participant['id']);
 
     //Change selection to a lower amount.
     $params['price_2'] = 50;
-    CRM_Price_BAO_LineItem::changeFeeSelections($params, $participant['id'], 'participant', $contribution->id, $feeBlock, $lineItem, $feeAmt);
+    CRM_Price_BAO_LineItem::changeFeeSelections($params, $participant['id'], 'participant', $contributionID, $feeBlock, $lineItem, $feeAmt);
 
     //Record a refund of the remaining amount.
     $submittedValues['total_amount'] = 50;
-    CRM_Contribute_BAO_Contribution::recordAdditionalPayment($contribution->id, $submittedValues, 'refund', $participant['id']);
+    CRM_Contribute_BAO_Contribution::recordAdditionalPayment($contributionID, $submittedValues, 'refund', $participant['id']);
     $paymentInfo = CRM_Contribute_BAO_Contribution::getPaymentInfo($participant['id'], 'event', TRUE);
     $transaction = $paymentInfo['transaction'];
 
index 894c6011975c965cf08223e9132bec9515591765..e26832f39094ac2cda8f34ebff7e83bc2c5091d0 100644 (file)
@@ -205,7 +205,6 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase {
       'total_amount' => $actualPaidAmt,
       'source' => 'Testset with information',
       'currency' => 'USD',
-      'non_deductible_amount' => 'null',
       'receipt_date' => date('Y-m-d') . " 00:00:00",
       'contact_id' => $this->_contactId,
       'financial_type_id' => 4,
@@ -217,8 +216,8 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase {
       'partial_amount_to_pay' => $actualPaidAmt,
     );
 
-    $contribution = CRM_Contribute_BAO_Contribution::create($contributionParams);
-    $this->_contributionId = $contribution->id;
+    $contribution = $this->callAPISuccess('Contribution', 'create', $contributionParams);
+    $this->_contributionId = $contribution['id'];
 
     $this->callAPISuccess('participant_payment', 'create', array(
       'participant_id'  => $this->_participantId,
@@ -229,7 +228,7 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase {
     $lineItem = CRM_Price_BAO_LineItem::getLineItems($this->_participantId, 'participant');
     CRM_Price_BAO_PriceSet::processAmount($this->_feeBlock, $priceSetParams, $lineItem);
     $lineItemVal[$this->_priceSetID] = $lineItem;
-    CRM_Price_BAO_LineItem::processPriceSet($participant['id'], $lineItemVal, $contribution, 'civicrm_participant');
+    CRM_Price_BAO_LineItem::processPriceSet($participant['id'], $lineItemVal, $this->getContributionObject($contribution['id']), 'civicrm_participant');
     $this->balanceCheck($this->_expensiveFee);
   }
 
@@ -346,7 +345,6 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase {
       'total_amount' => 10,
       'source' => 'Testset with information',
       'currency' => 'USD',
-      'non_deductible_amount' => 'null',
       'receipt_date' => date('Y-m-d') . " 00:00:00",
       'contact_id' => $this->_contactId,
       'financial_type_id' => 4,
@@ -356,8 +354,8 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase {
       'skipLineItem' => 1,
     );
 
-    $contribution = CRM_Contribute_BAO_Contribution::create($contributionParams);
-    $this->_contributionId = $contribution->id;
+    $contribution = $this->callAPISuccess('Contribution', 'create', $contributionParams);
+    $this->_contributionId = $contribution['id'];
 
     $this->callAPISuccess('participant_payment', 'create', array(
       'participant_id'  => $this->_participantId,
@@ -369,7 +367,7 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase {
     $lineItem = CRM_Price_BAO_LineItem::getLineItems($this->_participantId, 'participant');
     CRM_Price_BAO_PriceSet::processAmount($this->_feeBlock, $priceSetParams, $lineItem);
     $lineItemVal[$this->_priceSetID] = $lineItem;
-    CRM_Price_BAO_LineItem::processPriceSet($this->_participantId, $lineItemVal, $contribution, 'civicrm_participant');
+    CRM_Price_BAO_LineItem::processPriceSet($this->_participantId, $lineItemVal, $this->getContributionObject($contribution['id']), 'civicrm_participant');
 
     // CASE 2: Choose text price qty 3 (x$10 = $30 amount)
     $priceSetParams['price_1'] = 3;
index 08df6e7c7c5f40e758c7b94c13ae31bbdfcc502e..7c6ba2025f650af2c88139e79610b12851ce86e1 100644 (file)
@@ -352,18 +352,4 @@ class CRM_Financial_BAO_FinancialItemTest extends CiviUnitTestCase {
     $this->callAPISuccessGetSingle('FinancialItem', $params, $checkAgainst);
   }
 
-  /**
-   * Get the contribution object.
-   *
-   * @param int $contributionID
-   *
-   * @return \CRM_Contribute_BAO_Contribution
-   */
-  protected function getContributionObject($contributionID) {
-    $contributionObj = new CRM_Contribute_BAO_Contribution();
-    $contributionObj->id = $contributionID;
-    $contributionObj->find(TRUE);
-    return $contributionObj;
-  }
-
 }
index 93fa84fb3f78eb3373a1aed3bd7dbc5dfa82b528..adaba859a61055febcd6f43353130e6ed5f44eea 100644 (file)
@@ -3983,4 +3983,19 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
     return CRM_Utils_Money::format($amount, NULL, '%a');
   }
 
+
+  /**
+   * Get the contribution object.
+   *
+   * @param int $contributionID
+   *
+   * @return \CRM_Contribute_BAO_Contribution
+   */
+  protected function getContributionObject($contributionID) {
+    $contributionObj = new CRM_Contribute_BAO_Contribution();
+    $contributionObj->id = $contributionID;
+    $contributionObj->find(TRUE);
+    return $contributionObj;
+  }
+
 }