CRM-20158, added function to update credit card details like card type and pan trunc...
[civicrm-core.git] / tests / phpunit / CRM / Core / BAO / FinancialTrxnTest.php
index adfaa78a0cf2b9913c66d14e91b0d8426da1167b..5fdf40cebc9eec5047369d57779fd73fdcca9ded 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2016                                |
+ | Copyright CiviCRM LLC (c) 2004-2017                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -140,7 +140,6 @@ class CRM_Core_BAO_FinancialTrxnTest extends CiviUnitTestCase {
       'receive_date' => '2016-01-20',
       'total_amount' => 622,
       'financial_type_id' => 4,
-      'revenue_recognition_date' => date('Ymd', strtotime("+1 month")),
       'line_items' => array(
         array(
           'line_item' => array(
@@ -166,9 +165,83 @@ class CRM_Core_BAO_FinancialTrxnTest extends CiviUnitTestCase {
     // 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);
     $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")));
   }
 
+  /**
+   * Test for updateCreditCardDetails().
+   */
+  public function testUpdateCreditCardDetailsUsingContributionAPI() {
+    $cid = $this->individualCreate();
+    $params = array(
+      'contact_id' => $cid,
+      'receive_date' => '2016-01-20',
+      'total_amount' => 100,
+      'financial_type_id' => 1,
+    );
+    $contribution = CRM_Contribute_BAO_Contribution::create($params);
+    $lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution->id, 'DESC');
+    $financialTrxn = $this->callAPISuccessGetSingle(
+      'FinancialTrxn',
+      array(
+        'id' => $lastFinancialTrxnId['financialTrxnId'],
+        'return' => array('card_type', 'pan_truncation'),
+      )
+    );
+    $this->assertEquals(CRM_Utils_Array::value('card_type', $financialTrxn), NULL);
+    $this->assertEquals(CRM_Utils_Array::value('pan_truncation', $financialTrxn), NULL);
+    $params = array(
+      'card_type' => 2,
+      'pan_truncation' => 4567,
+      'id' => $contribution->id,
+    );
+    $this->callAPISuccess("Contribution", "create", $params);
+    $financialTrxn = $this->callAPISuccessGetSingle(
+      'FinancialTrxn',
+      array(
+        'id' => $lastFinancialTrxnId['financialTrxnId'],
+        'return' => array('card_type', 'pan_truncation'),
+      )
+    );
+    $this->assertEquals($financialTrxn['card_type'], 2);
+    $this->assertEquals($financialTrxn['pan_truncation'], 4567);
+  }
+
+  /**
+   * Test for updateCreditCardDetails().
+   */
+  public function testUpdateCreditCardDetails() {
+    $cid = $this->individualCreate();
+    $params = array(
+      'contact_id' => $cid,
+      'receive_date' => '2016-01-20',
+      'total_amount' => 100,
+      'financial_type_id' => 1,
+    );
+    $contribution = CRM_Contribute_BAO_Contribution::create($params);
+    $lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution->id, 'DESC');
+    $financialTrxn = $this->callAPISuccessGetSingle(
+      'FinancialTrxn',
+      array(
+        'id' => $lastFinancialTrxnId['financialTrxnId'],
+        'return' => array('card_type', 'pan_truncation'),
+      )
+    );
+    $this->assertEquals(CRM_Utils_Array::value('card_type', $financialTrxn), NULL);
+    $this->assertEquals(CRM_Utils_Array::value('pan_truncation', $financialTrxn), NULL);
+    CRM_Core_BAO_FinancialTrxn::updateCreditCardDetails($contribution->id, 4567, 2);
+    $financialTrxn = $this->callAPISuccessGetSingle(
+      'FinancialTrxn',
+      array(
+        'id' => $lastFinancialTrxnId['financialTrxnId'],
+        'return' => array('card_type', 'pan_truncation'),
+      )
+    );
+    $this->assertEquals($financialTrxn['card_type'], 2);
+    $this->assertEquals($financialTrxn['pan_truncation'], 4567);
+  }
+
 }