From: Jitendra Purohit Date: Mon, 14 Aug 2017 16:03:33 +0000 (+0530) Subject: replace setStatus with statusBounce X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=a48a4a2b4e55f73798d2314488eb03ca45d9bdd3;p=civicrm-core.git replace setStatus with statusBounce --- diff --git a/CRM/Financial/BAO/FinancialTypeAccount.php b/CRM/Financial/BAO/FinancialTypeAccount.php index c0febdc9e0..0ea4abfd71 100644 --- a/CRM/Financial/BAO/FinancialTypeAccount.php +++ b/CRM/Financial/BAO/FinancialTypeAccount.php @@ -91,10 +91,7 @@ class CRM_Financial_BAO_FinancialTypeAccount extends CRM_Financial_DAO_EntityFin $financialTypeAccount->find(TRUE); } $financialTypeAccount->copyValues($params); - $valid = self::validateRelationship($financialTypeAccount); - if (!$valid) { - return FALSE; - } + self::validateRelationship($financialTypeAccount); $financialTypeAccount->save(); return $financialTypeAccount; } @@ -105,7 +102,6 @@ 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 @@ -277,6 +273,7 @@ WHERE cog.name = 'payment_instrument' "; * * @param obj $financialTypeAccount of CRM_Financial_DAO_EntityFinancialAccount * + * @throws CRM_Core_Exception */ public static function validateRelationship($financialTypeAccount) { $financialAccountLinks = CRM_Financial_BAO_FinancialAccount::getfinancialAccountRelations(); @@ -286,10 +283,8 @@ WHERE cog.name = 'payment_instrument' "; $params = array( 1 => $accountRelationships[$financialTypeAccount->account_relationship], ); - CRM_Core_Session::setStatus(ts('This financial account cannot have \'%1\' relationship.', $params), ts('Error'), 'error'); - return FALSE; + throw new CRM_Core_Exception(ts("This financial account cannot have '%1' relationship.", $params)); } - return TRUE; } } diff --git a/CRM/Financial/Form/FinancialTypeAccount.php b/CRM/Financial/Form/FinancialTypeAccount.php index d1f8cb50ff..0b380935f1 100644 --- a/CRM/Financial/Form/FinancialTypeAccount.php +++ b/CRM/Financial/Form/FinancialTypeAccount.php @@ -299,10 +299,13 @@ class CRM_Financial_Form_FinancialTypeAccount extends CRM_Contribute_Form { if ($this->_action & CRM_Core_Action::ADD) { $params['entity_id'] = $this->_aid; } - $financialTypeAccount = CRM_Financial_BAO_FinancialTypeAccount::add($params, $ids); - if ($financialTypeAccount) { - CRM_Core_Session::setStatus(ts('The financial type Account has been saved.')); + try { + $financialTypeAccount = CRM_Financial_BAO_FinancialTypeAccount::add($params, $ids); } + catch (CRM_Core_Exception $e) { + CRM_Core_Error::statusBounce($e->getMessage()); + } + 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 c29b51875d..88172853d0 100644 --- a/tests/phpunit/CRM/Financial/BAO/FinancialTypeAccountTest.php +++ b/tests/phpunit/CRM/Financial/BAO/FinancialTypeAccountTest.php @@ -131,8 +131,14 @@ 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); - $valid = CRM_Financial_BAO_FinancialTypeAccount::validateRelationship($financialAccountType); - $this->assertFalse($valid); + 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."); + } } /**