From 62ee752a0e1e0d2b3feca51047c849145dc7c411 Mon Sep 17 00:00:00 2001 From: Jon Goldberg Date: Wed, 17 Jun 2020 15:06:06 -0400 Subject: [PATCH] core#1826: Ignore location_type_id when deduping postal address --- CRM/Dedupe/BAO/Rule.php | 2 -- tests/phpunit/CRM/Dedupe/DedupeFinderTest.php | 16 ---------- tests/phpunit/CRM/Dedupe/MergerTest.php | 31 +++++++++++++++++++ tests/phpunit/CiviTest/CiviUnitTestCase.php | 16 ++++++++++ 4 files changed, 47 insertions(+), 18 deletions(-) diff --git a/CRM/Dedupe/BAO/Rule.php b/CRM/Dedupe/BAO/Rule.php index ab58f12321..d05dd8e416 100644 --- a/CRM/Dedupe/BAO/Rule.php +++ b/CRM/Dedupe/BAO/Rule.php @@ -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) { diff --git a/tests/phpunit/CRM/Dedupe/DedupeFinderTest.php b/tests/phpunit/CRM/Dedupe/DedupeFinderTest.php index 6ba4c131ba..df954e592c 100644 --- a/tests/phpunit/CRM/Dedupe/DedupeFinderTest.php +++ b/tests/phpunit/CRM/Dedupe/DedupeFinderTest.php @@ -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; - } - } diff --git a/tests/phpunit/CRM/Dedupe/MergerTest.php b/tests/phpunit/CRM/Dedupe/MergerTest.php index e796173fa4..1ab6d7ee1f 100644 --- a/tests/phpunit/CRM/Dedupe/MergerTest.php +++ b/tests/phpunit/CRM/Dedupe/MergerTest.php @@ -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. * diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 899c6d5a64..12a84c10d8 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -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. * -- 2.25.1