Merge pull request #12615 from eileenmcnaughton/amex
[civicrm-core.git] / tests / phpunit / CRM / Contribute / PseudoConstantTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info'AT'civicrm'DOT'org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28 /**
29 * CRM_Contribute_PseudoConstantTest
30 * @group headless
31 */
32 class CRM_Contribute_PseudoConstantTest extends CiviUnitTestCase {
33
34 /**
35 * Clean up after tests.
36 */
37 public function tearDown() {
38 $this->quickCleanUpFinancialEntities();
39 parent::tearDown();
40 }
41
42 /**
43 * Test that getRelationalFinancialAccount works and returns the same as the performant alternative.
44 *
45 * Note this is to be changed to be a deprecated wrapper function.
46 *
47 * Future is CRM_Financial_BAO_FinancialAccount::getFinancialAccountForFinancialTypeByRelationship
48 */
49 public function testGetRelationalFinancialAccount() {
50 $financialTypes = $this->callAPISuccess('FinancialType', 'get', [])['values'];
51 $financialAccounts = $this->callAPISuccess('FinancialAccount', 'get', [])['values'];
52 foreach ($financialTypes as $financialType) {
53 $accountID = CRM_Contribute_PseudoConstant::getRelationalFinancialAccount($financialType['id'], 'Accounts Receivable Account is');
54 $this->assertEquals('Accounts Receivable', $financialAccounts[$accountID]['name']);
55 $accountIDFromBetterFunction = CRM_Financial_BAO_FinancialAccount::getFinancialAccountForFinancialTypeByRelationship(
56 $financialType['id'],
57 'Accounts Receivable Account is'
58 );
59 $this->assertEquals($accountIDFromBetterFunction, $accountID);
60
61 $accountID = CRM_Contribute_PseudoConstant::getRelationalFinancialAccount($financialType['id'], 'Income Account is');
62 $this->assertEquals($financialType['name'], $financialAccounts[$accountID]['name']);
63 $accountIDFromBetterFunction = CRM_Financial_BAO_FinancialAccount::getFinancialAccountForFinancialTypeByRelationship(
64 $financialType['id'],
65 'Income Account is'
66 );
67 $this->assertEquals($accountIDFromBetterFunction, $accountID);
68 }
69 }
70
71 /**
72 * Test that getRelationalFinancialAccount works and returns the same as the performant alternative.
73 *
74 * Note this is to be changed to be a deprecated wrapper function.
75 *
76 * Future is CRM_Financial_BAO_FinancialAccount::getFinancialAccountForFinancialTypeByRelationship
77 */
78 public function testGetRelationalFinancialAccountForPaymentInstrument() {
79 $paymentInstruments = $this->callAPISuccess('Contribution', 'getoptions', ['field' => 'payment_instrument_id'])['values'];
80 $financialAccounts = $this->callAPISuccess('FinancialAccount', 'get', [])['values'];
81 foreach ($paymentInstruments as $paymentInstrumentID => $paymentInstrumentName) {
82 $financialAccountID = CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount($paymentInstrumentID);
83 if (in_array($paymentInstrumentName, ['Credit Card', 'Debit Card'])) {
84 $this->assertEquals('Payment Processor Account', $financialAccounts[$financialAccountID]['name']);
85 }
86 else {
87 $this->assertEquals('Deposit Bank Account', $financialAccounts[$financialAccountID]['name']);
88 }
89 }
90 }
91
92 }