Skip to content
Snippets Groups Projects
Unverified Commit 6ea51756 authored by Seamus Lee's avatar Seamus Lee Committed by GitHub
Browse files

Merge pull request #13179 from eileenmcnaughton/dedupe_rule

Test support for fixing #397 including adding Rule api
parents 2b20bc05 63926b53
Branches
Tags
No related merge requests found
......@@ -282,7 +282,6 @@ class CRM_Dedupe_BAO_RuleGroup extends CRM_Dedupe_DAO_RuleGroup {
if ($dao->affectedRows() >= 1) {
$exclWeightSum[] = substr($fieldWeight, strrpos($fieldWeight, '.') + 1);
}
$dao->free();
}
else {
// its a die situation
......
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 5 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
* This api exposes CiviCRM (dedupe) rules.
*
* Rules dedupe critieria assigned to RuleGroups.
*
* @package CiviCRM_APIv3
*/
/**
* Create or update a rule.
*
* @param array $params
* Array per getfields metadata.
*
* @return array
* API result array
*/
function civicrm_api3_rule_create($params) {
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'Rule');
}
/**
* Specify Meta data for create.
*
* Note that this data is retrievable via the getfields function
* and is used for pre-filling defaults and ensuring mandatory requirements are met.
*
* @param array $params
*/
function _civicrm_api3_rule_create_spec(&$params) {
$params['dedupe_rule_group_id']['api.required'] = TRUE;
$params['rule_table']['api.default'] = 'civicrm_contact';
$params['rule_field']['api.required'] = TRUE;
$params['rule_weight']['api.required'] = TRUE;
}
/**
* Delete an existing Rule.
*
* @param array $params
*
* @return array
* API result array
*/
function civicrm_api3_rule_delete($params) {
return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
/**
* Get a Rule.
*
* @param array $params
* Array per getfields metadata.
*
* @return array
* API result array
*/
function civicrm_api3_rule_get($params) {
return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, TRUE, 'Rule');
}
......@@ -58,6 +58,11 @@ class CRM_Dedupe_DedupeFinderTest extends CiviUnitTestCase {
$this->assertEquals(count($foundDupes), 3, 'Check Individual-Fuzzy dupe rule for dupesInGroup().');
}
/**
* Test that a rule set to is_reserved = 0 works.
*
* There is a different search used dependent on this variable.
*/
public function testCustomRule() {
$this->setupForGroupDedupe();
......@@ -69,18 +74,20 @@ class CRM_Dedupe_DedupeFinderTest extends CiviUnitTestCase {
'title' => 'TestRule',
'is_reserved' => 0,
));
foreach (array('first_name', 'last_name') as $field) {
$ruleDao = new CRM_Dedupe_DAO_Rule();
$ruleDao->dedupe_rule_group_id = $ruleGroup['id'];
$ruleDao->rule_table = 'civicrm_contact';
$ruleDao->rule_field = $field;
$ruleDao->rule_length = NULL;
$ruleDao->rule_weight = 4;
$ruleDao->save();
$ruleDao->free();
$rules = [];
foreach (array('birth_date', 'first_name', 'last_name') as $field) {
$rules[$field] = $this->callAPISuccess('Rule', 'create', [
'dedupe_rule_group_id' => $ruleGroup['id'],
'rule_table' => 'civicrm_contact',
'rule_weight' => 4,
'rule_field' => $field,
]);
}
$foundDupes = CRM_Dedupe_Finder::dupesInGroup($ruleGroup['id'], $this->groupID);
$this->assertEquals(count($foundDupes), 4);
$this->markTestIncomplete('This currenctly fails - see https://lab.civicrm.org/dev/core/issues/397');
CRM_Dedupe_Finder::dupes($ruleGroup['id']);
}
/**
......@@ -179,12 +186,6 @@ class CRM_Dedupe_DedupeFinderTest extends CiviUnitTestCase {
// verify that all contacts have been created separately
$this->assertEquals(count($contactIds), 7, 'Check for number of contacts.');
$dao = new CRM_Dedupe_DAO_RuleGroup();
$dao->contact_type = 'Individual';
$dao->used = 'General';
$dao->is_default = 1;
$dao->find(TRUE);
$fields = array(
'first_name' => 'robin',
'last_name' => 'hood',
......@@ -224,12 +225,14 @@ class CRM_Dedupe_DedupeFinderTest extends CiviUnitTestCase {
'last_name' => 'hood',
'email' => 'robin@example.com',
'contact_type' => 'Individual',
'birth_date' => '2016-01-01',
),
array(
'first_name' => 'robin',
'last_name' => 'hood',
'email' => 'hood@example.com',
'contact_type' => 'Individual',
'birth_date' => '2016-01-01',
),
array(
'first_name' => 'robin',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment