diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 983110d85442..c8e943aea01e 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -2130,7 +2130,7 @@ public function restWhere(&$values) { $setTables = TRUE; - $locationType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'); + $locationType = CRM_Core_DAO_Address::buildOptions('location_type_id', 'validate'); if (isset($locType[1]) && is_numeric($locType[1])) { $lType = $locationType[$locType[1]]; } diff --git a/tests/phpunit/CRM/Contact/BAO/QueryTest.php b/tests/phpunit/CRM/Contact/BAO/QueryTest.php index 64f1140a7f05..d6a038bd9e89 100644 --- a/tests/phpunit/CRM/Contact/BAO/QueryTest.php +++ b/tests/phpunit/CRM/Contact/BAO/QueryTest.php @@ -208,6 +208,51 @@ public function testSearchPrimaryLocTypes() { } } + /** + * Test created to prove failure of search on state when location + * display name is different form location name (issue 607) + */ + public function testSearchOtherLocationUpperLower() { + + $params = [ + 0 => [ + 0 => 'state_province-4', + 1 => 'IS NOT EMPTY', + 2 => '', + 3 => 1, + 4 => 0, + ], + ]; + $returnProperties = [ + 'contact_type' => 1, + 'contact_sub_type' => 1, + 'sort_name' => 1, + 'location' => [ + 'other' => [ + 'location_type' => 4, + 'state_province' => 1, + ], + ], + ]; + + // update with the api does not work because it updates both the name and the + // the display_name. Plain SQL however does the job + CRM_Core_DAO::executeQuery('update civicrm_location_type set name=%2 where id=%1', + [ + 1 => [4, 'Integer'], + 2 => ['other', 'String'], + ]); + + $queryObj = new CRM_Contact_BAO_Query($params, $returnProperties); + + $resultDAO = $queryObj->searchQuery(0, 0, NULL, + FALSE, FALSE, + FALSE, FALSE, + FALSE); + $resultDAO->fetch(); + } + + /** * CRM-14263 search builder failure with search profile & address in criteria. *