Skip to content

Commit

Permalink
CRM-18497 add first very basic test to job.merge
Browse files Browse the repository at this point in the history
The test doesn't check any functionality, just the fact it runs without error. More to come
  • Loading branch information
eileenmcnaughton committed May 8, 2016
1 parent 5af25e3 commit 032b4d3
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CRM/Dedupe/Merger.php
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ public static function retrieveFields($main, $other) {
* A 'safe' value skips the merge if there are any un-resolved conflicts.
* Does a force merge otherwise.
* @param bool $autoFlip to let api decide which contact to retain and which to delete.
* Wether to let api decide which contact to retain and which to delete.
* Whether to let api decide which contact to retain and which to delete.
* @param int $batchLimit number of merges to carry out in one batch.
* @param int $isSelected if records with is_selected column needs to be processed.
*
Expand Down
21 changes: 12 additions & 9 deletions api/v3/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -474,22 +474,25 @@ function civicrm_api3_job_process_respondent($params) {
*
* @return array
* API Result Array
* @throws \CiviCRM_API3_Exception
*/
function civicrm_api3_job_process_batch_merge($params) {
$rgid = CRM_Utils_Array::value('rgid', $params);
$rule_group_id = CRM_Utils_Array::value('rgid', $params);
if (!$rule_group_id) {
$rule_group_id = civicrm_api3('RuleGroup', 'getvalue', array(
'contact_type' => 'Individual',
'used' => 'Unsupervised',
'return' => 'id',
));
}
$gid = CRM_Utils_Array::value('gid', $params);

$mode = CRM_Utils_Array::value('mode', $params, 'safe');
$autoFlip = CRM_Utils_Array::value('auto_flip', $params, TRUE);

$result = CRM_Dedupe_Merger::batchMerge($rgid, $gid, $mode, $autoFlip);
$result = CRM_Dedupe_Merger::batchMerge($rule_group_id, $gid, $mode, $autoFlip);

if ($result['is_error'] == 0) {
return civicrm_api3_create_success();
}
else {
return civicrm_api3_create_error($result['messages']);
}
return civicrm_api3_create_success($result, $params);
}

/**
Expand All @@ -499,7 +502,7 @@ function civicrm_api3_job_process_batch_merge($params) {
*/
function _civicrm_api3_job_process_batch_merge_spec(&$params) {
$params['rgid'] = array(
'title' => 'rule group id',
'title' => 'Dedupe rule group id, defaults to Contact Unsupervised rule',
'type' => CRM_Utils_Type::T_INT,
);
$params['gid'] = array(
Expand Down
83 changes: 83 additions & 0 deletions api/v3/RuleGroup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2016 |
+--------------------------------------------------------------------+
| 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 rule_groups.
*
* RuleGroups are used to group dedupe critieria.
*
* @package CiviCRM_APIv3
*/

/**
* Create or update a rule_group.
*
* @param array $params
* Array per getfields metadata.
*
* @return array
* API result array
*/
function civicrm_api3_rule_group_create($params) {
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}

/**
* 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_group_create_spec(&$params) {
}

/**
* Delete an existing RuleGroup.
*
* @param array $params
*
* @return array
* API result array
*/
function civicrm_api3_rule_group_delete($params) {
return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}

/**
* Get a RuleGroup.
*
* @param array $params
* Array per getfields metadata.
*
* @return array
* API result array
*/
function civicrm_api3_rule_group_get($params) {
return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
1 change: 0 additions & 1 deletion tests/phpunit/CiviTest/CiviUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
* Include class definitions
*/
require_once 'api/api.php';
require_once 'CRM/Financial/BAO/FinancialType.php';
define('API_LATEST_VERSION', 3);

/**
Expand Down
9 changes: 8 additions & 1 deletion tests/phpunit/api/v3/JobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function testCreateWithInvalidFrequency() {
'parameters' => 'Semi-formal explanation of runtime job parameters',
'is_active' => 1,
);
$result = $this->callAPIFailure('job', 'create', $params);
$this->callAPIFailure('job', 'create', $params);
}

/**
Expand Down Expand Up @@ -296,6 +296,13 @@ public function testCallDisableExpiredRelationships() {
$this->contactDelete($orgID);
}

/**
* Test the batch merge function.
*/
public function testBatchMerge() {
$this->callAPISuccess('Job', 'process_batch_merge', array());
}

/**
* @param $op
* @param string $objectName
Expand Down

0 comments on commit 032b4d3

Please sign in to comment.