From 0e94300054f6f18db43bff1a6385a41180628365 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Wed, 30 Nov 2022 11:59:45 +1300 Subject: [PATCH] Follow up on EntityFinancialAccount delete I decided the test was a waste of space as it was mixing up the entities & hence checking the wrong id with the wrong entity & meaningless. Form now uses the right api: --- CRM/Financial/BAO/EntityFinancialAccount.php | 1 + CRM/Financial/Form/FinancialTypeAccount.php | 13 +++++++------ .../Financial/BAO/FinancialTypeAccountTest.php | 15 --------------- 3 files changed, 8 insertions(+), 21 deletions(-) diff --git a/CRM/Financial/BAO/EntityFinancialAccount.php b/CRM/Financial/BAO/EntityFinancialAccount.php index f100f717bb..c2d8839d5d 100644 --- a/CRM/Financial/BAO/EntityFinancialAccount.php +++ b/CRM/Financial/BAO/EntityFinancialAccount.php @@ -81,6 +81,7 @@ class CRM_Financial_BAO_EntityFinancialAccount extends CRM_Financial_DAO_EntityF * @deprecated */ public static function del($financialTypeAccountId, $accountId = NULL) { + CRM_Core_Error::deprecatedFunctionWarning('api'); static::deleteRecord(['id' => $financialTypeAccountId]); } diff --git a/CRM/Financial/Form/FinancialTypeAccount.php b/CRM/Financial/Form/FinancialTypeAccount.php index 15abe94df5..3180d3830f 100644 --- a/CRM/Financial/Form/FinancialTypeAccount.php +++ b/CRM/Financial/Form/FinancialTypeAccount.php @@ -15,6 +15,8 @@ * @copyright CiviCRM LLC https://civicrm.org/licensing */ +use Civi\Api4\EntityFinancialAccount; + /** * This class generates form components for Financial Type Account */ @@ -270,20 +272,19 @@ class CRM_Financial_Form_FinancialTypeAccount extends CRM_Core_Form { /** * Process the form submission. */ - public function postProcess() { + public function postProcess(): void { if ($this->_action & CRM_Core_Action::DELETE) { try { - CRM_Financial_BAO_FinancialTypeAccount::del($this->_id); - CRM_Financial_BAO_EntityFinancialAccount::del($this->_id); + EntityFinancialAccount::delete()->addWhere('id', '=', $this->_id)->execute(); } catch (CRM_Core_Exception $e) { - CRM_Core_Session::setStatus($e->message); - return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/financial/financialType/accounts', "reset=1&action=browse&aid={$this->_aid}")); + CRM_Core_Session::setStatus($e->getMessage()); + CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/financial/financialType/accounts', "reset=1&action=browse&aid={$this->_aid}")); } CRM_Core_Session::setStatus(ts('Selected financial type account has been deleted.')); } else { - $params = $ids = []; + $ids = []; // store the submitted values in an array $params = $this->exportValues(); diff --git a/tests/phpunit/CRM/Financial/BAO/FinancialTypeAccountTest.php b/tests/phpunit/CRM/Financial/BAO/FinancialTypeAccountTest.php index 20e45f83ec..29211640a4 100644 --- a/tests/phpunit/CRM/Financial/BAO/FinancialTypeAccountTest.php +++ b/tests/phpunit/CRM/Financial/BAO/FinancialTypeAccountTest.php @@ -38,21 +38,6 @@ class CRM_Financial_BAO_FinancialTypeAccountTest extends CiviUnitTestCase { $this->assertEquals($result, $financialType->id, 'Verify Account Type'); } - /** - * Check method del() - */ - public function testDel() { - list($financialAccount, $financialType, $financialAccountType) = $this->createFinancialAccount( - 'Expenses', - 'Expense Account is' - ); - - CRM_Financial_BAO_EntityFinancialAccount::del($financialAccountType->id); - $params = ['id' => $financialAccountType->id]; - $result = CRM_Financial_BAO_FinancialType::retrieve($params, $defaults); - $this->assertEquals(empty($result), TRUE, 'Verify financial types record deletion.'); - } - /** * Check method retrieve() */ -- 2.25.1