From ef3fd2793b5a035ce4c5083123b8114c177a4e49 Mon Sep 17 00:00:00 2001 From: eileenmcnaugton Date: Tue, 25 Aug 2015 20:48:41 +1200 Subject: [PATCH] CRM-17023 put exact matches first Without tests it's a bit hard to know the original intent but this makes sense to me --- api/v3/Contact.php | 2 +- tests/phpunit/api/v3/ContactTest.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/api/v3/Contact.php b/api/v3/Contact.php index 5f603974ef..c0c0e462cb 100644 --- a/api/v3/Contact.php +++ b/api/v3/Contact.php @@ -876,7 +876,7 @@ function civicrm_api3_contact_getquick($params) { $orderByInner = $orderByOuter = "ORDER BY exactFirst"; if ($config->includeOrderByClause) { - $orderByInner = "ORDER BY sort_name"; + $orderByInner = "ORDER BY exactFirst, sort_name"; $orderByOuter .= ", sort_name"; } diff --git a/tests/phpunit/api/v3/ContactTest.php b/tests/phpunit/api/v3/ContactTest.php index 00ad2b9212..df5ef1a941 100644 --- a/tests/phpunit/api/v3/ContactTest.php +++ b/tests/phpunit/api/v3/ContactTest.php @@ -2243,9 +2243,12 @@ class api_v3_ContactTest extends CiviUnitTestCase { /** * 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! */ public function testGetQuickFirstName() { $this->getQuickSearchSampleData(); + $this->callAPISuccess('Setting', 'create', array('includeOrderByClause' => TRUE)); $result = $this->callAPISuccess('contact', 'getquick', array( 'name' => 'Bob', 'field_name' => 'first_name', @@ -2263,6 +2266,7 @@ class api_v3_ContactTest extends CiviUnitTestCase { $this->callAPISuccess('Setting', 'create', array('includeOrderByClause' => FALSE)); $result = $this->callAPISuccess('contact', 'getquick', array('name' => 'bob')); $this->assertEquals('Bob, Bob', $result['values'][0]['sort_name']); + $this->assertEquals('A Bobby, Bobby', $result['values'][1]['sort_name']); } /** -- 2.25.1