MergerTest.php (civicrm-core-5.59.2) | : | MergerTest.php (civicrm-core-5.59.3) | ||
---|---|---|---|---|
<?php | <?php | |||
use Civi\Api4\Contact; | ||||
/** | /** | |||
* Class CRM_Dedupe_DedupeMergerTest | * Class CRM_Dedupe_DedupeMergerTest | |||
* | * | |||
* @group headless | * @group headless | |||
*/ | */ | |||
class CRM_Dedupe_MergerTest extends CiviUnitTestCase { | class CRM_Dedupe_MergerTest extends CiviUnitTestCase { | |||
use CRMTraits_Custom_CustomDataTrait; | use CRMTraits_Custom_CustomDataTrait; | |||
protected $_groupId; | protected $_groupId; | |||
skipping to change at line 815 | skipping to change at line 817 | |||
// update the text custom field for original contact with value 'abc' | // update the text custom field for original contact with value 'abc' | |||
$this->callAPISuccess('Contact', 'create', [ | $this->callAPISuccess('Contact', 'create', [ | |||
'id' => $originalContactID, | 'id' => $originalContactID, | |||
$customFieldName => 'abc', | $customFieldName => 'abc', | |||
]); | ]); | |||
$this->assertCustomFieldValue($originalContactID, 'abc', $customFieldName); | $this->assertCustomFieldValue($originalContactID, 'abc', $customFieldName); | |||
// update the text custom field for duplicate contact 1 with value 'def' | // update the text custom field for duplicate contact 1 with value 'def' | |||
$this->callAPISuccess('Contact', 'create', [ | $this->callAPISuccess('Contact', 'create', [ | |||
'id' => $duplicateContactID1, | 'id' => $duplicateContactID1, | |||
"{$customFieldName}" => 'def', | $customFieldName => 'def', | |||
]); | ]); | |||
$this->assertCustomFieldValue($duplicateContactID1, 'def', $customFieldName) ; | $this->assertCustomFieldValue($duplicateContactID1, 'def', $customFieldName) ; | |||
// update the text custom field for duplicate contact 2 with value 'ghi' | // update the text custom field for duplicate contact 2 with value 'ghi' | |||
$this->callAPISuccess('Contact', 'create', [ | $this->callAPISuccess('Contact', 'create', [ | |||
'id' => $duplicateContactID2, | 'id' => $duplicateContactID2, | |||
(string) ($customFieldName) => 'ghi', | (string) ($customFieldName) => 'ghi', | |||
]); | ]); | |||
$this->assertCustomFieldValue($duplicateContactID2, 'ghi', $customFieldName) ; | $this->assertCustomFieldValue($duplicateContactID2, 'ghi', $customFieldName) ; | |||
skipping to change at line 1456 | skipping to change at line 1458 | |||
* Test that declaring a custom join for search kit does not break merge. | * Test that declaring a custom join for search kit does not break merge. | |||
*/ | */ | |||
public function testMergeWithDeclaredSearchJoin(): void { | public function testMergeWithDeclaredSearchJoin(): void { | |||
$this->hookClass->setHook('civicrm_entityTypes', [ | $this->hookClass->setHook('civicrm_entityTypes', [ | |||
$this, | $this, | |||
'hookEntityTypes', | 'hookEntityTypes', | |||
]); | ]); | |||
CRM_Core_DAO_AllCoreTables::flush(); | CRM_Core_DAO_AllCoreTables::flush(); | |||
$contact1 = $this->individualCreate(); | $contact1 = $this->individualCreate(); | |||
$contact2 = $this->individualCreate(['api.Im.create' => ['name' => 'chat_han dle']]); | $contact2 = $this->individualCreate(['api.Im.create' => ['name' => 'chat_han dle']]); | |||
$this->callAPISuccess('Contact', 'merge', ['to_keep_id' => $contact1, 'to_re | $this->callAPISuccess('Contact', 'merge', [ | |||
move_id' => $contact2]); | 'to_keep_id' => $contact1, | |||
'to_remove_id' => $contact2, | ||||
]); | ||||
} | ||||
/** | ||||
* Test that organization name is updated for employees of merged organization | ||||
s.. | ||||
* | ||||
* @throws \CRM_Core_Exception | ||||
*/ | ||||
public function testMergeWithEmployer(): void { | ||||
$organizationToRemoveID = $this->organizationCreate(['organization_name' => | ||||
'remove']); | ||||
$organizationToKeepID = $this->organizationCreate(['organization_name' => 'k | ||||
eep']); | ||||
$individualID = $this->createContactWithEmployerRelationship([ | ||||
'contact_id_b' => $organizationToRemoveID, | ||||
]); | ||||
$employerName = Contact::get()->addSelect('organization_name')->addWhere('id | ||||
', '=', $individualID)->execute()->first()['organization_name']; | ||||
$this->assertEquals('remove', $employerName); | ||||
$this->callAPISuccess('Contact', 'merge', ['to_keep_id' => $organizationToKe | ||||
epID, 'to_remove_id' => $organizationToRemoveID, 'mode' => 'aggressive']); | ||||
$employerName = Contact::get()->addSelect('organization_name')->addWhere('id | ||||
', '=', $individualID)->execute()->first()['organization_name']; | ||||
$this->assertEquals('keep', $employerName); | ||||
} | } | |||
/** | /** | |||
* Test that a custom field attached to the relationship does not block merge. | * Test that a custom field attached to the relationship does not block merge. | |||
* | * | |||
* @throws \CRM_Core_Exception | * @throws \CRM_Core_Exception | |||
*/ | */ | |||
public function testMergeWithRelationshipWithCustomFields(): void { | public function testMergeWithRelationshipWithCustomFields(): void { | |||
$contact1 = $this->individualCreate(); | $contact1 = $this->individualCreate(); | |||
$this->createCustomGroupWithFieldsOfAllTypes(['extends' => 'Relationship']); | $this->createCustomGroupWithFieldsOfAllTypes(['extends' => 'Relationship']); | |||
End of changes. 3 change blocks. | ||||
3 lines changed or deleted | 31 lines changed or added |