Commit | Line | Data |
---|---|---|
928a340b | 1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7d61e75f | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
928a340b | 5 | | | |
7d61e75f TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
928a340b | 9 | +--------------------------------------------------------------------+ |
10 | */ | |
11 | ||
12 | /** | |
13 | * CRM_Contribute_PseudoConstantTest | |
14 | * @group headless | |
15 | */ | |
16 | class CRM_Contribute_PseudoConstantTest extends CiviUnitTestCase { | |
17 | ||
18 | /** | |
19 | * Clean up after tests. | |
20 | */ | |
594a9328 | 21 | public function tearDown(): void { |
928a340b | 22 | $this->quickCleanUpFinancialEntities(); |
23 | parent::tearDown(); | |
24 | } | |
25 | ||
26 | /** | |
27 | * Test that getRelationalFinancialAccount works and returns the same as the performant alternative. | |
28 | * | |
29 | * Note this is to be changed to be a deprecated wrapper function. | |
30 | * | |
31 | * Future is CRM_Financial_BAO_FinancialAccount::getFinancialAccountForFinancialTypeByRelationship | |
32 | */ | |
33 | public function testGetRelationalFinancialAccount() { | |
34 | $financialTypes = $this->callAPISuccess('FinancialType', 'get', [])['values']; | |
35 | $financialAccounts = $this->callAPISuccess('FinancialAccount', 'get', [])['values']; | |
36 | foreach ($financialTypes as $financialType) { | |
37 | $accountID = CRM_Contribute_PseudoConstant::getRelationalFinancialAccount($financialType['id'], 'Accounts Receivable Account is'); | |
38 | $this->assertEquals('Accounts Receivable', $financialAccounts[$accountID]['name']); | |
39 | $accountIDFromBetterFunction = CRM_Financial_BAO_FinancialAccount::getFinancialAccountForFinancialTypeByRelationship( | |
40 | $financialType['id'], | |
41 | 'Accounts Receivable Account is' | |
42 | ); | |
43 | $this->assertEquals($accountIDFromBetterFunction, $accountID); | |
44 | ||
45 | $accountID = CRM_Contribute_PseudoConstant::getRelationalFinancialAccount($financialType['id'], 'Income Account is'); | |
46 | $this->assertEquals($financialType['name'], $financialAccounts[$accountID]['name']); | |
47 | $accountIDFromBetterFunction = CRM_Financial_BAO_FinancialAccount::getFinancialAccountForFinancialTypeByRelationship( | |
48 | $financialType['id'], | |
49 | 'Income Account is' | |
50 | ); | |
51 | $this->assertEquals($accountIDFromBetterFunction, $accountID); | |
52 | } | |
928a340b | 53 | } |
fe74d2b5 | 54 | |
928a340b | 55 | /** |
56 | * Test that getRelationalFinancialAccount works and returns the same as the performant alternative. | |
57 | * | |
58 | * Note this is to be changed to be a deprecated wrapper function. | |
59 | * | |
60 | * Future is CRM_Financial_BAO_FinancialAccount::getFinancialAccountForFinancialTypeByRelationship | |
61 | */ | |
62 | public function testGetRelationalFinancialAccountForPaymentInstrument() { | |
63 | $paymentInstruments = $this->callAPISuccess('Contribution', 'getoptions', ['field' => 'payment_instrument_id'])['values']; | |
64 | $financialAccounts = $this->callAPISuccess('FinancialAccount', 'get', [])['values']; | |
65 | foreach ($paymentInstruments as $paymentInstrumentID => $paymentInstrumentName) { | |
66 | $financialAccountID = CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount($paymentInstrumentID); | |
67 | if (in_array($paymentInstrumentName, ['Credit Card', 'Debit Card'])) { | |
68 | $this->assertEquals('Payment Processor Account', $financialAccounts[$financialAccountID]['name']); | |
69 | } | |
70 | else { | |
71 | $this->assertEquals('Deposit Bank Account', $financialAccounts[$financialAccountID]['name']); | |
72 | } | |
73 | } | |
74 | } | |
75 | ||
76 | } |