Ensure filtering on email via the api looks for an exact match
authoreileen <emcnaughton@wikimedia.org>
Wed, 11 Sep 2019 01:49:06 +0000 (13:49 +1200)
committereileen <emcnaughton@wikimedia.org>
Wed, 11 Sep 2019 02:15:06 +0000 (14:15 +1200)
api/v3/Contact.php
tests/phpunit/api/v3/ContactTest.php

index 3c2fc5bed28f07efda93bdbad960bf5de36a36e8..bcaa9954cc8b0fd69302347da3932079c93408b0 100644 (file)
@@ -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;
index 146d5abad7e0840ab4533a36b58189d13ce48b69..1fdd6721d725149bbae51abb3910544c5870cc51 100644 (file)
@@ -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);
   }