From c73dd828dd531ef909d5a6a1c23fe22bfc9af700 Mon Sep 17 00:00:00 2001 From: Edsel Date: Mon, 20 Jun 2016 17:07:24 +0530 Subject: [PATCH] CRM-16189 Added unit test for deferred financial types ---------------------------------------- * CRM-16189: Improve support for Accrual Method bookkeeping https://issues.civicrm.org/jira/browse/CRM-16189 Conflicts: tests/phpunit/CRM/Financial/BAO/FinancialAccountTest.php --- .../Financial/BAO/FinancialAccountTest.php | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/phpunit/CRM/Financial/BAO/FinancialAccountTest.php b/tests/phpunit/CRM/Financial/BAO/FinancialAccountTest.php index acaa6177a4..424416f303 100644 --- a/tests/phpunit/CRM/Financial/BAO/FinancialAccountTest.php +++ b/tests/phpunit/CRM/Financial/BAO/FinancialAccountTest.php @@ -214,4 +214,42 @@ class CRM_Financial_BAO_FinancialAccountTest extends CiviUnitTestCase { $this->assertTrue(($relations == $financialAccountLinks), "The two arrays are not the same"); } + /* + * Test getting deferred financial type. + */ + public function testGetDeferredFinancialType() { + $params = array( + 'name' => 'TestFinancialAccount_1', + 'accounting_code' => 4800, + 'contact_id' => 1, + 'is_deductible' => 0, + 'is_active' => 1, + 'is_reserved' => 0, + ); + + $ids = array(); + $financialAccount = CRM_Financial_BAO_FinancialAccount::add($params, $ids); + $params['name'] = 'test_financialType1'; + $financialType = CRM_Financial_BAO_FinancialType::add($params, $ids); + $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Deferred Revenue Account is' ")); + $financialParams = array( + 'entity_table' => 'civicrm_financial_type', + 'entity_id' => $financialType->id, + 'account_relationship' => $relationTypeId, + 'financial_account_id' => $financialAccount->id, + ); + + CRM_Financial_BAO_FinancialTypeAccount::add($financialParams, $ids); + $result = $this->assertDBNotNull( + 'CRM_Financial_DAO_EntityFinancialAccount', + $financialAccount->id, + 'entity_id', + 'financial_account_id', + 'Database check on added financial type record.' + ); + $this->assertEquals($result, $financialType->id, 'Verify Account Type'); + $financialTypes = CRM_Financial_BAO_FinancialAccount::getDeferredFinancialType(); + $this->assertTrue(array_key_exists($result, $financialTypes), "The financial type created does not have a deferred account relationship"); + } + } -- 2.25.1