From fb1ee4681b56ebe0efc4f95181e72e6640f91182 Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 2 Jul 2019 15:12:36 +1200 Subject: [PATCH] [NFC][test] code formatting only SearchTest, SelectorTest --- tests/phpunit/CRM/Contact/BAO/QueryTest.php | 301 +++++++++++--------- tests/phpunit/CRM/Contact/SelectorTest.php | 225 +++++++-------- 2 files changed, 286 insertions(+), 240 deletions(-) diff --git a/tests/phpunit/CRM/Contact/BAO/QueryTest.php b/tests/phpunit/CRM/Contact/BAO/QueryTest.php index 2303dd6e81..824a8ce215 100644 --- a/tests/phpunit/CRM/Contact/BAO/QueryTest.php +++ b/tests/phpunit/CRM/Contact/BAO/QueryTest.php @@ -2,9 +2,11 @@ /** * Include dataProvider for tests + * * @group headless */ class CRM_Contact_BAO_QueryTest extends CiviUnitTestCase { + use CRMTraits_Financial_FinancialACLTrait; use CRMTraits_Financial_PriceSetTrait; @@ -70,19 +72,51 @@ class CRM_Contact_BAO_QueryTest extends CiviUnitTestCase { ['first_name' => 'Test', 'last_name' => 'Test Contact 9', 'gender_id' => 1, 'prefix_id' => 1, 'suffix_id' => 1], ['first_name' => 'Test', 'last_name' => 'Test Contact 10', 'gender_id' => 2, 'prefix_id' => 2, 'suffix_id' => 2, 'api.entity_tag.create' => ['tag_id' => $tag9]], ['first_name' => 'Test', 'last_name' => 'Test Contact 11', 'gender_id' => 3, 'prefix_id' => 3, 'suffix_id' => 3, 'api.entity_tag.create' => ['tag_id' => $tag7]], - ['first_name' => 'Test', 'last_name' => 'Test Contact 12', 'gender_id' => 3, 'prefix_id' => 4, 'suffix_id' => 4, 'api.entity_tag.create' => ['tag_id' => $tag9], 'api.entity_tag.create.2' => ['tag_id' => $tag7]], + [ + 'first_name' => 'Test', + 'last_name' => 'Test Contact 12', + 'gender_id' => 3, + 'prefix_id' => 4, + 'suffix_id' => 4, + 'api.entity_tag.create' => ['tag_id' => $tag9], + 'api.entity_tag.create.2' => ['tag_id' => $tag7], + ], ['first_name' => 'Test', 'last_name' => 'Test Contact 13', 'gender_id' => 2, 'prefix_id' => 2, 'suffix_id' => 2], ['first_name' => 'Test', 'last_name' => 'Test Contact 14', 'gender_id' => 3, 'prefix_id' => 4, 'suffix_id' => 4, 'api.entity_tag.create' => ['tag_id' => $tag9]], ['first_name' => 'Test', 'last_name' => 'Test Contact 15', 'gender_id' => 3, 'prefix_id' => 4, 'suffix_id' => 5, 'api.entity_tag.create' => ['tag_id' => $tag7]], - ['first_name' => 'Test', 'last_name' => 'Test Contact 16', 'gender_id' => 3, 'prefix_id' => 4, 'suffix_id' => 6, 'api.entity_tag.create' => ['tag_id' => $tag9], 'api.entity_tag.create.2' => ['tag_id' => $tag7]], + [ + 'first_name' => 'Test', + 'last_name' => 'Test Contact 16', + 'gender_id' => 3, + 'prefix_id' => 4, + 'suffix_id' => 6, + 'api.entity_tag.create' => ['tag_id' => $tag9], + 'api.entity_tag.create.2' => ['tag_id' => $tag7], + ], ['first_name' => 'Test', 'last_name' => 'Test Contact 17', 'gender_id' => 2, 'prefix_id' => 4, 'suffix_id' => 7], ['first_name' => 'Test', 'last_name' => 'Test Contact 18', 'gender_id' => 2, 'prefix_id' => 4, 'suffix_id' => 4, 'api.entity_tag.create' => ['tag_id' => $tag9]], ['first_name' => 'Test', 'last_name' => 'Test Contact 19', 'gender_id' => 2, 'prefix_id' => 4, 'suffix_id' => 6, 'api.entity_tag.create.2' => ['tag_id' => $tag7]], - ['first_name' => 'Test', 'last_name' => 'Test Contact 20', 'gender_id' => 1, 'prefix_id' => 4, 'suffix_id' => 6, 'api.entity_tag.create' => ['tag_id' => $tag9], 'api.entity_tag.create.2' => ['tag_id' => $tag7]], + [ + 'first_name' => 'Test', + 'last_name' => 'Test Contact 20', + 'gender_id' => 1, + 'prefix_id' => 4, + 'suffix_id' => 6, + 'api.entity_tag.create' => ['tag_id' => $tag9], + 'api.entity_tag.create.2' => ['tag_id' => $tag7], + ], ['first_name' => 'Test', 'last_name' => 'Test Contact 21', 'gender_id' => 3, 'prefix_id' => 1, 'suffix_id' => 6], ['first_name' => 'Test', 'last_name' => 'Test Contact 22', 'gender_id' => 1, 'prefix_id' => 1, 'suffix_id' => 1, 'api.entity_tag.create' => ['tag_id' => $tag9]], ['first_name' => 'Test', 'last_name' => 'Test Contact 23', 'gender_id' => 3, 'prefix_id' => 1, 'suffix_id' => 1, 'api.entity_tag.create' => ['tag_id' => $tag7]], - ['first_name' => 'Test', 'last_name' => 'Test Contact 24', 'gender_id' => 3, 'prefix_id' => 3, 'suffix_id' => 2, 'api.entity_tag.create' => ['tag_id' => $tag9], 'api.entity_tag.create.2' => ['tag_id' => $tag7]], + [ + 'first_name' => 'Test', + 'last_name' => 'Test Contact 24', + 'gender_id' => 3, + 'prefix_id' => 3, + 'suffix_id' => 2, + 'api.entity_tag.create' => ['tag_id' => $tag9], + 'api.entity_tag.create.2' => ['tag_id' => $tag7], + ], ]; foreach ($individuals as $individual) { $this->ids['Contact'][$individual['last_name']] = $this->individualCreate($individual); @@ -164,25 +198,25 @@ class CRM_Contact_BAO_QueryTest extends CiviUnitTestCase { public function testSearchProfileHomeCityCRM14263() { $contactID = $this->individualCreate(); CRM_Core_Config::singleton()->defaultSearchProfileID = 1; - $this->callAPISuccess('address', 'create', array( + $this->callAPISuccess('address', 'create', [ 'contact_id' => $contactID, 'city' => 'Cool City', 'location_type_id' => 1, - )); - $params = array( - 0 => array( + ]); + $params = [ + 0 => [ 0 => 'city-1', 1 => '=', 2 => 'Cool City', 3 => 1, 4 => 0, - ), - ); - $returnProperties = array( + ], + ]; + $returnProperties = [ 'contact_type' => 1, 'contact_sub_type' => 1, 'sort_name' => 1, - ); + ]; $queryObj = new CRM_Contact_BAO_Query($params, $returnProperties); try { @@ -203,25 +237,25 @@ class CRM_Contact_BAO_QueryTest extends CiviUnitTestCase { public function testSearchProfileHomeCityNoResultsCRM14263() { $contactID = $this->individualCreate(); CRM_Core_Config::singleton()->defaultSearchProfileID = 1; - $this->callAPISuccess('address', 'create', array( + $this->callAPISuccess('address', 'create', [ 'contact_id' => $contactID, 'city' => 'Cool City', 'location_type_id' => 1, - )); - $params = array( - 0 => array( + ]); + $params = [ + 0 => [ 0 => 'city-1', 1 => '=', 2 => 'Dumb City', 3 => 1, 4 => 0, - ), - ); - $returnProperties = array( + ], + ]; + $returnProperties = [ 'contact_type' => 1, 'contact_sub_type' => 1, 'sort_name' => 1, - ); + ]; $queryObj = new CRM_Contact_BAO_Query($params, $returnProperties); try { @@ -240,34 +274,34 @@ class CRM_Contact_BAO_QueryTest extends CiviUnitTestCase { */ public function testSearchPrimaryLocTypes() { $contactID = $this->individualCreate(); - $params = array( + $params = [ 'contact_id' => $contactID, 'email' => 'primary@example.com', 'is_primary' => 1, - ); + ]; $this->callAPISuccess('email', 'create', $params); unset($params['is_primary']); $params['email'] = 'secondary@team.com'; $this->callAPISuccess('email', 'create', $params); - foreach (array(0, 1) as $searchPrimary) { + foreach ([0, 1] as $searchPrimary) { Civi::settings()->set('searchPrimaryDetailsOnly', $searchPrimary); - $params = array( - 0 => array( + $params = [ + 0 => [ 0 => 'email', 1 => 'LIKE', 2 => 'sEcondary@example.com', 3 => 0, 4 => 1, - ), - ); - $returnProperties = array( + ], + ]; + $returnProperties = [ 'contact_type' => 1, 'contact_sub_type' => 1, 'sort_name' => 1, - ); + ]; $queryObj = new CRM_Contact_BAO_Query($params, $returnProperties); $resultDAO = $queryObj->searchQuery(); @@ -283,7 +317,7 @@ class CRM_Contact_BAO_QueryTest extends CiviUnitTestCase { } // API should always return primary email. - $result = $this->callAPISuccess('Contact', 'get', array('contact_id' => $contactID)); + $result = $this->callAPISuccess('Contact', 'get', ['contact_id' => $contactID]); $this->assertEquals('primary@example.com', $result['values'][$contactID]['email']); } } @@ -340,21 +374,23 @@ class CRM_Contact_BAO_QueryTest extends CiviUnitTestCase { * @param array $params * @param string $selectClause * @param string $whereClause + * + * @throws \CRM_Core_Exception */ public function testSearchProfilePrimaryCityCRM14263($params, $selectClause, $whereClause) { $contactID = $this->individualCreate(); CRM_Core_Config::singleton()->defaultSearchProfileID = 1; - $this->callAPISuccess('address', 'create', array( + $this->callAPISuccess('address', 'create', [ 'contact_id' => $contactID, 'city' => 'Cool CITY', 'street_address' => 'Long STREET', 'location_type_id' => 1, - )); - $returnProperties = array( + ]); + $returnProperties = [ 'contact_type' => 1, 'contact_sub_type' => 1, 'sort_name' => 1, - ); + ]; $expectedSQL = "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, " . $selectClause . " FROM civicrm_contact contact_a LEFT JOIN civicrm_address ON ( contact_a.id = civicrm_address.contact_id AND civicrm_address.is_primary = 1 ) WHERE ( ( " . $whereClause . " ) ) AND (contact_a.is_deleted = 0) ORDER BY `contact_a`.`sort_name` ASC, `contact_a`.`id` "; $queryObj = new CRM_Contact_BAO_Query($params, $returnProperties); try { @@ -377,13 +413,17 @@ class CRM_Contact_BAO_QueryTest extends CiviUnitTestCase { public function getSearchProfileData() { return [ [ - [['city', '=', 'Cool City', 1, 0]], "civicrm_address.city as `city`", "civicrm_address.city = 'Cool City'", + [['city', '=', 'Cool City', 1, 0]], + "civicrm_address.city as `city`", + "civicrm_address.city = 'Cool City'", ], [ // Note that in the query 'long street' is lower cased. We eventually want to change that & not mess with the vars - it turns out // it doesn't work on some charsets. However, the the lcasing affects more vars & we are looking to stagger removal of lcasing 'in case' // (although we have been removing without blowback since 2017) - [['street_address', '=', 'Long Street', 1, 0]], "civicrm_address.street_address as `street_address`", "civicrm_address.street_address LIKE '%Long Street%'", + [['street_address', '=', 'Long Street', 1, 0]], + "civicrm_address.street_address as `street_address`", + "civicrm_address.street_address LIKE '%Long Street%'", ], ]; } @@ -395,8 +435,8 @@ class CRM_Contact_BAO_QueryTest extends CiviUnitTestCase { * not be appended. */ public function testGroupContactCacheAddSearch() { - $returnProperties = array('contact_id'); - $params = array(array('group', 'IN', array(1), 0, 0)); + $returnProperties = ['contact_id']; + $params = [['group', 'IN', [1], 0, 0]]; $query = new CRM_Contact_BAO_Query( $params, $returnProperties, @@ -418,18 +458,18 @@ class CRM_Contact_BAO_QueryTest extends CiviUnitTestCase { // Precaution as hitting some inconsistent set up running in isolation vs in the suite. CRM_Core_DAO::executeQuery('UPDATE civicrm_address SET postal_code = NULL'); - $this->individualCreate(array('api.address.create' => array('postal_code' => 5, 'location_type_id' => 'Main'))); - $this->individualCreate(array('api.address.create' => array('postal_code' => 'EH10 4RB-889', 'location_type_id' => 'Main'))); - $this->individualCreate(array('api.address.create' => array('postal_code' => '4', 'location_type_id' => 'Main'))); - $this->individualCreate(array('api.address.create' => array('postal_code' => '6', 'location_type_id' => 'Main'))); - $this->individualCreate(array('api.address.create' => array('street_address' => 'just a street', 'location_type_id' => 'Main'))); - $this->individualCreate(array('api.address.create' => array('postal_code' => '12345678444455555555555555555555555555555555551314151617181920', 'location_type_id' => 'Main'))); + $this->individualCreate(['api.address.create' => ['postal_code' => 5, 'location_type_id' => 'Main']]); + $this->individualCreate(['api.address.create' => ['postal_code' => 'EH10 4RB-889', 'location_type_id' => 'Main']]); + $this->individualCreate(['api.address.create' => ['postal_code' => '4', 'location_type_id' => 'Main']]); + $this->individualCreate(['api.address.create' => ['postal_code' => '6', 'location_type_id' => 'Main']]); + $this->individualCreate(['api.address.create' => ['street_address' => 'just a street', 'location_type_id' => 'Main']]); + $this->individualCreate(['api.address.create' => ['postal_code' => '12345678444455555555555555555555555555555555551314151617181920', 'location_type_id' => 'Main']]); - $params = array(array('postal_code_low', '=', 5, 0, 0)); + $params = [['postal_code_low', '=', 5, 0, 0]]; CRM_Contact_BAO_Query::convertFormValues($params); $query = new CRM_Contact_BAO_Query( - $params, array('contact_id'), + $params, ['contact_id'], NULL, TRUE, FALSE, 1, TRUE, TRUE, FALSE @@ -444,7 +484,7 @@ class CRM_Contact_BAO_QueryTest extends CiviUnitTestCase { /// I was unable to get mysql warnings to activate in the context of the unit tests - but // felt this code still provided a useful bit of coverage as it runs the various queries to load // the group & could generate invalid sql if a bug were introduced. - $groupParams = array('title' => 'postal codes', 'formValues' => $params, 'is_active' => 1); + $groupParams = ['title' => 'postal codes', 'formValues' => $params, 'is_active' => 1]; $group = CRM_Contact_BAO_Group::createSmartGroup($groupParams); CRM_Contact_BAO_GroupContactCache::load($group, TRUE); } @@ -453,23 +493,23 @@ class CRM_Contact_BAO_QueryTest extends CiviUnitTestCase { * Test searches are case insensitive. */ public function testCaseInsensitive() { - $orgID = $this->organizationCreate(array('organization_name' => 'BOb')); - $params = array( + $orgID = $this->organizationCreate(['organization_name' => 'BOb']); + $params = [ 'display_name' => 'Minnie Mouse', 'first_name' => 'Minnie', 'last_name' => 'Mouse', 'employer_id' => $orgID, 'contact_type' => 'Individual', 'nick_name' => 'Mins', - ); + ]; $this->callAPISuccess('Contact', 'create', $params); unset($params['contact_type']); foreach ($params as $key => $value) { if ($key == 'employer_id') { - $searchParams = array(array('current_employer', '=', 'bob', 0, 1)); + $searchParams = [['current_employer', '=', 'bob', 0, 1]]; } else { - $searchParams = array(array($key, '=', strtolower($value), 0, 1)); + $searchParams = [[$key, '=', strtolower($value), 0, 1]]; } $query = new CRM_Contact_BAO_Query($searchParams); $result = $query->apiQuery($searchParams); @@ -486,16 +526,16 @@ class CRM_Contact_BAO_QueryTest extends CiviUnitTestCase { * CRM-14720 */ public function testNonNumericEqualsPostal() { - $this->individualCreate(array('api.address.create' => array('postal_code' => 5, 'location_type_id' => 'Main'))); - $this->individualCreate(array('api.address.create' => array('postal_code' => 'EH10 4RB-889', 'location_type_id' => 'Main'))); - $this->individualCreate(array('api.address.create' => array('postal_code' => '4', 'location_type_id' => 'Main'))); - $this->individualCreate(array('api.address.create' => array('postal_code' => '6', 'location_type_id' => 'Main'))); + $this->individualCreate(['api.address.create' => ['postal_code' => 5, 'location_type_id' => 'Main']]); + $this->individualCreate(['api.address.create' => ['postal_code' => 'EH10 4RB-889', 'location_type_id' => 'Main']]); + $this->individualCreate(['api.address.create' => ['postal_code' => '4', 'location_type_id' => 'Main']]); + $this->individualCreate(['api.address.create' => ['postal_code' => '6', 'location_type_id' => 'Main']]); - $params = array(array('postal_code', '=', 'EH10 4RB-889', 0, 0)); + $params = [['postal_code', '=', 'EH10 4RB-889', 0, 0]]; CRM_Contact_BAO_Query::convertFormValues($params); $query = new CRM_Contact_BAO_Query( - $params, array('contact_id'), + $params, ['contact_id'], NULL, TRUE, FALSE, 1, TRUE, TRUE, FALSE @@ -511,42 +551,42 @@ class CRM_Contact_BAO_QueryTest extends CiviUnitTestCase { public function testNonReciprocalRelationshipTargetGroupIsCorrectResults() { $contactID_a = $this->individualCreate(); $contactID_b = $this->individualCreate(); - $this->callAPISuccess('Relationship', 'create', array( + $this->callAPISuccess('Relationship', 'create', [ 'contact_id_a' => $contactID_a, 'contact_id_b' => $contactID_b, 'relationship_type_id' => 1, 'is_active' => 1, - )); + ]); // Create a group and add contact A to it. $groupID = $this->groupCreate(); - $this->callAPISuccess('GroupContact', 'create', array('group_id' => $groupID, 'contact_id' => $contactID_a, 'status' => 'Added')); + $this->callAPISuccess('GroupContact', 'create', ['group_id' => $groupID, 'contact_id' => $contactID_a, 'status' => 'Added']); // Add another (sans-relationship) contact to the group, $contactID_c = $this->individualCreate(); - $this->callAPISuccess('GroupContact', 'create', array('group_id' => $groupID, 'contact_id' => $contactID_c, 'status' => 'Added')); + $this->callAPISuccess('GroupContact', 'create', ['group_id' => $groupID, 'contact_id' => $contactID_c, 'status' => 'Added']); - $params = array( - array( + $params = [ + [ 0 => 'relation_type_id', 1 => 'IN', 2 => - array( - 0 => '1_b_a', - ), + [ + 0 => '1_b_a', + ], 3 => 0, 4 => 0, - ), - array( + ], + [ 0 => 'relation_target_group', 1 => 'IN', 2 => - array( - 0 => $groupID, - ), + [ + 0 => $groupID, + ], 3 => 0, 4 => 0, - ), - ); + ], + ]; $query = new CRM_Contact_BAO_Query($params); $dao = $query->searchQuery(); @@ -555,45 +595,48 @@ class CRM_Contact_BAO_QueryTest extends CiviUnitTestCase { $this->assertEquals($contactID_b, $dao->contact_id, "Search query returns parent of contact A?"); } + /** + * @throws \CRM_Core_Exception + */ public function testReciprocalRelationshipTargetGroupIsCorrectResults() { $contactID_a = $this->individualCreate(); $contactID_b = $this->individualCreate(); - $this->callAPISuccess('Relationship', 'create', array( + $this->callAPISuccess('Relationship', 'create', [ 'contact_id_a' => $contactID_a, 'contact_id_b' => $contactID_b, 'relationship_type_id' => 2, 'is_active' => 1, - )); + ]); // Create a group and add contact A to it. $groupID = $this->groupCreate(); - $this->callAPISuccess('GroupContact', 'create', array('group_id' => $groupID, 'contact_id' => $contactID_a, 'status' => 'Added')); + $this->callAPISuccess('GroupContact', 'create', ['group_id' => $groupID, 'contact_id' => $contactID_a, 'status' => 'Added']); // Add another (sans-relationship) contact to the group, $contactID_c = $this->individualCreate(); - $this->callAPISuccess('GroupContact', 'create', array('group_id' => $groupID, 'contact_id' => $contactID_c, 'status' => 'Added')); + $this->callAPISuccess('GroupContact', 'create', ['group_id' => $groupID, 'contact_id' => $contactID_c, 'status' => 'Added']); - $params = array( - array( + $params = [ + [ 0 => 'relation_type_id', 1 => 'IN', 2 => - array( - 0 => '2_a_b', - ), + [ + 0 => '2_a_b', + ], 3 => 0, 4 => 0, - ), - array( + ], + [ 0 => 'relation_target_group', 1 => 'IN', 2 => - array( - 0 => $groupID, - ), + [ + 0 => $groupID, + ], 3 => 0, 4 => 0, - ), - ); + ], + ]; $query = new CRM_Contact_BAO_Query($params); $dao = $query->searchQuery(); @@ -604,28 +647,28 @@ class CRM_Contact_BAO_QueryTest extends CiviUnitTestCase { public function testReciprocalRelationshipTargetGroupUsesTempTable() { $groupID = $this->groupCreate(); - $params = array( - array( + $params = [ + [ 0 => 'relation_type_id', 1 => 'IN', 2 => - array( - 0 => '2_a_b', - ), + [ + 0 => '2_a_b', + ], 3 => 0, 4 => 0, - ), - array( + ], + [ 0 => 'relation_target_group', 1 => 'IN', 2 => - array( - 0 => $groupID, - ), + [ + 0 => $groupID, + ], 3 => 0, 4 => 0, - ), - ); + ], + ]; $sql = CRM_Contact_BAO_Query::getQuery($params); $this->assertContains('INNER JOIN civicrm_rel_temp_', $sql, "Query appears to use temporary table of compiled relationships?", TRUE); } @@ -654,9 +697,9 @@ civicrm_relationship.is_active = 1 AND ( civicrm_relationship.start_date IS NULL OR civicrm_relationship.start_date <= {$today} ) ) AND (contact_b.is_deleted = 0) AND civicrm_relationship.relationship_type_id IN (8,10) ) AND (contact_a.is_deleted = 0)"; // Test Traditional single select format - $params1 = array(array('relation_type_id', '=', '8_a_b', 0, 0)); + $params1 = [['relation_type_id', '=', '8_a_b', 0, 0]]; $query1 = new CRM_Contact_BAO_Query( - $params1, array('contact_id'), + $params1, ['contact_id'], NULL, TRUE, FALSE, 1, TRUE, TRUE, FALSE @@ -665,9 +708,9 @@ civicrm_relationship.is_active = 1 AND $this->assertLike($from1, $sql1[1]); $this->assertLike($where1, $sql1[2]); // Test single relationship type selected in multiple select. - $params2 = array(array('relation_type_id', 'IN', array('8_a_b'), 0, 0)); + $params2 = [['relation_type_id', 'IN', ['8_a_b'], 0, 0]]; $query2 = new CRM_Contact_BAO_Query( - $params2, array('contact_id'), + $params2, ['contact_id'], NULL, TRUE, FALSE, 1, TRUE, TRUE, FALSE @@ -676,9 +719,9 @@ civicrm_relationship.is_active = 1 AND $this->assertLike($from1, $sql2[1]); $this->assertLike($where1, $sql2[2]); // Test multiple relationship types selected. - $params3 = array(array('relation_type_id', 'IN', array('8_a_b', '10_a_b'), 0, 0)); + $params3 = [['relation_type_id', 'IN', ['8_a_b', '10_a_b'], 0, 0]]; $query3 = new CRM_Contact_BAO_Query( - $params3, array('contact_id'), + $params3, ['contact_id'], NULL, TRUE, FALSE, 1, TRUE, TRUE, FALSE @@ -687,9 +730,9 @@ civicrm_relationship.is_active = 1 AND $this->assertLike($from1, $sql3[1]); $this->assertLike($where2, $sql3[2]); // Test Multiple Relationship type selected where one doesn't actually exist. - $params4 = array(array('relation_type_id', 'IN', array('8_a_b', '10_a_b', '14_a_b'), 0, 0)); + $params4 = [['relation_type_id', 'IN', ['8_a_b', '10_a_b', '14_a_b'], 0, 0]]; $query4 = new CRM_Contact_BAO_Query( - $params4, array('contact_id'), + $params4, ['contact_id'], NULL, TRUE, FALSE, 1, TRUE, TRUE, FALSE @@ -699,9 +742,9 @@ civicrm_relationship.is_active = 1 AND $this->assertLike($where2, $sql4[2]); // Test Multiple b to a Relationship type . - $params5 = array(array('relation_type_id', 'IN', array('8_b_a', '10_b_a', '14_b_a'), 0, 0)); + $params5 = [['relation_type_id', 'IN', ['8_b_a', '10_b_a', '14_b_a'], 0, 0]]; $query5 = new CRM_Contact_BAO_Query( - $params5, array('contact_id'), + $params5, ['contact_id'], NULL, TRUE, FALSE, 1, TRUE, TRUE, FALSE @@ -713,6 +756,8 @@ civicrm_relationship.is_active = 1 AND /** * Test we can narrow a group get by status. + * + * @throws \CRM_Core_Exception */ public function testGetByGroupWithStatus() { $groupID = $this->groupCreate(); @@ -763,15 +808,15 @@ civicrm_relationship.is_active = 1 AND $householdID = $this->householdCreate(); $individualID = $this->individualCreate(); $groupID = $this->smartGroupCreate(); - $this->callAPISuccess('GroupContact', 'create', array('group_id' => $groupID, 'contact_id' => $individualID, 'status' => 'Added')); - $this->callAPISuccess('GroupContact', 'create', array('group_id' => $groupID, 'contact_id' => $householdID, 'status' => 'Added')); + $this->callAPISuccess('GroupContact', 'create', ['group_id' => $groupID, 'contact_id' => $individualID, 'status' => 'Added']); + $this->callAPISuccess('GroupContact', 'create', ['group_id' => $groupID, 'contact_id' => $householdID, 'status' => 'Added']); // Refresh the cache for test purposes. It would be better to alter to alter the GroupContact add function to add contacts to the cache. CRM_Contact_BAO_GroupContactCache::clearGroupContactCache($groupID); $sql = CRM_Contact_BAO_Query::getQuery( - array(array('group', 'IN', array($groupID), 0, 0)), - array('contact_id') + [['group', 'IN', [$groupID], 0, 0]], + ['contact_id'] ); $dao = CRM_Core_DAO::executeQuery($sql); @@ -779,8 +824,8 @@ civicrm_relationship.is_active = 1 AND $this->assertFalse(strstr($sql, ' OR ')); $sql = CRM_Contact_BAO_Query::getQuery( - array(array('group', 'IN', array($groupID), 0, 0)), - array('contact_id' => 1, 'group' => 1) + [['group', 'IN', [$groupID], 0, 0]], + ['contact_id' => 1, 'group' => 1] ); $dao = CRM_Core_DAO::executeQuery($sql); @@ -795,11 +840,11 @@ civicrm_relationship.is_active = 1 AND * CRM-19562 ensure that only ids are used for contact_id searching. */ public function testContactIDClause() { - $params = array( - array("mark_x_2", "=", 1, 0, 0), - array("mark_x_foo@example.com", "=", 1, 0, 0), - ); - $returnProperties = array( + $params = [ + ["mark_x_2", "=", 1, 0, 0], + ["mark_x_foo@example.com", "=", 1, 0, 0], + ]; + $returnProperties = [ "sort_name" => 1, "email" => 1, "do_not_email" => 1, @@ -807,7 +852,7 @@ civicrm_relationship.is_active = 1 AND "on_hold" => 1, "display_name" => 1, "preferred_mail_format" => 1, - ); + ]; $numberOfContacts = 2; $query = new CRM_Contact_BAO_Query($params, $returnProperties); try { @@ -949,20 +994,20 @@ civicrm_relationship.is_active = 1 AND * CRM-21816 fix relative dates in search bug */ public function testConvertFormValuesCRM21816() { - $fv = array( - // next 60 days + $fv = [ + // next 60 days "member_end_date_relative" => "starting_2.month", "member_end_date_low" => "20180101000000", "member_end_date_high" => "20180331235959", "membership_is_current_member" => "1", "member_is_primary" => "1", - ); + ]; // $fv is modified by convertFormValues() $fv_orig = $fv; $params = CRM_Contact_BAO_Query::convertFormValues($fv); // restructure for easier testing - $modparams = array(); + $modparams = []; foreach ($params as $p) { $modparams[$p[0]] = $p; } diff --git a/tests/phpunit/CRM/Contact/SelectorTest.php b/tests/phpunit/CRM/Contact/SelectorTest.php index c45ba19b56..8f35c2d845 100644 --- a/tests/phpunit/CRM/Contact/SelectorTest.php +++ b/tests/phpunit/CRM/Contact/SelectorTest.php @@ -48,9 +48,9 @@ class CRM_Contact_SelectorTest extends CiviUnitTestCase { * @throws \Exception */ public function testSelectorQuery($dataSet) { - $params = CRM_Contact_BAO_Query::convertFormValues($dataSet['form_values'], 0, FALSE, NULL, array()); + $params = CRM_Contact_BAO_Query::convertFormValues($dataSet['form_values'], 0, FALSE, NULL, []); foreach ($dataSet['settings'] as $setting) { - $this->callAPISuccess('Setting', 'create', array($setting['name'] => $setting['value'])); + $this->callAPISuccess('Setting', 'create', [$setting['name'] => $setting['value']]); } $selector = new CRM_Contact_Selector( $dataSet['class'], @@ -112,24 +112,24 @@ class CRM_Contact_SelectorTest extends CiviUnitTestCase { */ public function testPrevNextCache() { $contactID = $this->individualCreate(['email' => 'mickey@mouseville.com']); - $dataSet = array( + $dataSet = [ 'description' => 'Normal default behaviour', 'class' => 'CRM_Contact_Selector', - 'settings' => array(), - 'form_values' => array('email' => 'mickey@mouseville.com'), - 'params' => array(), + 'settings' => [], + 'form_values' => ['email' => 'mickey@mouseville.com'], + 'params' => [], 'return_properties' => NULL, 'context' => 'advanced', 'action' => CRM_Core_Action::ADVANCED, 'includeContactIds' => NULL, 'searchDescendentGroups' => FALSE, - 'expected_query' => array( + 'expected_query' => [ 0 => 'default', 1 => 'default', 2 => "WHERE ( civicrm_email.email LIKE '%mickey@mouseville.com%' ) AND (contact_a.is_deleted = 0)", - ), - ); - $params = CRM_Contact_BAO_Query::convertFormValues($dataSet['form_values'], 0, FALSE, NULL, array()); + ], + ]; + $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( @@ -172,9 +172,9 @@ class CRM_Contact_SelectorTest extends CiviUnitTestCase { * Data sets for testing. */ public function querySets() { - return array( - array( - array( + return [ + [ + [ 'description' => 'Empty group test', 'class' => 'CRM_Contact_Selector', 'settings' => [], @@ -186,130 +186,130 @@ class CRM_Contact_SelectorTest extends CiviUnitTestCase { 'includeContactIds' => NULL, 'searchDescendentGroups' => FALSE, 'expected_query' => [], - ), - ), - array( - array( + ], + ], + [ + [ 'description' => 'Normal default behaviour', 'class' => 'CRM_Contact_Selector', - 'settings' => array(), - 'form_values' => array('email' => 'mickey@mouseville.com'), - 'params' => array(), + 'settings' => [], + 'form_values' => ['email' => 'mickey@mouseville.com'], + 'params' => [], 'return_properties' => NULL, 'context' => 'advanced', 'action' => CRM_Core_Action::ADVANCED, 'includeContactIds' => NULL, 'searchDescendentGroups' => FALSE, - 'expected_query' => array( + 'expected_query' => [ 0 => 'default', 1 => 'default', 2 => "WHERE ( civicrm_email.email LIKE '%mickey@mouseville.com%' ) AND (contact_a.is_deleted = 0)", - ), - ), - ), - array( - array( + ], + ], + ], + [ + [ 'description' => 'Normal default + user added wildcard', 'class' => 'CRM_Contact_Selector', - 'settings' => array(), - 'form_values' => array('email' => '%mickey@mouseville.com', 'sort_name' => 'Mouse'), - 'params' => array(), + 'settings' => [], + 'form_values' => ['email' => '%mickey@mouseville.com', 'sort_name' => 'Mouse'], + 'params' => [], 'return_properties' => NULL, 'context' => 'advanced', 'action' => CRM_Core_Action::ADVANCED, 'includeContactIds' => NULL, 'searchDescendentGroups' => FALSE, - 'expected_query' => array( + 'expected_query' => [ 0 => 'default', 1 => 'default', 2 => "WHERE ( civicrm_email.email LIKE '%mickey@mouseville.com%' AND ( ( ( contact_a.sort_name LIKE '%Mouse%' ) OR ( civicrm_email.email LIKE '%Mouse%' ) ) ) ) AND (contact_a.is_deleted = 0)", - ), - ), - ), - array( - array( + ], + ], + ], + [ + [ 'description' => 'Site set to not pre-pend wildcard', 'class' => 'CRM_Contact_Selector', - 'settings' => array(array('name' => 'includeWildCardInName', 'value' => FALSE)), - 'form_values' => array('email' => 'mickey@mouseville.com', 'sort_name' => 'Mouse'), - 'params' => array(), + 'settings' => [['name' => 'includeWildCardInName', 'value' => FALSE]], + 'form_values' => ['email' => 'mickey@mouseville.com', 'sort_name' => 'Mouse'], + 'params' => [], 'return_properties' => NULL, 'context' => 'advanced', 'action' => CRM_Core_Action::ADVANCED, 'includeContactIds' => NULL, 'searchDescendentGroups' => FALSE, - 'expected_query' => array( + 'expected_query' => [ 0 => 'default', 1 => 'default', 2 => "WHERE ( civicrm_email.email LIKE 'mickey@mouseville.com%' AND ( ( ( contact_a.sort_name LIKE 'Mouse%' ) OR ( civicrm_email.email LIKE 'Mouse%' ) ) ) ) AND (contact_a.is_deleted = 0)", - ), - ), - ), - array( - array( + ], + ], + ], + [ + [ 'description' => 'Use of quotes for exact string', 'use_case_comments' => 'This is something that was in the code but seemingly not working. No UI info on it though!', 'class' => 'CRM_Contact_Selector', - 'settings' => array(array('name' => 'includeWildCardInName', 'value' => FALSE)), - 'form_values' => array('email' => '"mickey@mouseville.com"', 'sort_name' => 'Mouse'), - 'params' => array(), + 'settings' => [['name' => 'includeWildCardInName', 'value' => FALSE]], + 'form_values' => ['email' => '"mickey@mouseville.com"', 'sort_name' => 'Mouse'], + 'params' => [], 'return_properties' => NULL, 'context' => 'advanced', 'action' => CRM_Core_Action::ADVANCED, 'includeContactIds' => NULL, 'searchDescendentGroups' => FALSE, - 'expected_query' => array( + 'expected_query' => [ 0 => 'default', 1 => 'default', 2 => "WHERE ( civicrm_email.email = 'mickey@mouseville.com' AND ( ( ( contact_a.sort_name LIKE 'Mouse%' ) OR ( civicrm_email.email LIKE 'Mouse%' ) ) ) ) AND (contact_a.is_deleted = 0)", - ), - ), - ), - array( - array( + ], + ], + ], + [ + [ 'description' => 'Normal search builder behaviour', 'class' => 'CRM_Contact_Selector', - 'settings' => array(), - 'form_values' => array('contact_type' => 'Individual', 'country' => array('IS NOT NULL' => 1)), - 'params' => array(), - 'return_properties' => array( + 'settings' => [], + 'form_values' => ['contact_type' => 'Individual', 'country' => ['IS NOT NULL' => 1]], + 'params' => [], + 'return_properties' => [ 'contact_type' => 1, 'contact_sub_type' => 1, 'sort_name' => 1, - ), + ], 'context' => 'builder', 'action' => CRM_Core_Action::NONE, 'includeContactIds' => NULL, 'searchDescendentGroups' => FALSE, - 'expected_query' => array( + 'expected_query' => [ 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)', - ), - ), - ), - array( - array( + ], + ], + ], + [ + [ 'description' => 'Search builder behaviour for Activity', 'class' => 'CRM_Contact_Selector', - 'settings' => array(), - 'form_values' => array('source_contact_id' => array('IS NOT NULL' => 1)), - 'params' => array(), - 'return_properties' => array( + 'settings' => [], + 'form_values' => ['source_contact_id' => ['IS NOT NULL' => 1]], + 'params' => [], + 'return_properties' => [ 'source_contact_id' => 1, - ), + ], 'context' => 'builder', 'action' => CRM_Core_Action::NONE, 'includeContactIds' => NULL, 'searchDescendentGroups' => FALSE, - 'expected_query' => array( + 'expected_query' => [ 0 => 'SELECT contact_a.id as contact_id, source_contact.id as source_contact_id', 2 => 'WHERE ( source_contact.id IS NOT NULL ) AND (contact_a.is_deleted = 0)', - ), - ), - ), - array( - array( + ], + ], + ], + [ + [ 'description' => 'Test display relationships', 'class' => 'CRM_Contact_Selector', 'settings' => [], @@ -320,15 +320,15 @@ class CRM_Contact_SelectorTest extends CiviUnitTestCase { 'action' => CRM_Core_Action::NONE, 'includeContactIds' => NULL, 'searchDescendentGroups' => FALSE, - 'expected_query' => array( + 'expected_query' => [ 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`, contact_a.display_name as `display_name`, contact_a.do_not_email as `do_not_email`, contact_a.do_not_phone as `do_not_phone`, contact_a.do_not_mail as `do_not_mail`, contact_a.do_not_sms as `do_not_sms`, contact_a.do_not_trade as `do_not_trade`, contact_a.is_opt_out as `is_opt_out`, contact_a.legal_identifier as `legal_identifier`, contact_a.external_identifier as `external_identifier`, contact_a.nick_name as `nick_name`, contact_a.legal_name as `legal_name`, contact_a.image_URL as `image_URL`, contact_a.preferred_communication_method as `preferred_communication_method`, contact_a.preferred_language as `preferred_language`, contact_a.preferred_mail_format as `preferred_mail_format`, contact_a.first_name as `first_name`, contact_a.middle_name as `middle_name`, contact_a.last_name as `last_name`, contact_a.prefix_id as `prefix_id`, contact_a.suffix_id as `suffix_id`, contact_a.formal_title as `formal_title`, contact_a.communication_style_id as `communication_style_id`, contact_a.job_title as `job_title`, contact_a.gender_id as `gender_id`, contact_a.birth_date as `birth_date`, contact_a.is_deceased as `is_deceased`, contact_a.deceased_date as `deceased_date`, contact_a.household_name as `household_name`, IF ( contact_a.contact_type = \'Individual\', NULL, contact_a.organization_name ) as organization_name, contact_a.sic_code as `sic_code`, contact_a.is_deleted as `contact_is_deleted`, IF ( contact_a.contact_type = \'Individual\', contact_a.organization_name, NULL ) as current_employer, civicrm_address.id as address_id, civicrm_address.street_address as `street_address`, civicrm_address.supplemental_address_1 as `supplemental_address_1`, civicrm_address.supplemental_address_2 as `supplemental_address_2`, civicrm_address.supplemental_address_3 as `supplemental_address_3`, civicrm_address.city as `city`, civicrm_address.postal_code_suffix as `postal_code_suffix`, civicrm_address.postal_code as `postal_code`, civicrm_address.geo_code_1 as `geo_code_1`, civicrm_address.geo_code_2 as `geo_code_2`, civicrm_address.state_province_id as state_province_id, civicrm_address.country_id as country_id, civicrm_phone.id as phone_id, civicrm_phone.phone_type_id as phone_type_id, civicrm_phone.phone as `phone`, civicrm_email.id as email_id, civicrm_email.email as `email`, civicrm_email.on_hold as `on_hold`, civicrm_im.id as im_id, civicrm_im.provider_id as provider_id, civicrm_im.name as `im`, civicrm_worldregion.id as worldregion_id, civicrm_worldregion.name as `world_region`', 2 => 'WHERE displayRelType.relationship_type_id = 1 AND displayRelType.is_active = 1 AND (contact_a.is_deleted = 0)', - ), - ), - ), - ); + ], + ], + ], + ]; } /** @@ -374,7 +374,7 @@ AND (contact_a.is_deleted = 0)', 0 => 'email-' . $locationType->id, 1 => 'IS NOT NULL', 2 => NULL, - 3 => 1, + 3 => 1, 4 => 0, ], ], @@ -483,25 +483,25 @@ AND (contact_a.is_deleted = 0)', ]; //Create a test custom group and field. - $customGroup = $this->callAPISuccess('CustomGroup', 'create', array( + $customGroup = $this->callAPISuccess('CustomGroup', 'create', [ 'title' => "test custom group", 'extends' => "Individual", - )); + ]); $cgTableName = $customGroup['values'][$customGroup['id']]['table_name']; - $customField = $this->callAPISuccess('CustomField', 'create', array( + $customField = $this->callAPISuccess('CustomField', 'create', [ 'custom_group_id' => $customGroup['id'], 'label' => "test field", 'html_type' => "Text", - )); + ]); $customFieldId = $customField['id']; //Sort by the custom field created above. - $sortParams = array( - 1 => array( + $sortParams = [ + 1 => [ 'name' => 'test field', 'sort' => "custom_{$customFieldId}", - ), - ); + ], + ]; $sort = new CRM_Utils_Sort($sortParams, '1_d'); //Form a query to order by a custom field. @@ -529,10 +529,10 @@ AND (contact_a.is_deleted = 0)', public function testCustomDateField() { $contactID = $this->individualCreate(); //Create a test custom group and field. - $customGroup = $this->callAPISuccess('CustomGroup', 'create', array( + $customGroup = $this->callAPISuccess('CustomGroup', 'create', [ 'title' => "test custom group", 'extends' => "Individual", - )); + ]); $customTableName = $this->callAPISuccess('CustomGroup', 'getValue', ['id' => $customGroup['id'], 'return' => 'table_name']); $customGroupTableName = $customGroup['values'][$customGroup['id']]['table_name']; @@ -584,22 +584,22 @@ AND (contact_a.is_deleted = 0)', */ public function getDefaultSelectString() { return '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`,' - . ' contact_a.display_name as `display_name`, contact_a.do_not_email as `do_not_email`, contact_a.do_not_phone as `do_not_phone`, contact_a.do_not_mail as `do_not_mail`,' - . ' contact_a.do_not_sms as `do_not_sms`, contact_a.do_not_trade as `do_not_trade`, contact_a.is_opt_out as `is_opt_out`, contact_a.legal_identifier as `legal_identifier`,' - . ' contact_a.external_identifier as `external_identifier`, contact_a.nick_name as `nick_name`, contact_a.legal_name as `legal_name`, contact_a.image_URL as `image_URL`,' - . ' contact_a.preferred_communication_method as `preferred_communication_method`, contact_a.preferred_language as `preferred_language`,' - . ' contact_a.preferred_mail_format as `preferred_mail_format`, contact_a.first_name as `first_name`, contact_a.middle_name as `middle_name`, contact_a.last_name as `last_name`,' - . ' contact_a.prefix_id as `prefix_id`, contact_a.suffix_id as `suffix_id`, contact_a.formal_title as `formal_title`, contact_a.communication_style_id as `communication_style_id`,' - . ' contact_a.job_title as `job_title`, contact_a.gender_id as `gender_id`, contact_a.birth_date as `birth_date`, contact_a.is_deceased as `is_deceased`,' - . ' contact_a.deceased_date as `deceased_date`, contact_a.household_name as `household_name`,' - . ' IF ( contact_a.contact_type = \'Individual\', NULL, contact_a.organization_name ) as organization_name, contact_a.sic_code as `sic_code`, contact_a.is_deleted as `contact_is_deleted`,' - . ' IF ( contact_a.contact_type = \'Individual\', contact_a.organization_name, NULL ) as current_employer, civicrm_address.id as address_id,' - . ' civicrm_address.street_address as `street_address`, civicrm_address.supplemental_address_1 as `supplemental_address_1`, ' - . 'civicrm_address.supplemental_address_2 as `supplemental_address_2`, civicrm_address.supplemental_address_3 as `supplemental_address_3`, civicrm_address.city as `city`, civicrm_address.postal_code_suffix as `postal_code_suffix`, ' - . 'civicrm_address.postal_code as `postal_code`, civicrm_address.geo_code_1 as `geo_code_1`, civicrm_address.geo_code_2 as `geo_code_2`, ' - . 'civicrm_address.state_province_id as state_province_id, civicrm_address.country_id as country_id, civicrm_phone.id as phone_id, civicrm_phone.phone_type_id as phone_type_id, ' - . 'civicrm_phone.phone as `phone`, civicrm_email.id as email_id, civicrm_email.email as `email`, civicrm_email.on_hold as `on_hold`, civicrm_im.id as im_id, ' - . 'civicrm_im.provider_id as provider_id, civicrm_im.name as `im`, civicrm_worldregion.id as worldregion_id, civicrm_worldregion.name as `world_region`'; + . ' contact_a.display_name as `display_name`, contact_a.do_not_email as `do_not_email`, contact_a.do_not_phone as `do_not_phone`, contact_a.do_not_mail as `do_not_mail`,' + . ' contact_a.do_not_sms as `do_not_sms`, contact_a.do_not_trade as `do_not_trade`, contact_a.is_opt_out as `is_opt_out`, contact_a.legal_identifier as `legal_identifier`,' + . ' contact_a.external_identifier as `external_identifier`, contact_a.nick_name as `nick_name`, contact_a.legal_name as `legal_name`, contact_a.image_URL as `image_URL`,' + . ' contact_a.preferred_communication_method as `preferred_communication_method`, contact_a.preferred_language as `preferred_language`,' + . ' contact_a.preferred_mail_format as `preferred_mail_format`, contact_a.first_name as `first_name`, contact_a.middle_name as `middle_name`, contact_a.last_name as `last_name`,' + . ' contact_a.prefix_id as `prefix_id`, contact_a.suffix_id as `suffix_id`, contact_a.formal_title as `formal_title`, contact_a.communication_style_id as `communication_style_id`,' + . ' contact_a.job_title as `job_title`, contact_a.gender_id as `gender_id`, contact_a.birth_date as `birth_date`, contact_a.is_deceased as `is_deceased`,' + . ' contact_a.deceased_date as `deceased_date`, contact_a.household_name as `household_name`,' + . ' IF ( contact_a.contact_type = \'Individual\', NULL, contact_a.organization_name ) as organization_name, contact_a.sic_code as `sic_code`, contact_a.is_deleted as `contact_is_deleted`,' + . ' IF ( contact_a.contact_type = \'Individual\', contact_a.organization_name, NULL ) as current_employer, civicrm_address.id as address_id,' + . ' civicrm_address.street_address as `street_address`, civicrm_address.supplemental_address_1 as `supplemental_address_1`, ' + . 'civicrm_address.supplemental_address_2 as `supplemental_address_2`, civicrm_address.supplemental_address_3 as `supplemental_address_3`, civicrm_address.city as `city`, civicrm_address.postal_code_suffix as `postal_code_suffix`, ' + . 'civicrm_address.postal_code as `postal_code`, civicrm_address.geo_code_1 as `geo_code_1`, civicrm_address.geo_code_2 as `geo_code_2`, ' + . 'civicrm_address.state_province_id as state_province_id, civicrm_address.country_id as country_id, civicrm_phone.id as phone_id, civicrm_phone.phone_type_id as phone_type_id, ' + . 'civicrm_phone.phone as `phone`, civicrm_email.id as email_id, civicrm_email.email as `email`, civicrm_email.on_hold as `on_hold`, civicrm_im.id as im_id, ' + . 'civicrm_im.provider_id as provider_id, civicrm_im.name as `im`, civicrm_worldregion.id as worldregion_id, civicrm_worldregion.name as `world_region`'; } /** @@ -607,17 +607,18 @@ AND (contact_a.is_deleted = 0)', */ public function getDefaultFromString() { return ' FROM civicrm_contact contact_a LEFT JOIN civicrm_address ON ( contact_a.id = civicrm_address.contact_id AND civicrm_address.is_primary = 1 )' - . ' LEFT JOIN civicrm_country ON ( civicrm_address.country_id = civicrm_country.id ) ' - . ' LEFT JOIN civicrm_email ON (contact_a.id = civicrm_email.contact_id AND civicrm_email.is_primary = 1)' - . ' LEFT JOIN civicrm_phone ON (contact_a.id = civicrm_phone.contact_id AND civicrm_phone.is_primary = 1)' - . ' LEFT JOIN civicrm_im ON (contact_a.id = civicrm_im.contact_id AND civicrm_im.is_primary = 1) ' - . 'LEFT JOIN civicrm_worldregion ON civicrm_country.region_id = civicrm_worldregion.id '; + . ' LEFT JOIN civicrm_country ON ( civicrm_address.country_id = civicrm_country.id ) ' + . ' LEFT JOIN civicrm_email ON (contact_a.id = civicrm_email.contact_id AND civicrm_email.is_primary = 1)' + . ' LEFT JOIN civicrm_phone ON (contact_a.id = civicrm_phone.contact_id AND civicrm_phone.is_primary = 1)' + . ' LEFT JOIN civicrm_im ON (contact_a.id = civicrm_im.contact_id AND civicrm_im.is_primary = 1) ' + . 'LEFT JOIN civicrm_worldregion ON civicrm_country.region_id = civicrm_worldregion.id '; } /** * Strangle strings into a more matchable format. * * @param string $string + * * @return string */ public function strWrangle($string) { -- 2.25.1