From 74c3274a1c6899cc53596c616f954886f7559303 Mon Sep 17 00:00:00 2001 From: Jitendra Purohit Date: Thu, 13 Jul 2017 16:36:25 +0530 Subject: [PATCH] CRM-19739: New Account Relationship Option Screen does not show exception --- CRM/Financial/BAO/FinancialTypeAccount.php | 10 ++++++++-- CRM/Financial/Form/FinancialTypeAccount.php | 4 +++- .../CRM/Financial/BAO/FinancialTypeAccountTest.php | 10 ++-------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/CRM/Financial/BAO/FinancialTypeAccount.php b/CRM/Financial/BAO/FinancialTypeAccount.php index 92b8aa8d61..c0febdc9e0 100644 --- a/CRM/Financial/BAO/FinancialTypeAccount.php +++ b/CRM/Financial/BAO/FinancialTypeAccount.php @@ -91,7 +91,10 @@ class CRM_Financial_BAO_FinancialTypeAccount extends CRM_Financial_DAO_EntityFin $financialTypeAccount->find(TRUE); } $financialTypeAccount->copyValues($params); - self::validateRelationship($financialTypeAccount); + $valid = self::validateRelationship($financialTypeAccount); + if (!$valid) { + return FALSE; + } $financialTypeAccount->save(); return $financialTypeAccount; } @@ -102,6 +105,7 @@ class CRM_Financial_BAO_FinancialTypeAccount extends CRM_Financial_DAO_EntityFin * @param int $financialTypeAccountId * @param int $accountId * + * @return bool */ public static function del($financialTypeAccountId, $accountId = NULL) { // check if financial type is present @@ -282,8 +286,10 @@ WHERE cog.name = 'payment_instrument' "; $params = array( 1 => $accountRelationships[$financialTypeAccount->account_relationship], ); - throw new Exception(ts("This financial account cannot have '%1' relationship.", $params)); + CRM_Core_Session::setStatus(ts('This financial account cannot have \'%1\' relationship.', $params), ts('Error'), 'error'); + return FALSE; } + return TRUE; } } diff --git a/CRM/Financial/Form/FinancialTypeAccount.php b/CRM/Financial/Form/FinancialTypeAccount.php index e686724d37..d1f8cb50ff 100644 --- a/CRM/Financial/Form/FinancialTypeAccount.php +++ b/CRM/Financial/Form/FinancialTypeAccount.php @@ -300,7 +300,9 @@ class CRM_Financial_Form_FinancialTypeAccount extends CRM_Contribute_Form { $params['entity_id'] = $this->_aid; } $financialTypeAccount = CRM_Financial_BAO_FinancialTypeAccount::add($params, $ids); - CRM_Core_Session::setStatus(ts('The financial type Account has been saved.')); + if ($financialTypeAccount) { + CRM_Core_Session::setStatus(ts('The financial type Account has been saved.')); + } } $buttonName = $this->controller->getButtonName(); diff --git a/tests/phpunit/CRM/Financial/BAO/FinancialTypeAccountTest.php b/tests/phpunit/CRM/Financial/BAO/FinancialTypeAccountTest.php index 88172853d0..c29b51875d 100644 --- a/tests/phpunit/CRM/Financial/BAO/FinancialTypeAccountTest.php +++ b/tests/phpunit/CRM/Financial/BAO/FinancialTypeAccountTest.php @@ -131,14 +131,8 @@ class CRM_Financial_BAO_FinancialTypeAccountTest extends CiviUnitTestCase { $financialAccountType->entity_id = array_search('Member Dues', $financialType); $financialAccountType->account_relationship = array_search('Credit/Contra Revenue Account is', $accountRelationships); $financialAccountType->financial_account_id = array_search('Liability', $financialAccount); - try { - CRM_Financial_BAO_FinancialTypeAccount::validateRelationship($financialAccountType); - $this->fail("Missed expected exception"); - } - catch (Exception $e) { - $this->assertTrue(TRUE, 'Received expected exception'); - $this->assertEquals($e->getMessage(), "This financial account cannot have 'Credit/Contra Revenue Account is' relationship."); - } + $valid = CRM_Financial_BAO_FinancialTypeAccount::validateRelationship($financialAccountType); + $this->assertFalse($valid); } /** -- 2.25.1