(dev/core/116) Search builder searches on primary addresses are producing unexpected...
authordeb.monish <monish.deb@jmaconsulting.biz>
Thu, 17 May 2018 09:48:53 +0000 (15:18 +0530)
committerdeb.monish <monish.deb@jmaconsulting.biz>
Thu, 17 May 2018 09:48:53 +0000 (15:18 +0530)
CRM/Contact/BAO/Query.php
tests/phpunit/CRM/Contact/SelectorTest.php

index 81a191cfa362a059a6bc0b5b8879a8f43cb2a5f7..d25a91de4aed5c0ed8825ff7e86c609ba25811b3 100644 (file)
@@ -3736,7 +3736,7 @@ WHERE  $smartGroupClause
     }
 
     $countryClause = $countryQill = NULL;
-    if ($values && !empty($value)) {
+    if (in_array($op, array('IS NULL', 'IS NOT NULL', 'IS EMPTY', 'IS NOT EMPTY')) || ($values && !empty($value))) {
       $this->_tables['civicrm_address'] = 1;
       $this->_whereTables['civicrm_address'] = 1;
 
index a949df54207f230e6b5b8959565c3a873c6e8d66..b2ab9ae310aa0a9a0079107a787eaa8ad0ca6135 100644 (file)
@@ -73,6 +73,12 @@ class CRM_Contact_Form_SelectorTest extends CiviUnitTestCase {
     // Ensure that search builder return individual contact as per criteria
     if (!empty($dataSet['context'] == 'builder')) {
       $contactID = $this->individualCreate(['first_name' => 'James', 'last_name' => 'Bond']);
+      $this->callAPISuccess('Address', 'create', [
+        'contact_id' => $contactID,
+        'location_type_id' => "Home",
+        'is_primary' => 1,
+        'country_id' => "IN",
+      ]);
       $rows = $selector->getRows(CRM_Core_Action::VIEW, 0, 50, '');
       $this->assertEquals(1, count($rows));
       $sortChar = $selector->alphabetQuery()->fetchAll();
@@ -231,7 +237,7 @@ class CRM_Contact_Form_SelectorTest extends CiviUnitTestCase {
           'description' => 'Normal search builder behaviour',
           'class' => 'CRM_Contact_Selector',
           'settings' => array(),
-          'form_values' => array('contact_type' => 'Individual'),
+          'form_values' => array('contact_type' => 'Individual', 'country' => array('IS NOT NULL' => 1)),
           'params' => array(),
           'return_properties' => array(
             'contact_type' => 1,
@@ -243,9 +249,9 @@ class CRM_Contact_Form_SelectorTest extends CiviUnitTestCase {
           'includeContactIds' => NULL,
           'searchDescendentGroups' => FALSE,
           'expected_query' => array(
-            0 => 'SELECT contact_a.id as contact_id, contact_a.contact_type as `contact_type`, contact_a.contact_sub_type as `contact_sub_type`, contact_a.sort_name as `sort_name`',
-            1 => ' FROM civicrm_contact contact_a',
-            2 => 'WHERE  ( contact_a.contact_type IN ("Individual") )  AND (contact_a.is_deleted = 0)',
+            0 => 'SELECT contact_a.id as contact_id, contact_a.contact_type as `contact_type`, contact_a.contact_sub_type as `contact_sub_type`, contact_a.sort_name as `sort_name`, civicrm_address.id as address_id, civicrm_address.country_id as country_id',
+            1 => ' FROM civicrm_contact contact_a LEFT JOIN civicrm_address ON ( contact_a.id = civicrm_address.contact_id AND civicrm_address.is_primary = 1 )',
+            2 => 'WHERE ( contact_a.contact_type IN ("Individual") AND civicrm_address.country_id IS NOT NULL ) AND (contact_a.is_deleted = 0)',
           ),
         ),
       ),