core#1826: Ignore location_type_id when deduping postal address
authorJon Goldberg <jon@megaphonetech.com>
Wed, 17 Jun 2020 19:06:06 +0000 (15:06 -0400)
committerJon Goldberg <jon@megaphonetech.com>
Thu, 18 Jun 2020 18:15:39 +0000 (14:15 -0400)
CRM/Dedupe/BAO/Rule.php
tests/phpunit/CRM/Dedupe/DedupeFinderTest.php
tests/phpunit/CRM/Dedupe/MergerTest.php
tests/phpunit/CiviTest/CiviUnitTestCase.php

index ab58f123215aaedb7acd16605e1daa6fdabec3e4..d05dd8e4163e2f91e0633501165a4f0b44e098d9 100644 (file)
@@ -93,8 +93,6 @@ class CRM_Dedupe_BAO_Rule extends CRM_Dedupe_DAO_Rule {
 
       case 'civicrm_address':
         $id = 'contact_id';
-        $on[] = 't1.location_type_id = t2.location_type_id';
-        $innerJoinClauses[] = 't1.location_type_id = t2.location_type_id';
         if (!empty($this->params['civicrm_address']['location_type_id'])) {
           $locTypeId = CRM_Utils_Type::escape($this->params['civicrm_address']['location_type_id'], 'Integer', FALSE);
           if ($locTypeId) {
index 6ba4c131bacc28e081df0951b0fe93e901708c7d..df954e592c17409c5a5e1bb5c7f33e01d062c2f8 100644 (file)
@@ -448,20 +448,4 @@ class CRM_Dedupe_DedupeFinderTest extends CiviUnitTestCase {
     $this->assertEquals(count($this->contactIDs), 7, 'Check for number of contacts.');
   }
 
-  /**
-   * @return array|int
-   * @throws \CRM_Core_Exception
-   */
-  protected function createRuleGroup() {
-    $ruleGroup = $this->callAPISuccess('RuleGroup', 'create', [
-      'contact_type' => 'Individual',
-      'threshold' => 8,
-      'used' => 'General',
-      'name' => 'TestRule',
-      'title' => 'TestRule',
-      'is_reserved' => 0,
-    ]);
-    return $ruleGroup;
-  }
-
 }
index e796173fa4b7641c8366630b2e4cd06349e889e2..1ab6d7ee1febc1cea4c9f3e6d7e0ed55614818fe 100644 (file)
@@ -323,6 +323,37 @@ class CRM_Dedupe_MergerTest extends CiviUnitTestCase {
     ], $pairs);
   }
 
+  /**
+   * Test that location type is ignored when deduping by postal address.
+   *
+   * @throws \CRM_Core_Exception
+   */
+  public function testGetMatchesIgnoreLocationType() {
+    $contact1 = $this->individualCreate();
+    $contact2 = $this->individualCreate();
+    $this->callAPISuccess('address', 'create', [
+      'contact_id' => $contact1,
+      'state_province_id' => 1049,
+      'location_type_id' => 1,
+    ]);
+    $this->callAPISuccess('address', 'create', [
+      'contact_id' => $contact2,
+      'state_province_id' => 1049,
+      'location_type_id' => 2,
+    ]);
+    $ruleGroup = $this->createRuleGroup();
+    $this->callAPISuccess('Rule', 'create', [
+      'dedupe_rule_group_id' => $ruleGroup['id'],
+      'rule_table' => 'civicrm_address',
+      'rule_field' => 'state_province_id',
+      'rule_weight' => 8,
+    ]);
+    $dupeCount = $this->callAPISuccess('Dedupe', 'getduplicates', [
+      'rule_group_id' => $ruleGroup['id'],
+    ])['count'];
+    $this->assertEquals($dupeCount, 1);
+  }
+
   /**
    * Test results are returned when criteria are passed in.
    *
index 899c6d5a648e9c88fc070af52d5478b03abb8964..12a84c10d889acec1c311a48c899971c36a0bd27 100644 (file)
@@ -3549,6 +3549,22 @@ VALUES
     }
   }
 
+  /**
+   * @return array|int
+   * @throws \CRM_Core_Exception
+   */
+  protected function createRuleGroup() {
+    $ruleGroup = $this->callAPISuccess('RuleGroup', 'create', [
+      'contact_type' => 'Individual',
+      'threshold' => 8,
+      'used' => 'General',
+      'name' => 'TestRule',
+      'title' => 'TestRule',
+      'is_reserved' => 0,
+    ]);
+    return $ruleGroup;
+  }
+
   /**
    * Generic create test.
    *