enable matching on contact phone when importing contributions
[civicrm-core.git] / tests / phpunit / CRM / Contribute / Import / Parser / ContributionTest.php
index 02e42c062b789819be8d47967f7526bce1c37179..8182fe9e2e468ca992f666f8d2db6dce4d2cf7f0 100644 (file)
@@ -179,6 +179,40 @@ class CRM_Contribute_Import_Parser_ContributionTest extends CiviUnitTestCase {
     $this->assertEquals('20191020000000', $formatted[$this->getCustomFieldName('date')]);
   }
 
+  /**
+   * Test phone is included if it is part of dedupe rule. 
+   *
+   * @throws \CRM_Core_Exception
+   */
+  public function testPhoneMatchOnContact() {
+    // Update existing unsupervised rule, change to general.
+    $unsupervisedRuleGroup = $this->callApiSuccess('RuleGroup', 'getsingle', [
+      'used' => 'Unsupervised',
+      'contact_type' => 'Individual'
+    ]);
+    $this->callApiSuccess('RuleGroup', 'create', [
+      'id' => $unsupervisedRuleGroup['id'],
+      'used' => 'General'
+    ]);
+
+    // Create new unsupervised rule with Phone field.
+    $ruleGroup = $this->callAPISuccess('RuleGroup', 'create', [
+      'contact_type' => 'Individual',
+      'threshold' => 10,
+      'used' => 'Unsupervised',
+      'name' => 'MatchingPhone',
+      'title' => 'Matching Phone',
+      'is_reserved' => 0,
+    ]);
+    $this->callAPISuccess('Rule', 'create', [
+      'dedupe_rule_group_id' => $ruleGroup['id'],
+      'rule_table' => 'civicrm_phone',
+      'rule_weight' => 10,
+      'rule_field' => 'phone_numeric',
+    ]);
+    $fields = CRM_Contribute_BAO_Contribution::importableFields();
+    $this->assertTrue(array_key_exists('phone', $fields));
+  }
   /**
    * Run the import parser.
    *