return;
}
- $exception = new CRM_Dedupe_DAO_Exception();
- $exception->contact_id1 = $cid;
- $exception->contact_id2 = $oid;
- //make sure contact2 > contact1.
- if ($cid > $oid) {
- $exception->contact_id1 = $oid;
- $exception->contact_id2 = $cid;
- }
- $exception->find(TRUE);
- $status = NULL;
- if ($oper == 'dupe-nondupe') {
- $status = $exception->save();
- }
- if ($oper == 'nondupe-dupe') {
- $status = $exception->delete();
- }
+ $status = self::markNonDuplicates($cid, $oid, $oper);
CRM_Utils_JSON::output(['status' => ($status) ? $oper : $status]);
}
return !empty($searchData['value']);
}
+ /**
+ * Mark not duplicates.
+ *
+ * Note this function would sensibly be replaced by an api-call but extracting here to add a test first.
+ *
+ * I would have like to make it private but test class accesses it & it doesn't warrant being a BAO class
+ * as it should feel very endangered.
+ *
+ * @param int $cid
+ * @param int $oid
+ * @param 'dupe-nondupe'|'nondupe-dupe' $oper
+ *
+ * @return \CRM_Core_DAO|mixed|null
+ */
+ public static function markNonDuplicates($cid, $oid, $oper) {
+ $exception = new CRM_Dedupe_DAO_Exception();
+ $exception->contact_id1 = $cid;
+ $exception->contact_id2 = $oid;
+ //make sure contact2 > contact1.
+ if ($cid > $oid) {
+ $exception->contact_id1 = $oid;
+ $exception->contact_id2 = $cid;
+ }
+ $exception->find(TRUE);
+ $status = NULL;
+ if ($oper == 'dupe-nondupe') {
+ $status = $exception->save();
+ }
+ if ($oper == 'nondupe-dupe') {
+ $status = $exception->delete();
+ }
+ return $status;
+ }
+
/**
* Retrieve a PDF Page Format for the PDF Letter form.
*/
$this->assertEquals(array('data' => array(), 'recordsTotal' => 0, 'recordsFiltered' => 0), $result);
}
+ /**
+ * Tests the 'guts' of the processDupes function.
+ *
+ * @throws \Exception
+ */
+ public function testProcessDupes() {
+ $contact1 = $this->individualCreate();
+ $contact2 = $this->individualCreate();
+ $contact3 = $this->individualCreate();
+ CRM_Contact_Page_AJAX::markNonDuplicates($contact1, $contact2, 'dupe-nondupe');
+ CRM_Contact_Page_AJAX::markNonDuplicates($contact3, $contact1, 'dupe-nondupe');
+ $this->callAPISuccessGetSingle('Exception', ['contact_id1' => $contact1, 'contact_id2' => $contact2]);
+ // Note that in saving the order is changed to have the lowest ID first.
+ $this->callAPISuccessGetSingle('Exception', ['contact_id1' => $contact1, 'contact_id2' => $contact3]);
+ }
+
public function testGetDedupesPostCode() {
$_REQUEST['gid'] = 1;
$_REQUEST['rgid'] = 1;