add test
authorDemeritCowboy <demeritcowboy@hotmail.com>
Wed, 10 Apr 2019 00:59:15 +0000 (20:59 -0400)
committereileen <emcnaughton@wikimedia.org>
Thu, 11 Apr 2019 23:25:59 +0000 (09:25 +1000)
tests/phpunit/CRM/Dedupe/DedupeFinderTest.php

index f559aece3c1885f3fec4bc2c507f4410e0080e42..65a728c05c6bd9a68434ee06e43bfa657e9a0c4e 100644 (file)
@@ -89,6 +89,35 @@ class CRM_Dedupe_DedupeFinderTest extends CiviUnitTestCase {
 
   }
 
+  /**
+   * Test a custom rule with a non-default field.
+   */
+  public function testCustomRuleWithAddress() {
+    $this->setupForGroupDedupe();
+
+    $ruleGroup = $this->callAPISuccess('RuleGroup', 'create', array(
+      'contact_type' => 'Individual',
+      'threshold' => 10,
+      'used' => 'General',
+      'name' => 'TestRule',
+      'title' => 'TestRule',
+      'is_reserved' => 0,
+    ));
+    $rules = [];
+    foreach (array('postal_code') as $field) {
+      $rules[$field] = $this->callAPISuccess('Rule', 'create', [
+        'dedupe_rule_group_id' => $ruleGroup['id'],
+        'rule_table' => 'civicrm_address',
+        'rule_weight' => 10,
+        'rule_field' => $field,
+      ]);
+    }
+    $foundDupes = CRM_Dedupe_Finder::dupesInGroup($ruleGroup['id'], $this->groupID);
+    $this->assertEquals(count($foundDupes), 1);
+    CRM_Dedupe_Finder::dupes($ruleGroup['id']);
+
+  }
+
   /**
    * Test the supervised dedupe rule against a group.
    *
@@ -260,6 +289,7 @@ class CRM_Dedupe_DedupeFinderTest extends CiviUnitTestCase {
         'email' => 'robin@example.com',
         'contact_type' => 'Individual',
         'birth_date' => '2016-01-01',
+        'api.Address.create' => ['location_type_id' => 'Billing', 'postal_code' => '99999'],
       ),
       array(
         'first_name' => 'robin',
@@ -267,6 +297,7 @@ class CRM_Dedupe_DedupeFinderTest extends CiviUnitTestCase {
         'email' => 'hood@example.com',
         'contact_type' => 'Individual',
         'birth_date' => '2016-01-01',
+        'api.Address.create' => ['location_type_id' => 'Billing', 'postal_code' => '99999'],
       ),
       array(
         'first_name' => 'robin',