BAO - Refactor Address add/create to use writeRecord
authorColeman Watts <coleman@civicrm.org>
Tue, 28 Mar 2023 14:25:01 +0000 (10:25 -0400)
committerColeman Watts <coleman@civicrm.org>
Wed, 29 Mar 2023 21:58:51 +0000 (17:58 -0400)
CRM/Contribute/BAO/Contribution.php
CRM/Core/BAO/Address.php
CRM/Core/BAO/Block.php
CRM/Event/Form/ManageEvent/Location.php
Civi/Api4/Action/Address/AddressSaveTrait.php
Civi/Test/Api3TestTrait.php
api/v3/Address.php
tests/phpunit/CRM/Contact/BAO/ContactTest.php
tests/phpunit/CRM/Core/BAO/AddressTest.php
tests/phpunit/api/v3/AddressTest.php
tests/phpunit/api/v3/PaymentTest.php

index b1971d2add56adfd88302548caa7d2523a49482b..04e96089834f1ac3e50c76d48e990be8fa29172a 100644 (file)
@@ -1663,7 +1663,7 @@ LEFT JOIN civicrm_option_value contribution_status ON (civicrm_contribution.cont
   public static function createAddress($params, $billingLocationTypeID) {
     [$hasBillingField, $addressParams] = self::getBillingAddressParams($params, $billingLocationTypeID);
     if ($hasBillingField) {
-      $address = CRM_Core_BAO_Address::add($addressParams, FALSE);
+      $address = CRM_Core_BAO_Address::writeRecord($addressParams);
       return $address->id;
     }
     return NULL;
index 004922b0d345ca5d9867c4ac187c1e8b8fda877a..909b4e607fb87ece0dd6ad129d13bbb436ab6188 100644 (file)
@@ -20,96 +20,70 @@ use Civi\Api4\Address;
 /**
  * This is class to handle address related functions.
  */
-class CRM_Core_BAO_Address extends CRM_Core_DAO_Address {
+class CRM_Core_BAO_Address extends CRM_Core_DAO_Address implements Civi\Core\HookInterface {
   use CRM_Contact_AccessTrait;
 
   /**
-   * Takes an associative array and creates a address.
+   * @deprecated
    *
    * @param array $params
-   *   (reference ) an assoc array of name/value pairs.
    * @param bool $fixAddress
-   *   True if you need to fix (format) address values.
-   *                               before inserting in db
-   *
-   * @return array|NULL|self
-   *   array of created address
+   * @return CRM_Core_BAO_Address
+   * @throws CRM_Core_Exception
    */
   public static function create(array &$params, $fixAddress = TRUE) {
-    return self::add($params, $fixAddress);
+    CRM_Core_Error::deprecatedFunctionWarning('writeRecord');
+    if ($fixAddress) {
+      CRM_Core_BAO_Address::fixAddress($params);
+    }
+    return self::writeRecord($params);
   }
 
   /**
-   * Takes an associative array and adds address.
+   * @deprecated
    *
    * @param array $params
-   *   (reference ) an assoc array of name/value pairs.
    * @param bool $fixAddress
-   *   True if you need to fix (format) address values.
-   *                               before inserting in db
-   *
-   * @return CRM_Core_BAO_Address|null
+   * @return CRM_Core_BAO_Address
+   * @throws CRM_Core_Exception
    */
   public static function add(&$params, $fixAddress = FALSE) {
+    return self::create($params, $fixAddress);
+  }
 
-    $address = new CRM_Core_DAO_Address();
-    $checkPermissions = $params['check_permissions'] ?? TRUE;
-
-    // fixAddress mode to be done
-    if ($fixAddress) {
-      CRM_Core_BAO_Address::fixAddress($params);
-    }
-
-    $hook = empty($params['id']) ? 'create' : 'edit';
-    CRM_Utils_Hook::pre($hook, 'Address', CRM_Utils_Array::value('id', $params), $params);
-
-    CRM_Core_BAO_Block::handlePrimary($params, get_class());
-    CRM_Core_BAO_Block::handleBilling($params, get_class());
-
-    // (prevent chaining 1 and 3) CRM-21214
-    if (isset($params['master_id']) && !CRM_Utils_System::isNull($params['master_id'])) {
-      self::fixSharedAddress($params);
-    }
-
-    $address->copyValues($params);
-    $address->save();
-
-    if ($address->id) {
-      // first get custom field from master address if any
-      if (isset($params['master_id']) && !CRM_Utils_System::isNull($params['master_id'])) {
-        $address->copyCustomFields($params['master_id'], $address->id, $hook);
+  /**
+   * Event fired before modifying an Address.
+   * @param \Civi\Core\Event\PreEvent $event
+   */
+  public static function self_hook_civicrm_pre(\Civi\Core\Event\PreEvent $event) {
+    if (in_array($event->action, ['create', 'edit'])) {
+      CRM_Core_BAO_Block::handlePrimary($event->params, __CLASS__);
+      CRM_Core_BAO_Block::handleBilling($event->params, __CLASS__);
+
+      // (prevent chaining 1 and 3) CRM-21214
+      if (isset($event->params['master_id']) && !CRM_Utils_System::isNull($event->params['master_id'])) {
+        self::fixSharedAddress($event->params);
       }
+    }
+  }
 
-      if (isset($params['custom'])) {
-        $addressCustom = $params['custom'];
-      }
-      else {
-        $customFields = CRM_Core_BAO_CustomField::getFields('Address', FALSE, TRUE, NULL, NULL,
-          FALSE, FALSE, $checkPermissions ? CRM_Core_Permission::EDIT : FALSE);
-
-        if (!empty($customFields)) {
-          $addressCustom = CRM_Core_BAO_CustomField::postProcess($params,
-            $address->id,
-            'Address',
-            FALSE,
-            $checkPermissions
-          );
-        }
-      }
-      if (!empty($addressCustom)) {
-        CRM_Core_BAO_CustomValueTable::store($addressCustom, 'civicrm_address', $address->id, $hook);
+  /**
+   * Event fired after modifying an Address.
+   * @param \Civi\Core\Event\PostEvent $event
+   */
+  public static function self_hook_civicrm_post(\Civi\Core\Event\PostEvent $event) {
+    // Copy custom data from master address if not supplied
+    if ($event->action === 'create' && !isset($event->params['custom'])) {
+      if (isset($event->params['master_id']) && !CRM_Utils_System::isNull($event->params['master_id'])) {
+        $event->object->copyCustomFields($event->params['master_id'], $event->id, $event->action);
       }
-
+    }
+    if (in_array($event->action, ['create', 'edit'])) {
       // call the function to sync shared address and create relationships
       // if address is already shared, share master_id with all children and update relationships accordingly
       // (prevent chaining 2) CRM-21214
-      self::processSharedAddress($address->id, $params, $hook);
-
-      // lets call the post hook only after we've done all the follow on processing
-      CRM_Utils_Hook::post($hook, 'Address', $address->id, $address);
+      self::processSharedAddress($event->id, $event->params, $event->action);
     }
-
-    return $address;
   }
 
   /**
@@ -1336,7 +1310,6 @@ SELECT is_primary,
       return NULL;
     }
     CRM_Core_BAO_Block::sortPrimaryFirst($params['address']);
-    $contactId = NULL;
 
     $updateBlankLocInfo = CRM_Utils_Array::value('updateBlankLocInfo', $params, FALSE);
     $contactId = $params['contact_id'];
@@ -1386,7 +1359,17 @@ SELECT is_primary,
         $value['manual_geo_code'] = 0;
       }
       $value['contact_id'] = $contactId;
-      $blocks[] = self::add($value, $fixAddress);
+
+      if ($fixAddress) {
+        self::fixAddress($value);
+      }
+
+      // Format custom data
+      if (!isset($value['custom'])) {
+        $value['custom'] = CRM_Core_BAO_CustomField::postProcess($value, $value['id'] ?? NULL, 'Address');
+      }
+
+      $blocks[] = self::writeRecord($value);
     }
     return $blocks;
   }
index 506e9515763b24fae9b0dcfe9c3e31b83351201d..a5abbe73c827d5667d5195414c27979ca29fb239 100644 (file)
@@ -282,7 +282,10 @@ class CRM_Core_BAO_Block {
       }
 
       $blockFields = array_merge($value, $contactFields);
-      $blocks[] = $baoString::create($blockFields);
+      if ($baoString === 'CRM_Core_BAO_Address') {
+        CRM_Core_BAO_Address::fixAddress($blockFields);
+      }
+      $blocks[] = $baoString::writeRecord($blockFields);
     }
 
     return $blocks;
index 5d7be182ea925f1eb939071680b5903f44c6fef5..cc41a4447fbcb930282f98ace1329fcae95f5042 100644 (file)
@@ -13,7 +13,6 @@ use Civi\Api4\Event;
 use Civi\Api4\LocBlock;
 use Civi\Api4\Email;
 use Civi\Api4\Phone;
-use Civi\Api4\Address;
 
 /**
  *
@@ -331,8 +330,15 @@ class CRM_Event_Form_ManageEvent_Location extends CRM_Event_Form_ManageEvent {
 
     }
 
-    // Update the Blocks.
-    $addresses = empty($params['address']) ? [] : Address::save(FALSE)->setRecords($params['address'])->execute();
+    // Update location Blocks.
+    $addresses = [];
+    // Don't use APIv4 for address because it doesn't handle custom fields in the format used by this form (custom_xx)
+    foreach ($params['address'] ?? [] as $address) {
+      CRM_Core_BAO_Address::fixAddress($address);
+      $address['custom'] = CRM_Core_BAO_CustomField::postProcess($address, $address['id'] ?? NULL, 'Address');
+      $addresses[] = (array) CRM_Core_BAO_Address::writeRecord($address);
+    }
+    // Using APIv4 for email & phone, the form doesn't support custom data for them anyway
     $emails = empty($params['email']) ? [] : Email::save(FALSE)->setRecords($params['email'])->execute();
     $phones = empty($params['phone']) ? [] : Phone::save(FALSE)->setRecords($params['phone'])->execute();
 
index d14fca6a1d9957025554db4812a8cc2ed7724a08..3759e978ed3448810e1eb2e4ad04476515c7d36e 100644 (file)
@@ -55,7 +55,10 @@ trait AddressSaveTrait {
         $item = array_merge($item, \CRM_Core_BAO_Address::parseStreetAddress($item['street_address']));
       }
       $item['skip_geocode'] = $this->skipGeocode;
-      $saved[] = \CRM_Core_BAO_Address::add($item, $this->fixAddress);
+      if ($this->fixAddress) {
+        \CRM_Core_BAO_Address::fixAddress($item);
+      }
+      $saved[] = \CRM_Core_BAO_Address::writeRecord($item);
     }
     return $saved;
   }
index 49d81e97b43560024fcca2cecd9b55a64c3f7dd0..e00452ab9749313cbb76837962450c9cf652a39e 100644 (file)
@@ -428,6 +428,11 @@ trait Api3TestTrait {
           if ($v4Entity != 'Setting' && !in_array('id', $v4Params['select'])) {
             $v4Params['select'][] = 'id';
           }
+          // Convert 'custom' to 'custom.*'
+          $selectCustom = array_search('custom', $v4Params['select']);
+          if ($selectCustom !== FALSE) {
+            $v4Params['select'][$selectCustom] = 'custom.*';
+          }
         }
         if ($options['limit'] && $v4Entity != 'Setting') {
           $v4Params['limit'] = $options['limit'];
index f7988a249ae096f934698d5a02f2b43fd9f3c89d..dd74c46c11b897e498acc5d724d3577a24c7be72 100644 (file)
@@ -60,22 +60,11 @@ function civicrm_api3_address_create($params) {
     $params['check_permissions'] = 0;
   }
 
-  if (!isset($params['fix_address'])) {
-    $params['fix_address'] = TRUE;
+  if (!isset($params['fix_address']) || $params['fix_address']) {
+    CRM_Core_BAO_Address::fixAddress($params);
   }
 
-  /**
-   * Create array for BAO (expects address params in as an
-   * element in array 'address'
-   */
-  $addressBAO = CRM_Core_BAO_Address::create($params, $params['fix_address']);
-  if (empty($addressBAO)) {
-    return civicrm_api3_create_error("Address is not created or updated ");
-  }
-  else {
-    $values = _civicrm_api3_dao_to_array($addressBAO, $params);
-    return civicrm_api3_create_success($values, $params, 'Address', $addressBAO);
-  }
+  return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'Address');
 }
 
 /**
index 180f4f37a457a4f149615f5e9b867d409ca7aeea..e553e538445ab38f429a6fdcce921878b8c2df03 100644 (file)
@@ -1565,7 +1565,7 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase {
       'is_billing' => 1,
       'state_province_id' => '3934',
     ];
-    $addAddressA = CRM_Core_BAO_Address::add($addressParamsA, FALSE);
+    $addAddressA = CRM_Core_BAO_Address::writeRecord($addressParamsA);
 
     $addressParamsB[1] = [
       'contact_id' => $contactIdB,
@@ -1574,7 +1574,7 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase {
     ];
 
     CRM_Contact_BAO_Contact_Utils::processSharedAddress($addressParamsB);
-    $addAddressB = CRM_Core_BAO_Address::add($addressParamsB[1], FALSE);
+    $addAddressB = CRM_Core_BAO_Address::writeRecord($addressParamsB[1]);
 
     foreach ($addAddressA as $key => $value) {
       if (!in_array($key, ['id', 'contact_id', 'master_id', 'is_primary', 'is_billing', 'location_type_id', 'manual_geo_code'])) {
index e1c573bf8f0a4b094b59e56139e0617d5e882faa..5780a6c0a9685ce4a1ae8c9e2ce2f659a5dd212f 100644 (file)
@@ -112,7 +112,8 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase {
       'contact_id' => $contactId,
     ];
 
-    $addAddress = CRM_Core_BAO_Address::add($fixParams, $fixAddress = TRUE);
+    CRM_Core_BAO_Address::fixAddress($fixParams);
+    $addAddress = CRM_Core_BAO_Address::writeRecord($fixParams);
 
     $addParams = $this->assertDBNotNull('CRM_Core_DAO_Address', $contactId, 'id', 'contact_id',
       'Database check for created contact address.'
@@ -216,7 +217,8 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase {
       'contact_id' => $contactId,
     ];
 
-    CRM_Core_BAO_Address::add($params['address']['1'], $fixAddress = TRUE);
+    CRM_Core_BAO_Address::fixAddress($params['address']['1']);
+    CRM_Core_BAO_Address::writeRecord($params['address']['1']);
 
     // Add address 2
     $params['address']['2'] = [
@@ -236,7 +238,8 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase {
       'contact_id' => $contactId,
     ];
 
-    CRM_Core_BAO_Address::add($params['address']['2'], $fixAddress = TRUE);
+    CRM_Core_BAO_Address::fixAddress($params['address']['2']);
+    CRM_Core_BAO_Address::writeRecord($params['address']['2']);
 
     $addresses = CRM_Core_BAO_Address::getValues($entityBlock);
 
@@ -281,7 +284,8 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase {
       'contact_id' => $contactId,
     ];
 
-    CRM_Core_BAO_Address::add($fixParams, $fixAddress = TRUE);
+    CRM_Core_BAO_Address::fixAddress($fixParams);
+    CRM_Core_BAO_Address::writeRecord($fixParams);
 
     $addParams = $this->assertDBNotNull('CRM_Core_DAO_Address', $contactId, 'id', 'contact_id',
       'Database check for created contact address.'
@@ -304,7 +308,8 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase {
       'contact_id' => $contactId,
     ];
 
-    CRM_Core_BAO_Address::add($fixParams, $fixAddress = TRUE);
+    CRM_Core_BAO_Address::fixAddress($fixParams);
+    CRM_Core_BAO_Address::writeRecord($fixParams);
 
     $addParams = $this->assertDBNotNull('CRM_Core_DAO_Address', $contactId, 'id', 'contact_id',
       'Database check for created contact address.'
@@ -341,7 +346,8 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase {
       'contact_id' => $contactId,
     ];
 
-    CRM_Core_BAO_Address::add($fixParams, $fixAddress = TRUE);
+    CRM_Core_BAO_Address::fixAddress($fixParams);
+    CRM_Core_BAO_Address::writeRecord($fixParams);
 
     $addParams = $this->assertDBNotNull('CRM_Core_DAO_Address', $contactId, 'id', 'contact_id',
       'Database check for created contact address.'
@@ -585,7 +591,7 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase {
       'is_primary' => '1',
       'contact_id' => $contactIdA,
     ];
-    $addAddressA = CRM_Core_BAO_Address::add($addressParamsA, FALSE);
+    $addAddressA = CRM_Core_BAO_Address::writeRecord($addressParamsA);
 
     $addressParamsB = [
       'street_address' => '123 Fake St.',
@@ -594,7 +600,7 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase {
       'master_id' => $addAddressA->id,
       'contact_id' => $contactIdB,
     ];
-    $addAddressB = CRM_Core_BAO_Address::add($addressParamsB, FALSE);
+    $addAddressB = CRM_Core_BAO_Address::writeRecord($addressParamsB);
 
     $addressParamsC = [
       'street_address' => '123 Fake St.',
@@ -603,7 +609,7 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase {
       'master_id' => $addAddressB->id,
       'contact_id' => $contactIdC,
     ];
-    $addAddressC = CRM_Core_BAO_Address::add($addressParamsC, FALSE);
+    $addAddressC = CRM_Core_BAO_Address::writeRecord($addressParamsC);
 
     $updatedAddressParamsA = [
       'id' => $addAddressA->id,
@@ -612,7 +618,7 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase {
       'is_primary' => '1',
       'contact_id' => $contactIdA,
     ];
-    $updatedAddressA = CRM_Core_BAO_Address::add($updatedAddressParamsA, FALSE);
+    $updatedAddressA = CRM_Core_BAO_Address::writeRecord($updatedAddressParamsA);
 
     // CRM-21214 - Has Address C been updated with Address A's new values?
     $newAddressC = new CRM_Core_DAO_Address();
@@ -645,7 +651,7 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase {
       'is_primary' => '1',
       'contact_id' => $contactIdA,
     ];
-    $addAddressA = CRM_Core_BAO_Address::add($addressParamsA, FALSE);
+    $addAddressA = CRM_Core_BAO_Address::writeRecord($addressParamsA);
 
     $addressParamsB = [
       'street_address' => '123 Fake St.',
@@ -653,7 +659,7 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase {
       'is_primary' => '1',
       'contact_id' => $contactIdB,
     ];
-    $addAddressB = CRM_Core_BAO_Address::add($addressParamsB, FALSE);
+    $addAddressB = CRM_Core_BAO_Address::writeRecord($addressParamsB);
 
     $addressParamsC = [
       'street_address' => '123 Fake St.',
@@ -662,7 +668,7 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase {
       'master_id' => $addAddressA->id,
       'contact_id' => $contactIdC,
     ];
-    $addAddressC = CRM_Core_BAO_Address::add($addressParamsC, FALSE);
+    $addAddressC = CRM_Core_BAO_Address::writeRecord($addressParamsC);
 
     $updatedAddressParamsA = [
       'id' => $addAddressA->id,
@@ -672,7 +678,7 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase {
       'master_id' => $addAddressB->id,
       'contact_id' => $contactIdA,
     ];
-    $updatedAddressA = CRM_Core_BAO_Address::add($updatedAddressParamsA, FALSE);
+    $updatedAddressA = CRM_Core_BAO_Address::writeRecord($updatedAddressParamsA);
 
     $updatedAddressParamsB = [
       'id' => $addAddressB->id,
@@ -681,7 +687,7 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase {
       'is_primary' => '1',
       'contact_id' => $contactIdB,
     ];
-    $updatedAddressB = CRM_Core_BAO_Address::add($updatedAddressParamsB, FALSE);
+    $updatedAddressB = CRM_Core_BAO_Address::writeRecord($updatedAddressParamsB);
 
     // CRM-21214 - Has Address C been updated with Address B's new values?
     $newAddressC = new CRM_Core_DAO_Address();
@@ -709,7 +715,7 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase {
       'is_primary' => '1',
       'contact_id' => $contactIdA,
     ];
-    $addAddressA = CRM_Core_BAO_Address::add($addressParamsA, FALSE);
+    $addAddressA = CRM_Core_BAO_Address::writeRecord($addressParamsA);
 
     $updatedAddressParamsA = [
       'id' => $addAddressA->id,
@@ -719,7 +725,7 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase {
       'master_id' => $addAddressA->id,
       'contact_id' => $contactIdA,
     ];
-    $updatedAddressA = CRM_Core_BAO_Address::add($updatedAddressParamsA, FALSE);
+    $updatedAddressA = CRM_Core_BAO_Address::writeRecord($updatedAddressParamsA);
 
     // CRM-21214 - AdressA shouldn't be master of itself.
     $this->assertEmpty($updatedAddressA->master_id);
@@ -746,8 +752,9 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase {
       'contact_id' => $contactIdA,
       $customField => 'this is a custom text field',
     ];
+    $addressParamsA['custom'] = CRM_Core_BAO_CustomField::postProcess($addressParamsA, NULL, 'Address');
 
-    $addAddressA = CRM_Core_BAO_Address::add($addressParamsA, FALSE);
+    $addAddressA = CRM_Core_BAO_Address::writeRecord($addressParamsA);
 
     // without having the custom field, we should still copy the values from master
     $addressParamsB = [
@@ -757,7 +764,7 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase {
       'master_id' => $addAddressA->id,
       'contact_id' => $contactIdB,
     ];
-    $addAddressB = CRM_Core_BAO_Address::add($addressParamsB, FALSE);
+    $addAddressB = CRM_Core_BAO_Address::writeRecord($addressParamsB);
 
     // 1. check if the custom fields values have been copied from master to shared address
     $address = $this->callAPISuccessGetSingle('Address', ['id' => $addAddressB->id, 'return' => $this->getCustomFieldName('text')]);
@@ -766,7 +773,8 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase {
     // 2. now, we update addressA custom field to see if it goes into addressB
     $addressParamsA['id'] = $addAddressA->id;
     $addressParamsA[$customField] = 'updated custom text field';
-    $addAddressA = CRM_Core_BAO_Address::add($addressParamsA, FALSE);
+    $addressParamsA['custom'] = CRM_Core_BAO_CustomField::postProcess($addressParamsA, NULL, 'Address');
+    CRM_Core_BAO_Address::writeRecord($addressParamsA);
 
     $address = $this->callAPISuccessGetSingle('Address', ['id' => $addAddressB->id, 'return' => $this->getCustomFieldName('text')]);
     $this->assertEquals($addressParamsA[$customField], $address[$customField]);
@@ -846,7 +854,8 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase {
       'contact_id' => $contactId,
     ];
 
-    $addAddress = CRM_Core_BAO_Address::add($fixParams, TRUE);
+    CRM_Core_BAO_Address::fixAddress($fixParams);
+    $addAddress = CRM_Core_BAO_Address::writeRecord($fixParams);
 
     $addParams = $this->assertDBNotNull('CRM_Core_DAO_Address', $contactId, 'id', 'contact_id',
       'Database check for created contact address.'
index 6ea58248e58bfdaaad2dc92bd2d870036da5031d..271628ae418adb14db047fa1bb06332afae40ee6 100644 (file)
@@ -375,9 +375,11 @@ class api_v3_AddressTest extends CiviUnitTestCase {
   }
 
   /**
-   * FIXME: Api4 custom address fields broken?
+   * @param int $version
+   * @dataProvider versionThreeAndFour
    */
-  public function testGetWithCustom() {
+  public function testGetWithCustom($version) {
+    $this->_apiversion = $version;
     $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
 
     $params = $this->_params;
index 446c5822e129a35d182606b3db97f639f7d3f758..5e407b29934afe2774c05155c5f40ed1340a4a52 100644 (file)
@@ -1184,7 +1184,7 @@ class api_v3_PaymentTest extends CiviUnitTestCase {
       'is_primary' => 1,
     ];
     // api requires contact_id - perhaps incorrectly but use add to get past that.
-    $address = CRM_Core_BAO_Address::add($addressParams);
+    $address = CRM_Core_BAO_Address::writeRecord($addressParams);
 
     $location = $this->callAPISuccess('LocBlock', 'create', ['address_id' => $address->id]);
     $this->callAPISuccess('Event', 'create', [