From 56088900185a5aea4f14c838ed1c7a1806f01d7a Mon Sep 17 00:00:00 2001 From: colemanw Date: Tue, 27 Jun 2023 00:42:38 -0400 Subject: [PATCH] Remove deprecated v3 Contact.getquick api --- CRM/Core/Permission.php | 3 - CRM/Utils/API/AbstractFieldCoder.php | 2 +- api/v3/Contact.php | 402 ------------------------ tests/phpunit/api/v3/ContactTest.php | 453 --------------------------- 4 files changed, 1 insertion(+), 859 deletions(-) diff --git a/CRM/Core/Permission.php b/CRM/Core/Permission.php index 4bcdf5eda3..64a7db180b 100644 --- a/CRM/Core/Permission.php +++ b/CRM/Core/Permission.php @@ -996,9 +996,6 @@ class CRM_Core_Permission { 'get' => [], // managed by _civicrm_api3_check_edit_permissions 'update' => [], - 'getquick' => [ - ['access CiviCRM', 'access AJAX API'], - ], 'duplicatecheck' => [ 'access CiviCRM', ], diff --git a/CRM/Utils/API/AbstractFieldCoder.php b/CRM/Utils/API/AbstractFieldCoder.php index f99293f9e8..99ce120f1a 100644 --- a/CRM/Utils/API/AbstractFieldCoder.php +++ b/CRM/Utils/API/AbstractFieldCoder.php @@ -117,7 +117,7 @@ abstract class CRM_Utils_API_AbstractFieldCoder implements API_Wrapper { */ public function toApiOutput($apiRequest, $result) { $lowerAction = strtolower($apiRequest['action']); - if ($apiRequest['version'] == 3 && in_array($lowerAction, ['get', 'create', 'setvalue', 'getquick'])) { + if ($apiRequest['version'] == 3 && in_array($lowerAction, ['get', 'create', 'setvalue'])) { foreach ($result as $key => $value) { // Don't apply escaping to API control parameters (e.g. 'api.foo' or 'options.foo') // and don't apply to other skippable fields diff --git a/api/v3/Contact.php b/api/v3/Contact.php index 0fc2ca5b66..d3e35192ef 100644 --- a/api/v3/Contact.php +++ b/api/v3/Contact.php @@ -691,397 +691,6 @@ function _civicrm_api3_greeting_format_params($params) { } } -/** - * Adjust Metadata for Get action. - * - * @param array $params - * Array of parameters determined by getfields. - */ -function _civicrm_api3_contact_getquick_spec(&$params) { - $params['name']['api.required'] = TRUE; - $params['name']['title'] = ts('String to search on'); - $params['name']['type'] = CRM_Utils_Type::T_STRING; - $params['field']['type'] = CRM_Utils_Type::T_STRING; - $params['field']['title'] = ts('Field to search on'); - $params['field']['options'] = [ - '', - 'id', - 'contact_id', - 'external_identifier', - 'first_name', - 'last_name', - 'job_title', - 'postal_code', - 'street_address', - 'email', - 'city', - 'phone_numeric', - ]; - $params['table_name']['type'] = CRM_Utils_Type::T_STRING; - $params['table_name']['title'] = ts('Table alias to search on'); - $params['table_name']['api.default'] = 'cc'; -} - -/** - * Old Contact quick search api. - * - * @deprecated - * - * @param array $params - * - * @return array - * @throws \CRM_Core_Exception - */ -function civicrm_api3_contact_getquick($params) { - $name = CRM_Utils_Type::escape(CRM_Utils_Array::value('name', $params), 'String'); - $table_name = CRM_Utils_String::munge($params['table_name']); - // get the autocomplete options from settings - $acpref = explode(CRM_Core_DAO::VALUE_SEPARATOR, - CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, - 'contact_autocomplete_options' - ) - ); - - $table_names = [ - 'email' => 'eml', - 'phone_numeric' => 'phe', - 'street_address' => 'sts', - 'city' => 'sts', - 'postal_code' => 'sts', - ]; - - // get the option values for contact autocomplete - $acOptions = CRM_Core_OptionGroup::values('contact_autocomplete_options', FALSE, FALSE, FALSE, NULL, 'name'); - - $list = $from = []; - foreach ($acpref as $value) { - if ($value && !empty($acOptions[$value])) { - $list[$value] = $acOptions[$value]; - } - } - // If we are doing quicksearch by a field other than name, make sure that field is added to results - if (!empty($params['field_name'])) { - $field_name = CRM_Utils_String::munge($params['field_name']); - // there is no good reason to request api_key via getquick - if ($field_name == 'api_key') { - throw new CRM_Core_Exception('Illegal value "api_key" for parameter "field_name"'); - } - // Unique name contact_id = id - if ($field_name == 'contact_id') { - $field_name = 'id'; - } - // dev/core#1420 : trim non-numeric character from phone search string - elseif ($field_name == 'phone_numeric') { - $name = preg_replace('/[^\d]/', '', $name); - } - if (isset($table_names[$field_name])) { - $table_name = $table_names[$field_name]; - } - elseif (strpos($field_name, 'custom_') === 0) { - $customField = civicrm_api3('CustomField', 'getsingle', [ - 'id' => substr($field_name, 7), - 'return' => [ - 'custom_group_id.table_name', - 'column_name', - 'data_type', - 'option_group_id', - 'html_type', - ], - ]); - $field_name = $customField['column_name']; - $table_name = CRM_Utils_String::munge($customField['custom_group_id.table_name']); - $from[$field_name] = "LEFT JOIN `$table_name` ON cc.id = `$table_name`.entity_id"; - if (CRM_Core_BAO_CustomField::hasOptions($customField)) { - $customOptionsWhere = []; - $customFieldOptions = CRM_Contact_BAO_Contact::buildOptions('custom_' . $customField['id'], 'search'); - $isMultivalueField = CRM_Core_BAO_CustomField::isSerialized($customField); - $sep = CRM_Core_DAO::VALUE_SEPARATOR; - foreach ($customFieldOptions as $optionKey => $optionLabel) { - if (mb_stripos($optionLabel, $name) !== FALSE) { - $customOptionsWhere[$optionKey] = "$table_name.$field_name " . ($isMultivalueField ? "LIKE '%{$sep}{$optionKey}{$sep}%'" : "= '$optionKey'"); - } - } - } - } - // phone_numeric should be phone - $searchField = str_replace('_numeric', '', $field_name); - if (!in_array($searchField, $list)) { - $list[] = $searchField; - } - } - else { - // Set field name to first name for exact match checking. - $field_name = 'sort_name'; - } - - $select = $actualSelectElements = ['sort_name']; - - foreach ($list as $value) { - $suffix = substr($value, 0, 2) . substr($value, -1); - switch ($value) { - case 'street_address': - case 'city': - case 'postal_code': - $selectText = $value; - $value = "address"; - $suffix = 'sts'; - case 'phone': - case 'email': - $actualSelectElements[] = $select[] = ($value == 'address') ? $selectText : $value; - if ($value == 'phone') { - $actualSelectElements[] = $select[] = 'phone_ext'; - } - $from[$value] = "LEFT JOIN civicrm_{$value} {$suffix} ON ( cc.id = {$suffix}.contact_id AND {$suffix}.is_primary = 1 ) "; - break; - - case 'country': - case 'state_province': - $select[] = "{$suffix}.name as {$value}"; - $actualSelectElements[] = "{$suffix}.name"; - if (!in_array('address', $from)) { - $from['address'] = 'LEFT JOIN civicrm_address sts ON ( cc.id = sts.contact_id AND sts.is_primary = 1) '; - } - $from[$value] = " LEFT JOIN civicrm_{$value} {$suffix} ON ( sts.{$value}_id = {$suffix}.id ) "; - break; - - default: - if ($value == 'id') { - $actualSelectElements[] = 'cc.id'; - } - elseif ($value != 'sort_name') { - $suffix = 'cc'; - if ($field_name == $value) { - $suffix = $table_name; - } - $actualSelectElements[] = $select[] = $suffix . '.' . $value; - } - break; - } - } - - $config = CRM_Core_Config::singleton(); - $as = $select; - $select = implode(', ', $select); - if (!empty($select)) { - $select = ", $select"; - } - $actualSelectElements = implode(', ', $actualSelectElements); - $from = implode(' ', $from); - $limit = (int) ($params['limit'] ?? 0); - $limit = $limit > 0 ? $limit : Civi::settings()->get('search_autocomplete_count'); - - // add acl clause here - list($aclFrom, $aclWhere) = CRM_Contact_BAO_Contact_Permission::cacheClause('cc'); - $whereClauses = ['cc.is_deleted = 0']; - if ($aclWhere) { - $whereClauses[] = $aclWhere; - } - $isPrependWildcard = \Civi::settings()->get('includeWildCardInName'); - - if (!empty($params['org'])) { - $whereClauses[] = 'contact_type = "Organization"'; - - // CRM-7157, hack: get current employer details when - // employee_id is present. - $currEmpDetails = []; - if (!empty($params['employee_id'])) { - if ($currentEmployer = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', - (int) $params['employee_id'], - 'employer_id' - )) { - if ($isPrependWildcard) { - $strSearch = "%$name%"; - } - else { - $strSearch = "$name%"; - } - - // get current employer details - $dao = CRM_Core_DAO::executeQuery("SELECT cc.id as id, CONCAT_WS( ' :: ', {$actualSelectElements} ) as data, sort_name - FROM civicrm_contact cc {$from} WHERE cc.contact_type = \"Organization\" AND cc.id = {$currentEmployer} AND cc.sort_name LIKE '$strSearch'"); - if ($dao->fetch()) { - $currEmpDetails = [ - 'id' => $dao->id, - 'data' => $dao->data, - ]; - } - } - } - } - - if (!empty($params['contact_sub_type'])) { - $contactSubType = CRM_Utils_Type::escape($params['contact_sub_type'], 'String'); - $whereClauses[] = "cc.contact_sub_type = '{$contactSubType}'"; - } - - if (!empty($params['contact_type'])) { - $contactType = CRM_Utils_Type::escape($params['contact_type'], 'String'); - $whereClauses[] = "cc.contact_type LIKE '{$contactType}'"; - } - - // Set default for current_employer or return contact with particular id - if (!empty($params['id'])) { - $whereClauses[] = 'cc.id = ' . (int) $params['id']; - } - - if (!empty($params['cid'])) { - $whereClauses[] = 'cc.id <> ' . (int) $params['cid']; - } - - // Contact's based of relationhip type - $relType = NULL; - if (!empty($params['rel'])) { - $relation = explode('_', $params['rel']); - $relType = CRM_Utils_Type::escape($relation[0], 'Integer'); - $rel = CRM_Utils_Type::escape($relation[2], 'String'); - } - - if ($isPrependWildcard) { - $strSearch = "%$name%"; - } - else { - $strSearch = "$name%"; - } - $includeEmailFrom = $includeNickName = ''; - if ($config->includeNickNameInName) { - $includeNickName = " OR nick_name LIKE '$strSearch'"; - } - $where = ' AND ' . implode(' AND ', $whereClauses); - if (isset($customOptionsWhere)) { - $customOptionsWhere = $customOptionsWhere ?: [0]; - $whereClause = ' WHERE (' . implode(' OR ', $customOptionsWhere) . ") $where"; - } - elseif (!empty($params['field_name']) && !empty($params['table_name']) && $params['field_name'] != 'sort_name') { - $whereClause = " WHERE ( $table_name.$field_name LIKE '$strSearch') {$where}"; - // Search by id should be exact - if ($field_name == 'id' || $field_name == 'external_identifier') { - $whereClause = " WHERE ( $table_name.$field_name = '$name') {$where}"; - } - } - else { - $whereClause = " WHERE ( sort_name LIKE '$strSearch' $includeNickName ) {$where} "; - if ($config->includeEmailInName) { - if (!in_array('email', $list)) { - $includeEmailFrom = "LEFT JOIN civicrm_email eml ON ( cc.id = eml.contact_id AND eml.is_primary = 1 )"; - } - $emailWhere = " WHERE email LIKE '$strSearch'"; - } - } - - $additionalFrom = ''; - if ($relType) { - $additionalFrom = " - INNER JOIN civicrm_relationship_type r ON ( - r.id = {$relType} - AND ( cc.contact_type = r.contact_type_{$rel} OR r.contact_type_{$rel} IS NULL ) - AND ( cc.contact_sub_type = r.contact_sub_type_{$rel} OR r.contact_sub_type_{$rel} IS NULL ) - )"; - } - - // check if only CMS users are requested - if (!empty($params['cmsuser'])) { - $additionalFrom = " - INNER JOIN civicrm_uf_match um ON (um.contact_id=cc.id) - "; - } - $orderBy = _civicrm_api3_quicksearch_get_order_by($name, $isPrependWildcard, $field_name); - - //CRM-5954 - $query = " - SELECT DISTINCT(id), data, sort_name, exactFirst - FROM ( - ( SELECT IF($table_name.$field_name = '{$name}', 0, 1) as exactFirst, cc.id as id, CONCAT_WS( ' :: ', - {$actualSelectElements} ) - as data - {$select} - FROM civicrm_contact cc {$from} - {$aclFrom} - {$additionalFrom} - {$whereClause} - {$orderBy} - LIMIT 0, {$limit} ) - "; - - if (!empty($emailWhere)) { - $query .= " - UNION ( - SELECT IF($table_name.$field_name = '{$name}', 0, 1) as exactFirst, cc.id as id, CONCAT_WS( ' :: ', - {$actualSelectElements} ) - as data - {$select} - FROM civicrm_contact cc {$from} - {$aclFrom} - {$additionalFrom} {$includeEmailFrom} - {$emailWhere} AND cc.is_deleted = 0 " . ($aclWhere ? " AND $aclWhere " : '') . " - {$orderBy} - LIMIT 0, {$limit} - ) - "; - } - $query .= ") t - {$orderBy} - LIMIT 0, {$limit} - "; - - // send query to hook to be modified if needed - CRM_Utils_Hook::contactListQuery($query, - $name, - empty($params['context']) ? NULL : CRM_Utils_Type::escape($params['context'], 'String'), - empty($params['id']) ? NULL : $params['id'] - ); - - $dao = CRM_Core_DAO::executeQuery($query); - - $contactList = []; - $listCurrentEmployer = TRUE; - while ($dao->fetch()) { - $t = ['id' => $dao->id]; - foreach ($as as $k) { - $t[$k] = $dao->$k ?? ''; - } - $t['data'] = $dao->data; - // Replace keys with values when displaying fields from an option list - if (!empty($customOptionsWhere)) { - $data = explode(' :: ', $dao->data); - $pos = count($data) - 1; - $customValue = array_intersect(CRM_Utils_Array::explodePadded($data[$pos]), array_keys($customOptionsWhere)); - $data[$pos] = implode(', ', array_intersect_key($customFieldOptions, array_flip($customValue))); - $t['data'] = implode(' :: ', $data); - } - $contactList[] = $t; - if (!empty($params['org']) && - !empty($currEmpDetails) && - $dao->id == $currEmpDetails['id'] - ) { - $listCurrentEmployer = FALSE; - } - } - - //return organization name if doesn't exist in db - if (empty($contactList)) { - if (!empty($params['org'])) { - if ($listCurrentEmployer && !empty($currEmpDetails)) { - $contactList = [ - [ - 'data' => $currEmpDetails['data'], - 'id' => $currEmpDetails['id'], - ], - ]; - } - else { - $contactList = [ - [ - 'data' => $name, - 'id' => $name, - ], - ]; - } - } - } - - return civicrm_api3_create_success($contactList, $params, 'Contact', 'getquick'); -} - /** * Get the order by string for the quicksearch query. * @@ -1134,17 +743,6 @@ function _civicrm_api3_quicksearch_get_order_by($name, $isPrependWildcard, $fiel return "ORDER BY exactFirst, sort_name"; } -/** - * Declare deprecated api functions. - * - * @deprecated api notice - * @return array - * Array of deprecated actions - */ -function _civicrm_api3_contact_deprecation() { - return ['getquick' => 'The "getquick" action is deprecated in favor of "getlist".']; -} - /** * Merges given pair of duplicate contacts. * diff --git a/tests/phpunit/api/v3/ContactTest.php b/tests/phpunit/api/v3/ContactTest.php index 7aa20d7251..647b6060be 100644 --- a/tests/phpunit/api/v3/ContactTest.php +++ b/tests/phpunit/api/v3/ContactTest.php @@ -2197,24 +2197,6 @@ class api_v3_ContactTest extends CiviUnitTestCase { $this->assertEquals('Anthony', $result['values'][$contactID]['first_name']); } - /** - * Test civicrm_contact_getquick() with empty name param. - * - * @throws \CRM_Core_Exception - */ - public function testContactGetQuick(): void { - $contactID = $this->individualCreate(['first_name' => 'Test', 'last_name' => 'Contact', 'email' => 'TestContact@example.com']); - - $result = $this->callAPISuccess('contact', 'getquick', ['name' => 'T']); - $this->assertEquals($contactID, $result['values'][0]['id']); - $params = [ - 'name' => 'TestContact@example.com', - 'field_name' => 'sort_name', - ]; - $result = $this->callAPISuccess('contact', 'getquick', $params); - $this->assertEquals($contactID, $result['values'][0]['id']); - } - /** * Test civicrm_contact_get) with empty params. * @@ -3266,42 +3248,6 @@ class api_v3_ContactTest extends CiviUnitTestCase { $this->assertEquals(1, $result['count']); } - /** - * Test that Ajax API permission is sufficient to access getquick api. - * - * (note that getquick api is required for autocomplete & has ACL permissions - * applied) - * - * @throws \CRM_Core_Exception - */ - public function testGetquickPermissionCRM13744(): void { - CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviEvent']; - $this->callAPIFailure('contact', 'getquick', ['name' => 'b', 'check_permissions' => TRUE]); - CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM']; - $this->callAPISuccess('contact', 'getquick', ['name' => 'b', 'check_permissions' => TRUE]); - CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access AJAX API']; - $this->callAPISuccess('contact', 'getquick', ['name' => 'b', 'check_permissions' => TRUE]); - } - - /** - * Test that getquick returns contacts with an exact first name match first. - * - * The search string 'b' & 'bob' both return ordered by sort_name if - * includeOrderByClause is true (default) but if it is false then matches are - * returned in ID order. - * - * @dataProvider getSearchSortOptions - * @throws \CRM_Core_Exception - */ - public function testGetQuickExactFirst($searchParameters, $settings, $firstContact, $secondContact = NULL): void { - $this->getQuickSearchSampleData(); - $this->callAPISuccess('Setting', 'create', $settings); - $result = $this->callAPISuccess('contact', 'getquick', $searchParameters); - $this->assertEquals($firstContact, $result['values'][0]['sort_name']); - $this->assertEquals($secondContact, $result['values'][1]['sort_name']); - $this->callAPISuccess('Setting', 'create', ['includeWildCardInName' => TRUE, 'includeOrderByClause' => TRUE]); - } - public function getSearchSortOptions(): array { $firstAlphabeticalContactBySortName = 'A Bobby, Bobby'; $secondAlphabeticalContactBySortName = 'Aardvark, Bob'; @@ -3384,250 +3330,6 @@ class api_v3_ContactTest extends CiviUnitTestCase { ]; } - /** - * Test that getquick returns contacts with an exact first name match first. - * - * @throws \CRM_Core_Exception - */ - public function testGetQuickEmail(): void { - $this->getQuickSearchSampleData(); - $loggedInContactID = $this->createLoggedInUser(); - $result = $this->callAPISuccess('contact', 'getquick', [ - 'name' => 'c', - ]); - $expectedData = [ - 'A Bobby, Bobby :: bob@bobby.com', - 'Bob, Bob :: bob@bob.com', - 'C Bobby, Bobby', - 'H Bobby, Bobby :: bob@h.com', - 'Second Domain :: domainemail2@example.org', - $this->callAPISuccessGetValue('Contact', ['id' => $loggedInContactID, 'return' => 'last_name']) . ', Logged In :: anthony_anderson@civicrm.org', - ]; - $this->assertEquals(6, $result['count']); - foreach ($expectedData as $index => $value) { - $this->assertEquals($value, $result['values'][$index]['data']); - } - $result = $this->callAPISuccess('contact', 'getquick', [ - 'name' => 'h.', - ]); - $expectedData = [ - 'H Bobby, Bobby :: bob@h.com', - ]; - foreach ($expectedData as $index => $value) { - $this->assertEquals($value, $result['values'][$index]['data']); - } - $this->callAPISuccess('Setting', 'create', ['includeWildCardInName' => FALSE]); - $result = $this->callAPISuccess('contact', 'getquick', [ - 'name' => 'h.', - ]); - $this->callAPISuccess('Setting', 'create', ['includeWildCardInName' => TRUE]); - $this->assertEquals(0, $result['count']); - } - - /** - * Test that getquick returns contacts with an exact first name match first. - * - * @throws \CRM_Core_Exception - */ - public function testGetQuickEmailACL(): void { - $this->getQuickSearchSampleData(); - $loggedInContactID = $this->createLoggedInUser(); - CRM_Core_Config::singleton()->userPermissionClass->permissions = []; - $result = $this->callAPISuccess('contact', 'getquick', [ - 'name' => 'c', - ]); - $this->assertEquals(0, $result['count']); - - $this->hookClass->setHook('civicrm_aclWhereClause', [$this, 'aclWhereNoBobH']); - CRM_Contact_BAO_Contact_Permission::cache($loggedInContactID, CRM_Core_Permission::VIEW, TRUE); - $result = $this->callAPISuccess('contact', 'getquick', [ - 'name' => 'c', - ]); - - // Without the acl it would be 6 like the previous email getquick test. - $this->assertEquals(5, $result['count']); - $expectedData = [ - 'A Bobby, Bobby :: bob@bobby.com', - 'Bob, Bob :: bob@bob.com', - 'C Bobby, Bobby', - 'Second Domain :: domainemail2@example.org', - $this->callAPISuccessGetValue('Contact', ['id' => $loggedInContactID, 'return' => 'last_name']) . ', Logged In :: anthony_anderson@civicrm.org', - ]; - foreach ($expectedData as $index => $value) { - $this->assertEquals($value, $result['values'][$index]['data']); - } - } - - /** - * Test that getquick returns contacts with an exact first name match first. - * - * @throws \CRM_Core_Exception - */ - public function testGetQuickExternalID(): void { - $this->getQuickSearchSampleData(); - $result = $this->callAPISuccess('contact', 'getquick', [ - 'name' => 'b', - 'field_name' => 'external_identifier', - 'table_name' => 'cc', - ]); - $this->assertEquals(0, $result['count']); - $result = $this->callAPISuccess('contact', 'getquick', [ - 'name' => 'abc', - 'field_name' => 'external_identifier', - 'table_name' => 'cc', - ]); - $this->assertEquals(1, $result['count']); - $this->assertEquals('Bob, Bob', $result['values'][0]['sort_name']); - } - - /** - * Test that getquick returns contacts with an exact first name match first. - * - * @throws \CRM_Core_Exception - */ - public function testGetQuickID(): void { - $max = CRM_Core_DAO::singleValueQuery('SELECT max(id) FROM civicrm_contact'); - $this->getQuickSearchSampleData(); - $result = $this->callAPISuccess('contact', 'getquick', [ - 'name' => $max + 2, - 'field_name' => 'id', - 'table_name' => 'cc', - ]); - $this->assertEquals(1, $result['count']); - $this->assertEquals('E Bobby, Bobby', $result['values'][0]['sort_name']); - $result = $this->callAPISuccess('contact', 'getquick', [ - 'name' => $max + 2, - 'field_name' => 'contact_id', - 'table_name' => 'cc', - ]); - $this->assertEquals(1, $result['count']); - $this->assertEquals('E Bobby, Bobby', $result['values'][0]['sort_name']); - } - - /** - * Test that getquick returns contacts with different cases of phone - * substring. - * - * @throws \CRM_Core_Exception - */ - public function testGetQuickPhone(): void { - $this->getQuickSearchSampleData(); - $criterion = [ - [ - 'criteria' => [ - 'name' => '87-6', - 'field_name' => 'phone_numeric', - ], - 'count' => 2, - 'sort_names' => [ - 'I Bobby, Bobby', - 'J Bobby, Bobby', - ], - ], - [ - 'criteria' => [ - 'name' => '876-1', - 'field_name' => 'phone_numeric', - ], - 'count' => 1, - 'sort_names' => [ - 'I Bobby, Bobby', - ], - ], - [ - 'criteria' => [ - 'name' => '87623', - 'field_name' => 'phone_numeric', - ], - 'count' => 1, - 'sort_names' => [ - 'J Bobby, Bobby', - ], - ], - [ - 'criteria' => [ - 'name' => '8a7abc6', - 'field_name' => 'phone_numeric', - ], - 'count' => 2, - 'sort_names' => [ - 'I Bobby, Bobby', - 'J Bobby, Bobby', - ], - ], - ]; - - foreach ($criterion as $criteria) { - $result = $this->callAPISuccess('contact', 'getquick', $criteria['criteria']); - $this->assertEquals($result['count'], $criteria['count']); - foreach ($criteria['sort_names'] as $key => $sortName) { - $this->assertEquals($sortName, $result['values'][$key]['sort_name']); - } - } - } - - /** - * Test that getquick returns contacts with an exact first name match first. - * - * Depending on the setting the sort name sort might click in next or not - - * test! - * - * @throws \CRM_Core_Exception - */ - public function testGetQuickFirstName(): void { - $this->getQuickSearchSampleData(); - $this->callAPISuccess('Setting', 'create', ['includeOrderByClause' => TRUE]); - $result = $this->callAPISuccess('contact', 'getquick', [ - 'name' => 'Bob', - 'field_name' => 'first_name', - 'table_name' => 'cc', - ]); - $expected = [ - 'Aardvark, Bob', - 'Bob, Bob', - 'K Bobby, Bob', - 'A Bobby, Bobby', - ]; - - foreach ($expected as $index => $value) { - $this->assertEquals($value, $result['values'][$index]['sort_name']); - } - $this->callAPISuccess('Setting', 'create', ['includeOrderByClause' => FALSE]); - $result = $this->callAPISuccess('contact', 'getquick', ['name' => 'bob']); - $this->assertEquals('Bob, Bob', $result['values'][0]['sort_name']); - // This test has been disabled as is proving to be problematic to reproduce due to MySQL sorting issues between different versions - //$this->assertEquals('E Bobby, Bobby', $result['values'][1]['sort_name']); - } - - /** - * Test that getquick applies ACLs. - * - * @throws \CRM_Core_Exception - */ - public function testGetQuickFirstNameACLs(): void { - $this->getQuickSearchSampleData(); - $userID = $this->createLoggedInUser(); - $this->callAPISuccess('Setting', 'create', ['includeOrderByClause' => TRUE, 'search_autocomplete_count' => 15]); - CRM_Core_Config::singleton()->userPermissionClass->permissions = []; - $result = $this->callAPISuccess('contact', 'getquick', [ - 'name' => 'Bob', - 'field_name' => 'first_name', - 'table_name' => 'cc', - ]); - $this->assertEquals(0, $result['count']); - - $this->hookClass->setHook('civicrm_aclWhereClause', [$this, 'aclWhereNoBobH']); - CRM_Contact_BAO_Contact_Permission::cache($userID, CRM_Core_Permission::VIEW, TRUE); - $result = $this->callAPISuccess('contact', 'getquick', [ - 'name' => 'Bob', - 'field_name' => 'first_name', - 'table_name' => 'cc', - ]); - $this->assertEquals('K Bobby, Bob', $result['values'][2]['sort_name']); - // Without the ACL 9 would be bob@h.com. - $this->assertEquals('I Bobby, Bobby', $result['values'][10]['sort_name']); - } - /** * Full results returned. * @@ -3646,159 +3348,6 @@ class api_v3_ContactTest extends CiviUnitTestCase { $whereTables['civicrm_email'] = 'LEFT JOIN civicrm_email e ON contact_a.id = e.contact_id'; } - /** - * Test that getquick returns contacts with an exact last name match first. - * - * @throws \CRM_Core_Exception - */ - public function testGetQuickLastName(): void { - $this->getQuickSearchSampleData(); - $this->callAPISuccess('Setting', 'create', ['includeOrderByClause' => TRUE]); - $result = $this->callAPISuccess('contact', 'getquick', [ - 'name' => 'Bob', - 'field_name' => 'last_name', - 'table_name' => 'cc', - ]); - $expected = [ - 'Bob, Bob', - 'A Bobby, Bobby', - 'B Bobby, Bobby', - ]; - - foreach ($expected as $index => $value) { - $this->assertEquals($value, $result['values'][$index]['sort_name']); - } - $this->callAPISuccess('Setting', 'create', ['includeOrderByClause' => FALSE]); - $result = $this->callAPISuccess('contact', 'getquick', ['name' => 'bob']); - $this->assertEquals('Bob, Bob :: bob@bob.com', $result['values'][0]['data']); - } - - /** - * Test deleted contacts are excluded from getquick results. - * - * @throws \CRM_Core_Exception - */ - public function testGetQuickNotDeleted(): void { - $this->getQuickSearchSampleData(); - $result = $this->callAPISuccess('contact', 'getquick', [ - 'name' => 'abc', - 'field_name' => 'external_identifier', - 'table_name' => 'cc', - ])['values']; - $this->assertCount(1, $result); - $this->callAPISuccess('Contact', 'delete', ['id' => $result['0']['id']]); - $result = $this->callAPISuccess('contact', 'getquick', [ - 'name' => 'abc', - 'field_name' => 'external_identifier', - 'table_name' => 'cc', - ])['values']; - $this->assertCount(0, $result); - } - - /** - * Test that getquick returns contacts by city. - * - * @throws \CRM_Core_Exception - */ - public function testGetQuickCity(): void { - $this->getQuickSearchSampleData(); - $result = $this->callAPISuccess('contact', 'getquick', [ - 'name' => 'o', - 'field_name' => 'city', - 'table_name' => 'sts', - ]); - $this->assertEquals('B Bobby, Bobby :: Toronto', $result['values'][0]['data']); - $result = $this->callAPISuccess('contact', 'getquick', [ - 'name' => 'n', - 'field_name' => 'city', - 'table_name' => 'sts', - ]); - $this->assertEquals('B Bobby, Bobby :: Toronto', $result['values'][0]['data']); - $this->assertEquals('C Bobby, Bobby :: Whanganui', $result['values'][1]['data']); - } - - /** - * Test that getquick doesn't work with field_name=api_key - * - * @throws \CRM_Core_Exception - */ - public function testGetQuickApiKey(): void { - $this->callAPISuccess('Contact', 'create', [ - 'contact_type' => 'Individual', - 'email' => 'apiuser@example.com', - 'api_key' => 'hunter2', - ]); - $this->callAPIFailure('Contact', 'getquick', [ - 'name' => '%', - 'field_name' => 'api_key', - ], 'Illegal value "api_key" for parameter "field_name"'); - } - - /** - * Set up some sample data for testing quicksearch. - * - * @throws \CRM_Core_Exception - */ - public function getQuickSearchSampleData(): void { - $contacts = [ - ['first_name' => 'Bob', 'last_name' => 'Bob', 'external_identifier' => 'abc', 'email' => 'bob@bob.com'], - ['first_name' => 'Bobby', 'last_name' => 'E Bobby', 'external_identifier' => 'abcd'], - [ - 'first_name' => 'Bobby', - 'last_name' => 'B Bobby', - 'external_identifier' => 'bcd', - 'api.address.create' => [ - 'street_address' => 'Sesame Street', - 'city' => 'Toronto', - 'location_type_id' => 1, - ], - ], - [ - 'first_name' => 'Bobby', - 'last_name' => 'C Bobby', - 'external_identifier' => 'bcde', - 'api.address.create' => [ - 'street_address' => 'Te huarahi', - 'city' => 'Whanganui', - 'location_type_id' => 1, - ], - ], - ['first_name' => 'Bobby', 'last_name' => 'D Bobby', 'external_identifier' => 'efg'], - ['first_name' => 'Bobby', 'last_name' => 'A Bobby', 'external_identifier' => 'hij', 'email' => 'bob@bobby.com'], - ['first_name' => 'Bobby', 'last_name' => 'F Bobby', 'external_identifier' => 'klm'], - ['first_name' => 'Bobby', 'last_name' => 'G Bobby', 'external_identifier' => 'nop'], - ['first_name' => 'Bobby', 'last_name' => 'H Bobby', 'external_identifier' => 'qrs', 'email' => 'bob@h.com'], - [ - 'first_name' => 'Bobby', - 'last_name' => 'I Bobby', - 'api.phone.create' => [ - 'phone' => '876-123', - 'phone_ext' => '444', - 'phone_type_id' => 'Phone', - 'location_type_id' => 1, - 'is_primary' => 1, - ], - ], - [ - 'first_name' => 'Bobby', - 'last_name' => 'J Bobby', - 'api.phone.create' => [ - 'phone' => '87-6-234', - 'phone_ext' => '134', - 'phone_type_id' => 'Phone', - 'location_type_id' => 1, - 'is_primary' => 1, - ], - ], - ['first_name' => 'Bob', 'last_name' => 'K Bobby', 'external_identifier' => 'bcdef'], - ['first_name' => 'Bob', 'last_name' => 'Aardvark'], - ]; - foreach ($contacts as $contact) { - $contact['contact_type'] = 'Individual'; - $this->callAPISuccess('Contact', 'create', $contact); - } - } - /** * Test get ref api - gets a list of references to an entity. * @@ -3998,7 +3547,6 @@ class api_v3_ContactTest extends CiviUnitTestCase { 'getfields', 'getlist', 'getoptions', - 'getquick', 'getrefcount', 'getsingle', 'getvalue', @@ -4010,7 +3558,6 @@ class api_v3_ContactTest extends CiviUnitTestCase { ]; $deprecated = [ 'update', - 'getquick', ]; foreach ($expected as $action) { $this->assertContains($action, $result['values'], "Expected action $action"); -- 2.25.1