dev/core#183 Ensure that having a rule where each field is the same weight with the...
authorSeamus Lee <seamuslee001@gmail.com>
Sat, 28 Dec 2019 20:22:34 +0000 (07:22 +1100)
committerSeamus Lee <seamuslee001@gmail.com>
Sat, 28 Dec 2019 20:29:56 +0000 (07:29 +1100)
CRM/Dedupe/BAO/RuleGroup.php
tests/phpunit/CRM/Dedupe/DedupeFinderTest.php

index 8eb26212ed5a75cc55669fe5e331ba7214456961..08533684468f5053fca3c2ae21aca503d12cf21d 100644 (file)
@@ -234,6 +234,8 @@ class CRM_Dedupe_BAO_RuleGroup extends CRM_Dedupe_DAO_RuleGroup {
           $query = array_shift($tableQueries);
 
           if ($searchWithinDupes) {
+            // drop dedupe_copy table just in case if its already there.
+            $dedupeCopyTemporaryTableObject->drop();
             // get prepared to search within already found dupes if $searchWithinDupes flag is set
             $dedupeCopyTemporaryTableObject->createWithQuery("SELECT * FROM {$this->temporaryTables['dedupe']} WHERE weight >= {$weightSum}");
 
index b0318c12a0fddd65abe3ca83ab5d26a5ddbdc429..0666a70854c47071e023147ff864ed3e5970407b 100644 (file)
@@ -140,6 +140,33 @@ class CRM_Dedupe_DedupeFinderTest extends CiviUnitTestCase {
 
   }
 
+  /**
+   * Test rule from Richard
+   */
+  public function testRuleThreeContactFieldsEqualWeightWIthThresholdtheTotalSumOfAllWeight() {
+    $this->setupForGroupDedupe();
+
+    $ruleGroup = $this->callAPISuccess('RuleGroup', 'create', [
+      'contact_type' => 'Individual',
+      'threshold' => 30,
+      'used' => 'General',
+      'name' => 'TestRule',
+      'title' => 'TestRule',
+      'is_reserved' => 0,
+    ]);
+
+    foreach (['first_name', 'last_name', 'birth_date'] as $field) {
+      $rules[$field] = $this->callAPISuccess('Rule', 'create', [
+        'dedupe_rule_group_id' => $ruleGroup['id'],
+        'rule_table' => 'civicrm_contact',
+        'rule_weight' => 10,
+        'rule_field' => $field,
+      ]);
+    }
+    $foundDupes = CRM_Dedupe_Finder::dupesInGroup($ruleGroup['id'], $this->groupID);
+    $this->assertEquals(1, count($foundDupes));
+  }
+
   /**
    * Test a custom rule with a non-default field.
    */