Follow up on EntityFinancialAccount delete
authorEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 29 Nov 2022 22:59:45 +0000 (11:59 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 29 Nov 2022 22:59:45 +0000 (11:59 +1300)
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
CRM/Financial/Form/FinancialTypeAccount.php
tests/phpunit/CRM/Financial/BAO/FinancialTypeAccountTest.php

index f100f717bbc59bee762b38a8700db0ad84af81ae..c2d8839d5d6706347afaf705dab923907c401ce4 100644 (file)
@@ -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]);
   }
 
index 15abe94df53da83d3bd6d7c9ecdeb7eb09db1783..3180d3830fa298183e96e4c803c9d93b4dcfba0e 100644 (file)
@@ -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();
 
index 20e45f83ecca2b2fcd8dcd649992380bf625fef4..29211640a4f48f03b0bd1c51f90a64afb6e12945 100644 (file)
@@ -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()
    */