diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 37a13976fc00..083b643c5b75 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -3400,8 +3400,6 @@ public function sortName(&$values) { //By default, $sub elements should be joined together with OR statements (don't change this variable). $subGlue = ' OR '; - $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower'; - $firstChar = substr($value, 0, 1); $lastChar = substr($value, -1, 1); $quotes = array("'", '"'); @@ -3414,22 +3412,19 @@ public function sortName(&$values) { elseif ($op == 'LIKE' && strpos($value, ',') === FALSE) { $value = str_replace(' ', '%', $value); } - $value = $strtolower(CRM_Core_DAO::escapeString(trim($value))); + $value = CRM_Core_DAO::escapeString(trim($value)); if (strlen($value)) { $fieldsub = array(); $value = "'" . self::getWildCardedValue($wildcard, $op, $value) . "'"; if ($fieldName == 'sort_name') { - // LOWER roughly translates to 'hurt my database without deriving any benefit' See CRM-19811. - $wc = self::caseImportant($op) ? "LOWER(contact_a.sort_name)" : "contact_a.sort_name"; + $wc = "contact_a.sort_name"; } else { - // LOWER roughly translates to 'hurt my database without deriving any benefit' See CRM-19811. - $wc = self::caseImportant($op) ? "LOWER(contact_a.display_name)" : "contact_a.display_name"; + $wc = "contact_a.display_name"; } $fieldsub[] = " ( $wc $op $value )"; if ($config->includeNickNameInName) { - // LOWER roughly translates to 'hurt my database without deriving any benefit' See CRM-19811. - $wc = self::caseImportant($op) ? "LOWER(contact_a.nick_name)" : "contact_a.nick_name"; + $wc = "contact_a.nick_name"; $fieldsub[] = " ( $wc $op $value )"; } if ($config->includeEmailInName) { diff --git a/tests/phpunit/api/v3/ContactTest.php b/tests/phpunit/api/v3/ContactTest.php index 3e2e9b0c2622..ebef36284e3c 100644 --- a/tests/phpunit/api/v3/ContactTest.php +++ b/tests/phpunit/api/v3/ContactTest.php @@ -396,6 +396,22 @@ public function testCreateDisplayNameIndividual() { $this->getAndCheck($params, $contact['id'], 'contact'); } + /** + * Test that name searches are case insensitive. + */ + public function testGetNameVariantsCaseInsensitive() { + $this->callAPISuccess('contact', 'create', [ + 'display_name' => 'Abc1', + 'contact_type' => 'Individual', + ]); + $this->callAPISuccessGetSingle('Contact', ['display_name' => 'aBc1']); + $this->callAPISuccessGetSingle('Contact', ['sort_name' => 'aBc1']); + Civi::settings()->set('includeNickNameInName', TRUE); + $this->callAPISuccessGetSingle('Contact', ['display_name' => 'aBc1']); + $this->callAPISuccessGetSingle('Contact', ['sort_name' => 'aBc1']); + Civi::settings()->set('includeNickNameInName', FALSE); + } + /** * Test old keys still work. * @@ -3183,7 +3199,7 @@ public function testReturnCityProfile() { * CRM-15443 - ensure getlist api does not return deleted contacts. */ public function testGetlistExcludeConditions() { - $name = md5(time()); + $name = 'Scarabée'; $contact = $this->individualCreate(array('last_name' => $name)); $this->individualCreate(array('last_name' => $name, 'is_deceased' => 1)); $this->individualCreate(array('last_name' => $name, 'is_deleted' => 1));