From 7b73ab104c3dfa61280f592e3f96794bf087ddfd Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 11 Sep 2019 13:49:06 +1200 Subject: [PATCH] Ensure filtering on email via the api looks for an exact match --- api/v3/Contact.php | 7 +++++++ tests/phpunit/api/v3/ContactTest.php | 8 ++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/api/v3/Contact.php b/api/v3/Contact.php index 3c2fc5bed2..bcaa9954cc 100644 --- a/api/v3/Contact.php +++ b/api/v3/Contact.php @@ -163,6 +163,8 @@ function _civicrm_api3_contact_create_spec(&$params) { * * @return array * API Result Array + * + * @throws \API_Exception */ function civicrm_api3_contact_get($params) { $options = []; @@ -382,6 +384,11 @@ function _civicrm_api3_contact_get_spec(&$params) { * Array of options (so we can modify the filter). */ function _civicrm_api3_contact_get_supportanomalies(&$params, &$options) { + if (!empty($params['email']) && !is_array($params['email'])) { + // Fix this to be in array format so the query object does not add LIKE + // I think there is a better fix that I will do for master. + $params['email'] = ['=' => $params['email']]; + } if (isset($params['showAll'])) { if (strtolower($params['showAll']) == "active") { $params['contact_is_deleted'] = 0; diff --git a/tests/phpunit/api/v3/ContactTest.php b/tests/phpunit/api/v3/ContactTest.php index 146d5abad7..1fdd6721d7 100644 --- a/tests/phpunit/api/v3/ContactTest.php +++ b/tests/phpunit/api/v3/ContactTest.php @@ -367,6 +367,8 @@ class api_v3_ContactTest extends CiviUnitTestCase { /** * Verify that attempt to create individual contact with only an email succeeds. + * + * @throws \CRM_Core_Exception */ public function testCreateEmailIndividual() { $primaryEmail = 'man3@yahoo.com'; @@ -397,10 +399,12 @@ class api_v3_ContactTest extends CiviUnitTestCase { $this->assertEquals($primaryEmail, $email1['values'][$email1['id']]['email']); // Case 3: Check with email_id='primary email id' - $result = $this->callAPISuccess('contact', 'get', ['email_id' => $email1['id']]); - $this->assertEquals(1, $result['count']); + $result = $this->callAPISuccessGetSingle('contact', ['email_id' => $email1['id']]); $this->assertEquals($contact1['id'], $result['id']); + // Check no wildcard is appended + $this->callAPISuccessGetCount('Contact', ['email' => 'man3@yahoo.co'], 0); + $this->callAPISuccess('contact', 'delete', $contact1); } -- 2.25.1