3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
29 * CRM_Contribute_PseudoConstantTest
32 class CRM_Contribute_PseudoConstantTest
extends CiviUnitTestCase
{
35 * Clean up after tests.
37 public function tearDown() {
38 $this->quickCleanUpFinancialEntities();
43 * Test that getRelationalFinancialAccount works and returns the same as the performant alternative.
45 * Note this is to be changed to be a deprecated wrapper function.
47 * Future is CRM_Financial_BAO_FinancialAccount::getFinancialAccountForFinancialTypeByRelationship
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(
57 'Accounts Receivable Account is'
59 $this->assertEquals($accountIDFromBetterFunction, $accountID);
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(
67 $this->assertEquals($accountIDFromBetterFunction, $accountID);
72 * Test that getRelationalFinancialAccount works and returns the same as the performant alternative.
74 * Note this is to be changed to be a deprecated wrapper function.
76 * Future is CRM_Financial_BAO_FinancialAccount::getFinancialAccountForFinancialTypeByRelationship
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']);
87 $this->assertEquals('Deposit Bank Account', $financialAccounts[$financialAccountID]['name']);