From ffec8e231c990b6756a5614582263c6f8fb9cedb Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 29 Mar 2017 20:34:24 +1300 Subject: [PATCH] CRM-20328 further fix on deprected duplicate code. Remove parameters only passed in in unit tests. This deprecated function is called from only one place, so reduce parameters & testing to reflect. Remove test that duplicates other test aside from deprecated paramter --- CRM/Contact/Import/Parser/Contact.php | 2 +- CRM/Utils/DeprecatedUtils.php | 21 +++++------ .../phpunit/CRM/Utils/DeprecatedUtilsTest.php | 36 ++----------------- 3 files changed, 11 insertions(+), 48 deletions(-) diff --git a/CRM/Contact/Import/Parser/Contact.php b/CRM/Contact/Import/Parser/Contact.php index ae49a80c8d..3358247de0 100644 --- a/CRM/Contact/Import/Parser/Contact.php +++ b/CRM/Contact/Import/Parser/Contact.php @@ -1677,7 +1677,7 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Contact_Import_Parser { //@todo direct call to API function not supported. // setting required check to false, CRM-2839 // plus we do our own required check in import - $error = _civicrm_api3_deprecated_contact_check_params($formatted, $dupeCheck, TRUE, FALSE, $dedupeRuleGroupID); + $error = _civicrm_api3_deprecated_contact_check_params($formatted, $dupeCheck, $dedupeRuleGroupID); if ((is_null($error)) && (civicrm_error(_civicrm_api3_deprecated_validate_formatted_contact($formatted)))) { $error = _civicrm_api3_deprecated_validate_formatted_contact($formatted); diff --git a/CRM/Utils/DeprecatedUtils.php b/CRM/Utils/DeprecatedUtils.php index 0fc7352b3e..9bd6b8839d 100644 --- a/CRM/Utils/DeprecatedUtils.php +++ b/CRM/Utils/DeprecatedUtils.php @@ -1375,8 +1375,6 @@ function _civicrm_api3_deprecated_contact_check_custom_params($params, $csType = /** * @param array $params * @param bool $dupeCheck - * @param bool $dupeErrorArray - * @param bool $requiredCheck * @param int $dedupeRuleGroupID * * @return array|null @@ -1384,9 +1382,10 @@ function _civicrm_api3_deprecated_contact_check_custom_params($params, $csType = function _civicrm_api3_deprecated_contact_check_params( &$params, $dupeCheck = TRUE, - $dupeErrorArray = FALSE, - $requiredCheck = TRUE, $dedupeRuleGroupID = NULL) { + + $requiredCheck = TRUE; + if (isset($params['id']) && is_numeric($params['id'])) { $requiredCheck = FALSE; } @@ -1458,15 +1457,11 @@ function _civicrm_api3_deprecated_contact_check_params( // $ids = $dupes['count'] ? implode(',', array_keys($dupes['values'])) : NULL; $ids = CRM_Contact_BAO_Contact::getDuplicateContacts($params, $params['contact_type'], 'Unsupervised', array(), CRM_Utils_Array::value('check_permissions', $params, $dedupeRuleGroupID)); if ($ids != NULL) { - if ($dupeErrorArray) { - $error = CRM_Core_Error::createError("Found matching contacts: $ids", - CRM_Core_Error::DUPLICATE_CONTACT, - 'Fatal', $ids - ); - return civicrm_api3_create_error($error->pop()); - } - - return civicrm_api3_create_error("Found matching contacts: $ids"); + $error = CRM_Core_Error::createError("Found matching contacts: " . implode(',', $ids), + CRM_Core_Error::DUPLICATE_CONTACT, + 'Fatal', $ids + ); + return civicrm_api3_create_error($error->pop()); } } diff --git a/tests/phpunit/CRM/Utils/DeprecatedUtilsTest.php b/tests/phpunit/CRM/Utils/DeprecatedUtilsTest.php index 601069c4b5..9c7277504c 100644 --- a/tests/phpunit/CRM/Utils/DeprecatedUtilsTest.php +++ b/tests/phpunit/CRM/Utils/DeprecatedUtilsTest.php @@ -30,41 +30,9 @@ class CRM_Utils_DeprecatedUtilsTest extends CiviUnitTestCase { public function testCheckParamsWithNoContactType() { $params = array('foo' => 'bar'); $contact = _civicrm_api3_deprecated_contact_check_params($params, FALSE); - $this->assertEquals(1, $contact['is_error'], "In line " . __LINE__); - } - - - /** - * Test civicrm_contact_check_params with a duplicate. - */ - public function testCheckParamsWithDuplicateContact() { - // Insert a row in civicrm_contact creating individual contact - $op = new PHPUnit_Extensions_Database_Operation_Insert(); - $op->execute($this->_dbconn, - $this->createXMLDataSet( - dirname(__FILE__) . '/../../api/v3/dataset/contact_17.xml' - ) - ); - $op->execute($this->_dbconn, - $this->createXMLDataSet( - dirname(__FILE__) . '/../../api/v3/dataset/email_contact_17.xml' - ) - ); - - $params = array( - 'first_name' => 'Test', - 'last_name' => 'Contact', - 'email' => 'TestContact@example.com', - 'contact_type' => 'Individual', - ); - $contact = _civicrm_api3_deprecated_contact_check_params($params, TRUE); $this->assertEquals(1, $contact['is_error']); - $this->assertRegexp("/matching contacts.*17/s", - CRM_Utils_Array::value('error_message', $contact) - ); } - /** * Test civicrm_contact_check_params with a duplicate. * and request the error in array format @@ -89,7 +57,7 @@ class CRM_Utils_DeprecatedUtilsTest extends CiviUnitTestCase { 'email' => 'TestContact@example.com', 'contact_type' => 'Individual', ); - $contact = _civicrm_api3_deprecated_contact_check_params($params, TRUE, TRUE); + $contact = _civicrm_api3_deprecated_contact_check_params($params, TRUE); $this->assertEquals(1, $contact['is_error']); $this->assertRegexp("/matching contacts.*17/s", $contact['error_message']['message'] @@ -103,7 +71,7 @@ class CRM_Utils_DeprecatedUtilsTest extends CiviUnitTestCase { public function testCheckParamsWithNoParams() { $params = array(); $contact = _civicrm_api3_deprecated_contact_check_params($params, FALSE); - $this->assertEquals(1, $contact['is_error'], "In line " . __LINE__); + $this->assertEquals(1, $contact['is_error']); } } -- 2.25.1