dev/core#2046 Migrate BAO_Address::create towards standardisation
[civicrm-core.git] / tests / phpunit / CRM / Core / BAO / AddressTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 * Class CRM_Core_BAO_AddressTest
14 * @group headless
15 */
16 class CRM_Core_BAO_AddressTest extends CiviUnitTestCase {
17
18 use CRMTraits_Custom_CustomDataTrait;
19
20 public function setUp() {
21 parent::setUp();
22
23 $this->quickCleanup(['civicrm_contact', 'civicrm_address']);
24 }
25
26 /**
27 * Create() method (create and update modes)
28 */
29 public function testCreate() {
30 $contactId = $this->individualCreate();
31
32 $params = [];
33 $params['address']['1'] = [
34 'street_address' => 'Oberoi Garden',
35 'supplemental_address_1' => 'Attn: Accounting',
36 'supplemental_address_2' => 'Powai',
37 'supplemental_address_3' => 'Somewhere',
38 'city' => 'Athens',
39 'postal_code' => '01903',
40 'state_province_id' => '1000',
41 'country_id' => '1228',
42 'geo_code_1' => '18.219023',
43 'geo_code_2' => '-105.00973',
44 'location_type_id' => '1',
45 'is_primary' => '1',
46 'is_billing' => '0',
47 ];
48
49 $params['contact_id'] = $contactId;
50
51 $fixAddress = TRUE;
52
53 CRM_Core_BAO_Address::legacyCreate($params, $fixAddress);
54 $addressId = $this->assertDBNotNull('CRM_Core_DAO_Address', 'Oberoi Garden', 'id', 'street_address',
55 'Database check for created address.'
56 );
57
58 // Now call add() to modify an existing address
59
60 $params = [];
61 $params['address']['1'] = [
62 'id' => $addressId,
63 'street_address' => '120 Terminal Road',
64 'supplemental_address_1' => 'A-wing:3037',
65 'supplemental_address_2' => 'Bandra',
66 'supplemental_address_3' => 'Somewhere',
67 'city' => 'Athens',
68 'postal_code' => '01903',
69 'state_province_id' => '1000',
70 'country_id' => '1228',
71 'geo_code_1' => '18.219023',
72 'geo_code_2' => '-105.00973',
73 'location_type_id' => '1',
74 'is_primary' => '1',
75 'is_billing' => '0',
76 ];
77 $params['contact_id'] = $contactId;
78
79 $block = CRM_Core_BAO_Address::legacyCreate($params, $fixAddress);
80
81 $this->assertDBNotNull('CRM_Core_DAO_Address', $contactId, 'id', 'contact_id',
82 'Database check for updated address by contactId.'
83 );
84 $this->assertDBNotNull('CRM_Core_DAO_Address', '120 Terminal Road', 'id', 'street_address',
85 'Database check for updated address by street_name.'
86 );
87 $this->contactDelete($contactId);
88 }
89
90 /**
91 * Add() method ( )
92 */
93 public function testAdd() {
94 $contactId = $this->individualCreate();
95
96 $fixParams = [
97 'street_address' => 'E 906N Pine Pl W',
98 'supplemental_address_1' => 'Editorial Dept',
99 'supplemental_address_2' => '',
100 'supplemental_address_3' => '',
101 'city' => 'El Paso',
102 'postal_code' => '88575',
103 'postal_code_suffix' => '',
104 'state_province_id' => '1001',
105 'country_id' => '1228',
106 'geo_code_1' => '31.694842',
107 'geo_code_2' => '-106.29998',
108 'location_type_id' => '1',
109 'is_primary' => '1',
110 'is_billing' => '0',
111 'contact_id' => $contactId,
112 ];
113
114 $addAddress = CRM_Core_BAO_Address::add($fixParams, $fixAddress = TRUE);
115
116 $addParams = $this->assertDBNotNull('CRM_Core_DAO_Address', $contactId, 'id', 'contact_id',
117 'Database check for created contact address.'
118 );
119
120 $this->assertEquals($addAddress->street_address, 'E 906N Pine Pl W', 'In line' . __LINE__);
121 $this->assertEquals($addAddress->supplemental_address_1, 'Editorial Dept', 'In line' . __LINE__);
122 $this->assertEquals($addAddress->city, 'El Paso', 'In line' . __LINE__);
123 $this->assertEquals($addAddress->postal_code, '88575', 'In line' . __LINE__);
124 $this->assertEquals($addAddress->geo_code_1, '31.694842', 'In line' . __LINE__);
125 $this->assertEquals($addAddress->geo_code_2, '-106.29998', 'In line' . __LINE__);
126 $this->assertEquals($addAddress->country_id, '1228', 'In line' . __LINE__);
127 $this->contactDelete($contactId);
128 }
129
130 /**
131 * AllAddress() method ( )
132 */
133 public function testallAddress() {
134 $contactId = $this->individualCreate();
135
136 $fixParams = [
137 'street_address' => 'E 906N Pine Pl W',
138 'supplemental_address_1' => 'Editorial Dept',
139 'supplemental_address_2' => '',
140 'supplemental_address_3' => '',
141 'city' => 'El Paso',
142 'postal_code' => '88575',
143 'postal_code_suffix' => '',
144 'state_province_id' => '1001',
145 'country_id' => '1228',
146 'geo_code_1' => '31.694842',
147 'geo_code_2' => '-106.29998',
148 'location_type_id' => '1',
149 'is_primary' => '1',
150 'is_billing' => '0',
151 'contact_id' => $contactId,
152 ];
153
154 CRM_Core_BAO_Address::add($fixParams, $fixAddress = TRUE);
155
156 $addParams = $this->assertDBNotNull('CRM_Core_DAO_Address', $contactId, 'id', 'contact_id',
157 'Database check for created contact address.'
158 );
159 $fixParams = [
160 'street_address' => 'SW 719B Beech Dr NW',
161 'supplemental_address_1' => 'C/o OPDC',
162 'supplemental_address_2' => '',
163 'supplemental_address_3' => '',
164 'city' => 'Neillsville',
165 'postal_code' => '54456',
166 'postal_code_suffix' => '',
167 'state_province_id' => '1001',
168 'country_id' => '1228',
169 'geo_code_1' => '44.553719',
170 'geo_code_2' => '-90.61457',
171 'location_type_id' => '2',
172 'is_primary' => '',
173 'is_billing' => '1',
174 'contact_id' => $contactId,
175 ];
176
177 CRM_Core_BAO_Address::add($fixParams, $fixAddress = TRUE);
178
179 $addParams = $this->assertDBNotNull('CRM_Core_DAO_Address', $contactId, 'id', 'contact_id',
180 'Database check for created contact address.'
181 );
182
183 $allAddress = CRM_Core_BAO_Address::allAddress($contactId);
184
185 $this->assertEquals(count($allAddress), 2, 'Checking number of returned addresses.');
186
187 $this->contactDelete($contactId);
188 }
189
190 /**
191 * AllAddress() method ( ) with null value
192 */
193 public function testnullallAddress() {
194 $contactId = $this->individualCreate();
195
196 $fixParams = [
197 'street_address' => 'E 906N Pine Pl W',
198 'supplemental_address_1' => 'Editorial Dept',
199 'supplemental_address_2' => '',
200 'supplemental_address_3' => '',
201 'city' => 'El Paso',
202 'postal_code' => '88575',
203 'postal_code_suffix' => '',
204 'state_province_id' => '1001',
205 'country_id' => '1228',
206 'geo_code_1' => '31.694842',
207 'geo_code_2' => '-106.29998',
208 'location_type_id' => '1',
209 'is_primary' => '1',
210 'is_billing' => '0',
211 'contact_id' => $contactId,
212 ];
213
214 CRM_Core_BAO_Address::add($fixParams, $fixAddress = TRUE);
215
216 $addParams = $this->assertDBNotNull('CRM_Core_DAO_Address', $contactId, 'id', 'contact_id',
217 'Database check for created contact address.'
218 );
219
220 $contact_Id = NULL;
221
222 $allAddress = CRM_Core_BAO_Address::allAddress($contact_Id);
223
224 $this->assertEquals($allAddress, NULL, 'Checking null for returned addresses.');
225
226 $this->contactDelete($contactId);
227 }
228
229 /**
230 * GetValues() method (get Address fields)
231 */
232 public function testGetValues() {
233 $contactId = $this->individualCreate();
234
235 $params = [];
236 $params['address']['1'] = [
237 'street_address' => 'Oberoi Garden',
238 'supplemental_address_1' => 'Attn: Accounting',
239 'supplemental_address_2' => 'Powai',
240 'supplemental_address_3' => 'Somewhere',
241 'city' => 'Athens',
242 'postal_code' => '01903',
243 'state_province_id' => '1000',
244 'country_id' => '1228',
245 'geo_code_1' => '18.219023',
246 'geo_code_2' => '-105.00973',
247 'location_type_id' => '1',
248 'is_primary' => '1',
249 'is_billing' => '0',
250 ];
251
252 $params['contact_id'] = $contactId;
253
254 $fixAddress = TRUE;
255
256 CRM_Core_BAO_Address::legacyCreate($params, $fixAddress);
257
258 $addressId = $this->assertDBNotNull('CRM_Core_DAO_Address', $contactId, 'id', 'contact_id',
259 'Database check for created address.'
260 );
261
262 $entityBlock = ['contact_id' => $contactId];
263 $address = CRM_Core_BAO_Address::getValues($entityBlock);
264 $this->assertEquals($address[1]['id'], $addressId);
265 $this->assertEquals($address[1]['contact_id'], $contactId);
266 $this->assertEquals($address[1]['state_province_abbreviation'], 'AL');
267 $this->assertEquals($address[1]['state_province'], 'Alabama');
268 $this->assertEquals($address[1]['country'], 'United States');
269 $this->assertEquals($address[1]['street_address'], 'Oberoi Garden');
270 $this->contactDelete($contactId);
271 }
272
273 /**
274 * Enable street address parsing.
275 *
276 * @param string $status
277 *
278 * @throws \CRM_Core_Exception
279 */
280 public function setStreetAddressParsing($status) {
281 $options = $this->callAPISuccess('Setting', 'getoptions', ['field' => 'address_options'])['values'];
282 $address_options = reset($this->callAPISuccess('Setting', 'get', ['return' => 'address_options'])['values'])['address_options'];
283 $parsingOption = array_search('Street Address Parsing', $options, TRUE);
284 $optionKey = array_search($parsingOption, $address_options, FALSE);
285 if ($status && !$optionKey) {
286 $address_options[] = $parsingOption;
287 }
288 if (!$status && $optionKey) {
289 unset($address_options[$optionKey]);
290 }
291 $this->callAPISuccess('Setting', 'create', ['address_options' => $address_options]);
292 }
293
294 /**
295 * ParseStreetAddress if enabled, otherwise, don't.
296 *
297 * @throws \CRM_Core_Exception
298 * @throws \CiviCRM_API3_Exception
299 */
300 public function testParseStreetAddressIfEnabled() {
301 // Turn off address standardization. Parsing should work without it.
302 Civi::settings()->set('address_standardization_provider', NULL);
303
304 // Ensure street parsing happens if enabled.
305 $this->setStreetAddressParsing(TRUE);
306
307 $contactId = $this->individualCreate();
308 $street_address = '54 Excelsior Ave.';
309 $params = [
310 'contact_id' => $contactId,
311 'street_address' => $street_address,
312 'location_type_id' => 1,
313 ];
314
315 $result = civicrm_api3('Address', 'create', $params);
316 $value = array_pop($result['values']);
317 $street_number = $value['street_number'] ?? NULL;
318 $this->assertEquals($street_number, '54');
319
320 // Ensure street parsing does not happen if disabled.
321 $this->setStreetAddressParsing(FALSE);
322 $result = civicrm_api3('Address', 'create', $params);
323 $value = array_pop($result['values']);
324 $street_number = $value['street_number'] ?? NULL;
325 $this->assertEmpty($street_number);
326
327 }
328
329 /**
330 * ParseStreetAddress() method (get street address parsed)
331 */
332 public function testParseStreetAddress() {
333
334 // valid Street address to be parsed ( without locale )
335 $street_address = "54A Excelsior Ave. Apt 1C";
336 $parsedStreetAddress = CRM_Core_BAO_Address::parseStreetAddress($street_address);
337 $this->assertEquals($parsedStreetAddress['street_name'], 'Excelsior Ave.');
338 $this->assertEquals($parsedStreetAddress['street_unit'], 'Apt 1C');
339 $this->assertEquals($parsedStreetAddress['street_number'], '54');
340 $this->assertEquals($parsedStreetAddress['street_number_suffix'], 'A');
341
342 // Out-of-range street number to be parsed.
343 $street_address = '505050505050 Main St';
344 $parsedStreetAddress = CRM_Core_BAO_Address::parseStreetAddress($street_address);
345 $this->assertEquals($parsedStreetAddress['street_name'], '');
346 $this->assertEquals($parsedStreetAddress['street_unit'], '');
347 $this->assertEquals($parsedStreetAddress['street_number'], '');
348 $this->assertEquals($parsedStreetAddress['street_number_suffix'], '');
349
350 // valid Street address to be parsed ( $locale = 'en_US' )
351 $street_address = "54A Excelsior Ave. Apt 1C";
352 $locale = 'en_US';
353 $parsedStreetAddress = CRM_Core_BAO_Address::parseStreetAddress($street_address, $locale);
354 $this->assertEquals($parsedStreetAddress['street_name'], 'Excelsior Ave.');
355 $this->assertEquals($parsedStreetAddress['street_unit'], 'Apt 1C');
356 $this->assertEquals($parsedStreetAddress['street_number'], '54');
357 $this->assertEquals($parsedStreetAddress['street_number_suffix'], 'A');
358
359 // invalid Street address ( $locale = 'en_US' )
360 $street_address = "West St. Apt 1";
361 $locale = 'en_US';
362 $parsedStreetAddress = CRM_Core_BAO_Address::parseStreetAddress($street_address, $locale);
363 $this->assertEquals($parsedStreetAddress['street_name'], 'West St.');
364 $this->assertEquals($parsedStreetAddress['street_unit'], 'Apt 1');
365 $this->assertNotContains('street_number', $parsedStreetAddress);
366 $this->assertNotContains('street_number_suffix', $parsedStreetAddress);
367
368 // valid Street address to be parsed ( $locale = 'fr_CA' )
369 $street_address = "2-123CA Main St";
370 $locale = 'fr_CA';
371 $parsedStreetAddress = CRM_Core_BAO_Address::parseStreetAddress($street_address, $locale);
372 $this->assertEquals($parsedStreetAddress['street_name'], 'Main St');
373 $this->assertEquals($parsedStreetAddress['street_unit'], '2');
374 $this->assertEquals($parsedStreetAddress['street_number'], '123');
375 $this->assertEquals($parsedStreetAddress['street_number_suffix'], 'CA');
376
377 // invalid Street address ( $locale = 'fr_CA' )
378 $street_address = "123 Main St";
379 $locale = 'fr_CA';
380 $parsedStreetAddress = CRM_Core_BAO_Address::parseStreetAddress($street_address, $locale);
381 $this->assertEquals($parsedStreetAddress['street_name'], 'Main St');
382 $this->assertEquals($parsedStreetAddress['street_number'], '123');
383 $this->assertNotContains('street_unit', $parsedStreetAddress);
384 $this->assertNotContains('street_number_suffix', $parsedStreetAddress);
385 }
386
387 /**
388 * @dataProvider supportedAddressParsingLocales
389 */
390 public function testIsSupportedByAddressParsingReturnTrueForSupportedLocales($locale) {
391 $isSupported = CRM_Core_BAO_Address::isSupportedParsingLocale($locale);
392 $this->assertTrue($isSupported);
393 }
394
395 /**
396 * @dataProvider supportedAddressParsingLocales
397 */
398 public function testIsSupportedByAddressParsingReturnTrueForSupportedDefaultLocales($locale) {
399 CRM_Core_Config::singleton()->lcMessages = $locale;
400 $isSupported = CRM_Core_BAO_Address::isSupportedParsingLocale();
401 $this->assertTrue($isSupported);
402
403 }
404
405 public function supportedAddressParsingLocales() {
406 return [
407 ['en_US'],
408 ['en_CA'],
409 ['fr_CA'],
410 ];
411 }
412
413 /**
414 * @dataProvider sampleOFUnsupportedAddressParsingLocales
415 */
416 public function testIsSupportedByAddressParsingReturnFalseForUnSupportedLocales($locale) {
417 $isNotSupported = CRM_Core_BAO_Address::isSupportedParsingLocale($locale);
418 $this->assertFalse($isNotSupported);
419 }
420
421 /**
422 * @dataProvider sampleOFUnsupportedAddressParsingLocales
423 */
424 public function testIsSupportedByAddressParsingReturnFalseForUnSupportedDefaultLocales($locale) {
425 CRM_Core_Config::singleton()->lcMessages = $locale;
426 $isNotSupported = CRM_Core_BAO_Address::isSupportedParsingLocale();
427 $this->assertFalse($isNotSupported);
428 }
429
430 public function sampleOFUnsupportedAddressParsingLocales() {
431 return [
432 ['en_GB'],
433 ['af_ZA'],
434 ['da_DK'],
435 ];
436 }
437
438 /**
439 * CRM-21214 - Ensure all child addresses are updated correctly - 1.
440 * 1. First, create three contacts: A, B, and C
441 * 2. Create an address for contact A
442 * 3. Use contact A's address for contact B
443 * 4. Use contact B's address for contact C
444 * 5. Change contact A's address
445 * Address of Contact C should reflect contact A's address change
446 * Also, Contact C's address' master_id should be Contact A's address id.
447 */
448 public function testSharedAddressChaining1() {
449 $contactIdA = $this->individualCreate([], 0);
450 $contactIdB = $this->individualCreate([], 1);
451 $contactIdC = $this->individualCreate([], 2);
452
453 $addressParamsA = [
454 'street_address' => '123 Fake St.',
455 'location_type_id' => '1',
456 'is_primary' => '1',
457 'contact_id' => $contactIdA,
458 ];
459 $addAddressA = CRM_Core_BAO_Address::add($addressParamsA, FALSE);
460
461 $addressParamsB = [
462 'street_address' => '123 Fake St.',
463 'location_type_id' => '1',
464 'is_primary' => '1',
465 'master_id' => $addAddressA->id,
466 'contact_id' => $contactIdB,
467 ];
468 $addAddressB = CRM_Core_BAO_Address::add($addressParamsB, FALSE);
469
470 $addressParamsC = [
471 'street_address' => '123 Fake St.',
472 'location_type_id' => '1',
473 'is_primary' => '1',
474 'master_id' => $addAddressB->id,
475 'contact_id' => $contactIdC,
476 ];
477 $addAddressC = CRM_Core_BAO_Address::add($addressParamsC, FALSE);
478
479 $updatedAddressParamsA = [
480 'id' => $addAddressA->id,
481 'street_address' => '1313 New Address Lane',
482 'location_type_id' => '1',
483 'is_primary' => '1',
484 'contact_id' => $contactIdA,
485 ];
486 $updatedAddressA = CRM_Core_BAO_Address::add($updatedAddressParamsA, FALSE);
487
488 // CRM-21214 - Has Address C been updated with Address A's new values?
489 $newAddressC = new CRM_Core_DAO_Address();
490 $newAddressC->id = $addAddressC->id;
491 $newAddressC->find(TRUE);
492 $newAddressC->fetch(TRUE);
493
494 $this->assertEquals($updatedAddressA->street_address, $newAddressC->street_address);
495 $this->assertEquals($updatedAddressA->id, $newAddressC->master_id);
496 }
497
498 /**
499 * CRM-21214 - Ensure all child addresses are updated correctly - 2.
500 * 1. First, create three contacts: A, B, and C
501 * 2. Create an address for contact A and B
502 * 3. Use contact A's address for contact C
503 * 4. Use contact B's address for contact A
504 * 5. Change contact B's address
505 * Address of Contact C should reflect contact B's address change
506 * Also, Contact C's address' master_id should be Contact B's address id.
507 */
508 public function testSharedAddressChaining2() {
509 $contactIdA = $this->individualCreate([], 0);
510 $contactIdB = $this->individualCreate([], 1);
511 $contactIdC = $this->individualCreate([], 2);
512
513 $addressParamsA = [
514 'street_address' => '123 Fake St.',
515 'location_type_id' => '1',
516 'is_primary' => '1',
517 'contact_id' => $contactIdA,
518 ];
519 $addAddressA = CRM_Core_BAO_Address::add($addressParamsA, FALSE);
520
521 $addressParamsB = [
522 'street_address' => '123 Fake St.',
523 'location_type_id' => '1',
524 'is_primary' => '1',
525 'contact_id' => $contactIdB,
526 ];
527 $addAddressB = CRM_Core_BAO_Address::add($addressParamsB, FALSE);
528
529 $addressParamsC = [
530 'street_address' => '123 Fake St.',
531 'location_type_id' => '1',
532 'is_primary' => '1',
533 'master_id' => $addAddressA->id,
534 'contact_id' => $contactIdC,
535 ];
536 $addAddressC = CRM_Core_BAO_Address::add($addressParamsC, FALSE);
537
538 $updatedAddressParamsA = [
539 'id' => $addAddressA->id,
540 'street_address' => '123 Fake St.',
541 'location_type_id' => '1',
542 'is_primary' => '1',
543 'master_id' => $addAddressB->id,
544 'contact_id' => $contactIdA,
545 ];
546 $updatedAddressA = CRM_Core_BAO_Address::add($updatedAddressParamsA, FALSE);
547
548 $updatedAddressParamsB = [
549 'id' => $addAddressB->id,
550 'street_address' => '1313 New Address Lane',
551 'location_type_id' => '1',
552 'is_primary' => '1',
553 'contact_id' => $contactIdB,
554 ];
555 $updatedAddressB = CRM_Core_BAO_Address::add($updatedAddressParamsB, FALSE);
556
557 // CRM-21214 - Has Address C been updated with Address B's new values?
558 $newAddressC = new CRM_Core_DAO_Address();
559 $newAddressC->id = $addAddressC->id;
560 $newAddressC->find(TRUE);
561 $newAddressC->fetch(TRUE);
562
563 $this->assertEquals($updatedAddressB->street_address, $newAddressC->street_address);
564 $this->assertEquals($updatedAddressB->id, $newAddressC->master_id);
565 }
566
567 /**
568 * CRM-21214 - Ensure all child addresses are updated correctly - 3.
569 * 1. First, create a contact: A
570 * 2. Create an address for contact A
571 * 3. Use contact A's address for contact A's address
572 * An error should be given, and master_id should remain the same.
573 */
574 public function testSharedAddressChaining3() {
575 $contactIdA = $this->individualCreate([], 0);
576
577 $addressParamsA = [
578 'street_address' => '123 Fake St.',
579 'location_type_id' => '1',
580 'is_primary' => '1',
581 'contact_id' => $contactIdA,
582 ];
583 $addAddressA = CRM_Core_BAO_Address::add($addressParamsA, FALSE);
584
585 $updatedAddressParamsA = [
586 'id' => $addAddressA->id,
587 'street_address' => '123 Fake St.',
588 'location_type_id' => '1',
589 'is_primary' => '1',
590 'master_id' => $addAddressA->id,
591 'contact_id' => $contactIdA,
592 ];
593 $updatedAddressA = CRM_Core_BAO_Address::add($updatedAddressParamsA, FALSE);
594
595 // CRM-21214 - AdressA shouldn't be master of itself.
596 $this->assertEmpty($updatedAddressA->master_id);
597 }
598
599 /**
600 * dev/core#1670 - Ensure that the custom fields on adresses are copied
601 * to inherited address
602 * 1. test the creation of the shared address with custom field
603 * 2. test the update of the custom field in the master
604 */
605 public function testSharedAddressCustomField() {
606
607 $this->createCustomGroupWithFieldOfType(['extends' => 'Address'], 'text');
608 $customField = $this->getCustomFieldName('text');
609
610 $contactIdA = $this->individualCreate([], 0);
611 $contactIdB = $this->individualCreate([], 1);
612
613 $addressParamsA = [
614 'street_address' => '123 Fake St.',
615 'location_type_id' => '1',
616 'is_primary' => '1',
617 'contact_id' => $contactIdA,
618 $customField => 'this is a custom text field',
619 ];
620
621 $addAddressA = CRM_Core_BAO_Address::add($addressParamsA, FALSE);
622
623 // without having the custom field, we should still copy the values from master
624 $addressParamsB = [
625 'street_address' => '123 Fake St.',
626 'location_type_id' => '1',
627 'is_primary' => '1',
628 'master_id' => $addAddressA->id,
629 'contact_id' => $contactIdB,
630 ];
631 $addAddressB = CRM_Core_BAO_Address::add($addressParamsB, FALSE);
632
633 // 1. check if the custom fields values have been copied from master to shared address
634 $address = $this->callAPISuccessGetSingle('Address', ['id' => $addAddressB->id, 'return' => $this->getCustomFieldName('text')]);
635 $this->assertEquals($addressParamsA[$customField], $address[$customField]);
636
637 // 2. now, we update addressA custom field to see if it goes into addressB
638 $addressParamsA['id'] = $addAddressA->id;
639 $addressParamsA[$customField] = 'updated custom text field';
640 $addAddressA = CRM_Core_BAO_Address::add($addressParamsA, FALSE);
641
642 $address = $this->callAPISuccessGetSingle('Address', ['id' => $addAddressB->id, 'return' => $this->getCustomFieldName('text')]);
643 $this->assertEquals($addressParamsA[$customField], $address[$customField]);
644
645 }
646
647 }