|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * File for the BatchTest class |
| 4 | + * |
| 5 | + * (PHP 5) |
| 6 | + * |
| 7 | + * @package CiviCRM |
| 8 | + * |
| 9 | + * This file is part of CiviCRM |
| 10 | + * |
| 11 | + * CiviCRM is free software; you can redistribute it and/or |
| 12 | + * modify it under the terms of the GNU Affero General Public License |
| 13 | + * as published by the Free Software Foundation; either version 3 of |
| 14 | + * the License, or (at your option) any later version. |
| 15 | + * |
| 16 | + * CiviCRM is distributed in the hope that it will be useful, |
| 17 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | + * GNU Affero General Public License for more details. |
| 20 | + * |
| 21 | + * You should have received a copy of the GNU Affero General Public |
| 22 | + * License along with this program. If not, see |
| 23 | + * <http://www.gnu.org/licenses/>. |
| 24 | + */ |
| 25 | + |
| 26 | +/** |
| 27 | + * Test CRM/Batch/BAO/Batch.php getBatchFinancialItems |
| 28 | + * |
| 29 | + * @package CiviCRM |
| 30 | + * @group headless |
| 31 | + */ |
| 32 | +class CRM_Batch_BAO_BatchTest extends CiviUnitTestCase { |
| 33 | + |
| 34 | + /** |
| 35 | + * This test checks that a batch search |
| 36 | + * by payment method works. |
| 37 | + * This function could later be expanded to include |
| 38 | + * checks that other types of searches are also |
| 39 | + * working. |
| 40 | + * |
| 41 | + * It creates two contributions, one with payment method credit |
| 42 | + * card and one with payment method check. After performing a |
| 43 | + * search by payment method for checks, it makes sure that the |
| 44 | + * results are only contributions made by check. |
| 45 | + */ |
| 46 | + public function testGetBatchFinancialItems() { |
| 47 | + |
| 48 | + // create two contributions: one check and one credit card |
| 49 | + |
| 50 | + $contactId = $this->individualCreate(array('first_name' => 'John', 'last_name' => 'Doe')); |
| 51 | + $this->contributionCreate([ |
| 52 | + 'contact_id' => $contactId, |
| 53 | + 'total_amount' => 1, |
| 54 | + 'payment_instrument_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', 'Check'), |
| 55 | + 'financial_type_id' => 1, |
| 56 | + 'contribution_status_id' => 1, |
| 57 | + 'receive_date' => '20080522000000', |
| 58 | + 'receipt_date' => '20080522000000', |
| 59 | + 'trxn_id' => '22ereerwww322323', |
| 60 | + 'id' => NULL, |
| 61 | + 'fee_amount' => 0, |
| 62 | + 'net_amount' => 1, |
| 63 | + 'currency' => 'USD', |
| 64 | + 'invoice_id' => '22ed39c9e9ee6ef6031621ce0eafe6da70', |
| 65 | + 'skipCleanMoney' => TRUE, |
| 66 | + ]); |
| 67 | + $this->contributionCreate([ |
| 68 | + 'contact_id' => $contactId, |
| 69 | + 'total_amount' => 1, |
| 70 | + 'payment_instrument_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', 'Credit Card'), |
| 71 | + 'financial_type_id' => 1, |
| 72 | + 'contribution_status_id' => 1, |
| 73 | + 'receive_date' => '20080523000000', |
| 74 | + 'receipt_date' => '20080523000000', |
| 75 | + 'trxn_id' => '22ereerwww323323', |
| 76 | + 'id' => NULL, |
| 77 | + 'fee_amount' => 0, |
| 78 | + 'net_amount' => 1, |
| 79 | + 'currency' => 'USD', |
| 80 | + 'invoice_id' => '22ed39c9e9ee6ef6031621ce0eafe6da71', |
| 81 | + 'skipCleanMoney' => TRUE, |
| 82 | + ]); |
| 83 | + |
| 84 | + //create an empty batch to use for the search, and run the search |
| 85 | + |
| 86 | + $batchParams = array('title' => 'Test Batch'); |
| 87 | + $batchParams['status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Batch_BAO_Batch', 'status_id', 'Open'); |
| 88 | + $batch = CRM_Batch_BAO_Batch::create($batchParams); |
| 89 | + $entityId = $batch->id; |
| 90 | + $returnvalues = array( |
| 91 | + 'civicrm_financial_trxn.payment_instrument_id as payment_method', |
| 92 | + ); |
| 93 | + $notPresent = TRUE; |
| 94 | + $params['contribution_payment_instrument_id'] |
| 95 | + = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', 'Check'); |
| 96 | + $result = CRM_Batch_BAO_Batch::getBatchFinancialItems($entityId, $returnvalues, $notPresent, $params, TRUE)->fetchAll(); |
| 97 | + $this->assertEquals(count($result), 1, 'In line' . __LINE__); |
| 98 | + $this->assertEquals($result[0]['payment_method'], CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', 'Check'), 'In line' . __LINE__); |
| 99 | + |
| 100 | + } |
| 101 | + |
| 102 | +} |
0 commit comments