Skip to content

Commit

Permalink
Merge pull request #13588 from jitendrapurohit/dev-631
Browse files Browse the repository at this point in the history
dev/core#631 - Enable 'add new' by default on merge screen
  • Loading branch information
eileenmcnaughton authored Feb 24, 2019
2 parents 1d29257 + c231c0d commit 2025d50
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
11 changes: 10 additions & 1 deletion CRM/Dedupe/Merger.php
Original file line number Diff line number Diff line change
Expand Up @@ -1433,7 +1433,16 @@ public static function getRowsElementsAndInfo($mainId, $otherId, $checkPermissio
}
}
if ($name == 'rel_table_memberships') {
$elements[] = array('checkbox', "operation[move_{$name}][add]", NULL, ts('add new'));
//Enable 'add new' checkbox if main contact does not contain any membership similar to duplicate contact.
$attributes = ['checked' => 'checked'];
$otherContactMemberships = CRM_Member_BAO_Membership::getAllContactMembership($otherId);
foreach ($otherContactMemberships as $membership) {
$mainMembership = CRM_Member_BAO_Membership::getContactMembership($mainId, $membership['membership_type_id'], FALSE);
if ($mainMembership) {
$attributes = [];
}
}
$elements[] = array('checkbox', "operation[move_{$name}][add]", NULL, ts('add new'), $attributes);
$migrationInfo["operation"]["move_{$name}"]['add'] = 1;
}
}
Expand Down
38 changes: 38 additions & 0 deletions tests/phpunit/CRM/Dedupe/MergerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,44 @@ public function testGetMatchesInGroup() {
), $pairs);
}

/**
* Test migration of Membership.
*/
public function testMergeMembership() {
// Contacts setup
$this->setupMatchData();
$originalContactID = $this->contacts[0]['id'];
$duplicateContactID = $this->contacts[1]['id'];

//Add Membership for the duplicate contact.
$memTypeId = $this->membershipTypeCreate();
$membership = $this->callAPISuccess('Membership', 'create', [
'membership_type_id' => $memTypeId,
'contact_id' => $duplicateContactID,
]);
//Assert if 'add new' checkbox is enabled on the merge form.
$rowsElementsAndInfo = CRM_Dedupe_Merger::getRowsElementsAndInfo($originalContactID, $duplicateContactID);
foreach ($rowsElementsAndInfo['elements'] as $element) {
if (!empty($element[3]) && $element[3] == 'add new') {
$checkedAttr = ['checked' => 'checked'];
$this->checkArrayEquals($element[4], $checkedAttr);
}
}

//Merge and move the mem to the main contact.
$this->mergeContacts($originalContactID, $duplicateContactID, [
'move_rel_table_memberships' => 1,
'operation' => ['move_rel_table_memberships' => ['add' => 1]]
]);

//Check if membership is correctly transferred to original contact.
$originalContactMembership = $this->callAPISuccess('Membership', 'get', [
'membership_type_id' => $memTypeId,
'contact_id' => $originalContactID,
]);
$this->assertEquals(1, $originalContactMembership['count']);
}

/**
* CRM-19653 : Test that custom field data should/shouldn't be overriden on
* selecting/not selecting option to migrate data respectively
Expand Down

0 comments on commit 2025d50

Please sign in to comment.