dev/core#1474 - (On Hold) text missing from email column when custom search profile...
authorJitendra Purohit <jitendra@fuzion.co.nz>
Fri, 13 Dec 2019 12:46:33 +0000 (18:16 +0530)
committerJitendra Purohit <jitendra@fuzion.co.nz>
Tue, 17 Dec 2019 06:34:01 +0000 (12:04 +0530)
Add test

CRM/Contact/Selector.php
tests/phpunit/CRM/Contact/SelectorTest.php

index 45a5b7afd13c39adb69ed075224b0cd26e93e790..f9ddd8e9549d4e0681e33da5aa25fceb9cbe10d8 100644 (file)
@@ -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;
         }
index 0abbe0b1bc797a150b92839e0bdfe5aec816bd9c..6e9740b9cbea7563ba2d8b15ade7da8c69c72d02 100644 (file)
@@ -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
    */