BatchTest.php 4.08 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
<?php
/**
 *  File for the BatchTest class
 *
 *  (PHP 5)
 *
 * @package   CiviCRM
 *
 *   This file is part of CiviCRM
 *
 *   CiviCRM is free software; you can redistribute it and/or
 *   modify it under the terms of the GNU Affero General Public License
 *   as published by the Free Software Foundation; either version 3 of
 *   the License, or (at your option) any later version.
 *
 *   CiviCRM is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU Affero General Public License for more details.
 *
 *   You should have received a copy of the GNU Affero General Public
 *   License along with this program.  If not, see
 *   <http://www.gnu.org/licenses/>.
 */

/**
 *  Test CRM/Batch/BAO/Batch.php getBatchFinancialItems
 *
 * @package   CiviCRM
 * @group headless
 */
class CRM_Batch_BAO_BatchTest extends CiviUnitTestCase {

  /**
   * This test checks that a batch search
   * by payment method works.
   * This function could later be expanded to include
   * checks that other types of searches are also
   * working.
   *
   * It creates two contributions, one with payment method credit
   * card and one with payment method check.  After performing a
   * search by payment method for checks, it makes sure that the
   * results are only contributions made by check.
   */
  public function testGetBatchFinancialItems() {

    // create two contributions: one check and one credit card

    $contactId = $this->individualCreate(array('first_name' => 'John', 'last_name' => 'Doe'));
51
    $this->contributionCreate([
52 53
      'contact_id' => $contactId,
      'total_amount' => 1,
Pradeep Nayak's avatar
Pradeep Nayak committed
54 55 56
      'payment_instrument_id' => 'Check',
      'financial_type_id' => 'Donation',
      'contribution_status_id' => 'Completed',
57 58 59 60 61 62 63
      'receive_date' => '20080522000000',
      'receipt_date' => '20080522000000',
      'trxn_id' => '22ereerwww322323',
      'id' => NULL,
      'fee_amount' => 0,
      'net_amount' => 1,
      'currency' => 'USD',
64
      'invoice_id' => '22ed39c9e9ee6ef6031621ce0eafe6da70',
65
      'skipCleanMoney' => TRUE,
66 67
    ]);
    $this->contributionCreate([
68
      'contact_id' => $contactId,
69
      'total_amount' => 1,
Pradeep Nayak's avatar
Pradeep Nayak committed
70 71 72
      'payment_instrument_id' => 'Credit Card',
      'financial_type_id' => 'Member Dues',
      'contribution_status_id' => 'Completed',
73 74 75 76 77 78 79
      'receive_date' => '20080523000000',
      'receipt_date' => '20080523000000',
      'trxn_id' => '22ereerwww323323',
      'id' => NULL,
      'fee_amount' => 0,
      'net_amount' => 1,
      'currency' => 'USD',
80
      'invoice_id' => '22ed39c9e9ee6ef6031621ce0eafe6da71',
81
      'skipCleanMoney' => TRUE,
82
    ]);
83 84 85 86 87 88 89 90 91 92 93

    //create an empty batch to use for the search, and run the search

    $batchParams = array('title' => 'Test Batch');
    $batchParams['status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Batch_BAO_Batch', 'status_id', 'Open');
    $batch = CRM_Batch_BAO_Batch::create($batchParams);
    $entityId = $batch->id;
    $returnvalues = array(
      'civicrm_financial_trxn.payment_instrument_id as payment_method',
    );
    $notPresent = TRUE;
Tanya Bouman's avatar
Tanya Bouman committed
94 95
    $params['contribution_payment_instrument_id']
      = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', 'Check');
96 97 98
    $result = CRM_Batch_BAO_Batch::getBatchFinancialItems($entityId, $returnvalues, $notPresent, $params, TRUE)->fetchAll();
    $this->assertEquals(count($result), 1, 'In line' . __LINE__);
    $this->assertEquals($result[0]['payment_method'], CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', 'Check'), 'In line' . __LINE__);
Pradeep Nayak's avatar
Pradeep Nayak committed
99 100 101 102 103 104
    $params['financial_type_id'] = implode(',', [
      CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'financial_type_id', 'Donation'),
      CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'financial_type_id', 'Member Dues'),
    ]);
    $result = CRM_Batch_BAO_Batch::getBatchFinancialItems($entityId, $returnvalues, $notPresent, $params, TRUE)->fetchAll();
    $this->assertEquals(count($result), 1, 'In line' . __LINE__);
105
  }
Tanya Bouman's avatar
Tanya Bouman committed
106

107
}