From 7906396a3424d6d9bf97015e9db612dde7d65047 Mon Sep 17 00:00:00 2001 From: Jitendra Purohit Date: Fri, 13 Dec 2019 18:16:33 +0530 Subject: [PATCH] dev/core#1474 - (On Hold) text missing from email column when custom search profile is used in Advanced Search Add test --- CRM/Contact/Selector.php | 16 ++++++ tests/phpunit/CRM/Contact/SelectorTest.php | 66 ++++++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/CRM/Contact/Selector.php b/CRM/Contact/Selector.php index 45a5b7afd1..f9ddd8e954 100644 --- a/CRM/Contact/Selector.php +++ b/CRM/Contact/Selector.php @@ -195,6 +195,13 @@ class CRM_Contact_Selector extends CRM_Core_Selector_Base implements CRM_Core_Se $this->_returnProperties['contact_type'] = 1; $this->_returnProperties['contact_sub_type'] = 1; $this->_returnProperties['sort_name'] = 1; + if (!empty($this->_returnProperties['location']) && is_array($this->_returnProperties['location'])) { + foreach ($this->_returnProperties['location'] as $key => $property) { + if (!empty($property['email'])) { + $this->_returnProperties['location'][$key]['on_hold'] = 1; + } + } + } } $displayRelationshipType = CRM_Utils_Array::value('display_relationship_type', $this->_formValues); @@ -708,6 +715,15 @@ class CRM_Contact_Selector extends CRM_Core_Selector_Base implements CRM_Core_Se } $row[$property] = $websiteUrl; } + elseif (strpos($property, '-email') !== FALSE) { + list($locType) = explode("-email", $property); + $onholdProperty = "{$locType}-on_hold"; + + $row[$property] = isset($result->$property) ? $result->$property : NULL; + if (!empty($row[$property]) && !empty($result->$onholdProperty)) { + $row[$property] .= " (On Hold)"; + } + } else { $row[$property] = isset($result->$property) ? $result->$property : NULL; } diff --git a/tests/phpunit/CRM/Contact/SelectorTest.php b/tests/phpunit/CRM/Contact/SelectorTest.php index 0abbe0b1bc..6e9740b9cb 100644 --- a/tests/phpunit/CRM/Contact/SelectorTest.php +++ b/tests/phpunit/CRM/Contact/SelectorTest.php @@ -91,6 +91,72 @@ class CRM_Contact_SelectorTest extends CiviUnitTestCase { } } + /** + * Test advanced search results by uf_group_id. + */ + public function testSearchByProfile() { + //Create search profile for contacts. + $ufGroup = $this->callAPISuccess('uf_group', 'create', [ + 'group_type' => 'Contact', + 'name' => 'test_search_profile', + 'title' => 'Test Search Profile', + 'api.uf_field.create' => [ + [ + 'field_name' => 'email', + 'visibility' => 'Public Pages and Listings', + 'field_type' => 'Contact', + 'label' => 'Email', + 'in_selector' => 1, + ], + ], + ]); + $contactID = $this->individualCreate(['email' => 'mickey@mouseville.com']); + //Put the email on hold. + $email = $this->callAPISuccess('Email', 'get', [ + 'sequential' => 1, + 'contact_id' => $contactID, + ]); + $this->callAPISuccess('Email', 'create', [ + 'id' => $email['id'], + 'on_hold' => 1, + ]); + + $dataSet = [ + 'description' => 'Normal default behaviour', + 'class' => 'CRM_Contact_Selector', + 'settings' => [], + 'form_values' => ['email' => 'mickey@mouseville.com', 'uf_group_id' => $ufGroup['id']], + 'params' => [], + 'return_properties' => NULL, + 'context' => 'advanced', + 'action' => CRM_Core_Action::ADVANCED, + 'includeContactIds' => NULL, + 'searchDescendentGroups' => FALSE, + ]; + $params = CRM_Contact_BAO_Query::convertFormValues($dataSet['form_values'], 0, FALSE, NULL, []); + // create CRM_Contact_Selector instance and set desired query params + $selector = new CRM_Contact_Selector( + $dataSet['class'], + $dataSet['form_values'], + $params, + $dataSet['return_properties'], + $dataSet['action'], + $dataSet['includeContactIds'], + $dataSet['searchDescendentGroups'], + $dataSet['context'] + ); + $rows = $selector->getRows(CRM_Core_Action::VIEW, 0, 50, ''); + $this->assertEquals(1, count($rows)); + $this->assertEquals($contactID, key($rows)); + + //Check if email column contains (On Hold) string. + foreach ($rows[$contactID] as $key => $value) { + if (strpos($key, 'email') !== FALSE) { + $this->assertContains("(On Hold)", (string) $value); + } + } + } + /** * Test the civicrm_prevnext_cache entry if it correctly stores the search query result */ -- 2.25.1