Skip to content

Commit

Permalink
Merge pull request #15276 from eileenmcnaughton/email2
Browse files Browse the repository at this point in the history
Ensure filtering on email via the api looks for an exact match
  • Loading branch information
eileenmcnaughton authored Sep 11, 2019
2 parents 12c0761 + b69793b commit 91ae8b4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 7 additions & 0 deletions api/v3/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions tests/phpunit/api/v3/ContactTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,8 @@ public function testCreateBadRequiredFieldsOrganization() {

/**
* Verify that attempt to create individual contact with only an email succeeds.
*
* @throws \CRM_Core_Exception
*/
public function testCreateEmailIndividual() {
$primaryEmail = 'man3@yahoo.com';
Expand Down Expand Up @@ -397,10 +399,12 @@ public function testCreateEmailIndividual() {
$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);
}

Expand Down

0 comments on commit 91ae8b4

Please sign in to comment.