Merge pull request #16574 from civicrm/5.23
[civicrm-core.git] / tests / phpunit / CRM / Dedupe / DedupeFinderTest.php
index b0318c12a0fddd65abe3ca83ab5d26a5ddbdc429..0e5f599a35c31a3a924771629e0e172565bc516f 100644 (file)
@@ -22,6 +22,8 @@ class CRM_Dedupe_DedupeFinderTest extends CiviUnitTestCase {
 
   /**
    * Clean up after the test.
+   *
+   * @throws \CRM_Core_Exception
    */
   public function tearDown() {
 
@@ -60,6 +62,8 @@ class CRM_Dedupe_DedupeFinderTest extends CiviUnitTestCase {
 
   /**
    * Test duplicate contact retrieval with 2 email fields.
+   *
+   * @throws \CRM_Core_Exception
    */
   public function testUnsupervisedWithTwoEmailFields() {
     $this->setupForGroupDedupe();
@@ -84,6 +88,8 @@ class CRM_Dedupe_DedupeFinderTest extends CiviUnitTestCase {
    * Test that a rule set to is_reserved = 0 works.
    *
    * There is a different search used dependent on this variable.
+   *
+   * @throws \CRM_Core_Exception
    */
   public function testCustomRule() {
     $this->setupForGroupDedupe();
@@ -113,6 +119,8 @@ class CRM_Dedupe_DedupeFinderTest extends CiviUnitTestCase {
 
   /**
    * Test a custom rule with a non-default field.
+   *
+   * @throws \CRM_Core_Exception
    */
   public function testCustomRuleWithAddress() {
     $this->setupForGroupDedupe();
@@ -140,8 +148,39 @@ class CRM_Dedupe_DedupeFinderTest extends CiviUnitTestCase {
 
   }
 
+  /**
+   * Test rule from Richard
+   *
+   * @throws \CRM_Core_Exception
+   */
+  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->assertCount(1, $foundDupes);
+  }
+
   /**
    * Test a custom rule with a non-default field.
+   *
+   * @throws \CRM_Core_Exception
    */
   public function testInclusiveRule() {
     $this->setupForGroupDedupe();
@@ -164,7 +203,7 @@ class CRM_Dedupe_DedupeFinderTest extends CiviUnitTestCase {
       ]);
     }
     $foundDupes = CRM_Dedupe_Finder::dupesInGroup($ruleGroup['id'], $this->groupID);
-    $this->assertEquals(4, count($foundDupes));
+    $this->assertCount(4, $foundDupes);
     CRM_Dedupe_Finder::dupes($ruleGroup['id']);
   }
 
@@ -188,6 +227,8 @@ class CRM_Dedupe_DedupeFinderTest extends CiviUnitTestCase {
 
   /**
    * Test dupesByParams function.
+   *
+   * @throws \CRM_Core_Exception
    */
   public function testDupesByParams() {
     // make dupe checks based on based on following contact sets:
@@ -319,6 +360,8 @@ class CRM_Dedupe_DedupeFinderTest extends CiviUnitTestCase {
 
   /**
    * Set up a group of dedupable contacts.
+   *
+   * @throws \CRM_Core_Exception
    */
   protected function setupForGroupDedupe() {
     $params = [