0abbe0b1bc797a150b92839e0bdfe5aec816bd9c
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * Include parent class definition
17 * Test contact custom search functions
22 class CRM_Contact_SelectorTest
extends CiviUnitTestCase
{
25 * Test the query from the selector class is consistent with the dataset expectation.
27 * @param array $dataSet
28 * The data set to be tested. Note that when adding new datasets often only form_values and expected where
29 * clause will need changing.
31 * @dataProvider querySets
34 public function testSelectorQuery($dataSet) {
35 $params = CRM_Contact_BAO_Query
::convertFormValues($dataSet['form_values'], 0, FALSE, NULL, []);
36 foreach ($dataSet['settings'] as $setting) {
37 $this->callAPISuccess('Setting', 'create', [$setting['name'] => $setting['value']]);
39 $selector = new CRM_Contact_Selector(
41 $dataSet['form_values'],
43 $dataSet['return_properties'],
45 $dataSet['includeContactIds'],
46 $dataSet['searchDescendentGroups'],
49 $queryObject = $selector->getQueryObject();
50 // Make sure there is no fail on alphabet query.
51 $selector->alphabetQuery()->fetchAll();
52 $sql = $queryObject->query();
53 $this->wrangleDefaultClauses($dataSet['expected_query']);
54 foreach ($dataSet['expected_query'] as $index => $queryString) {
55 $this->assertLike($this->strWrangle($queryString), $this->strWrangle($sql[$index]));
57 // Ensure that search builder return individual contact as per criteria
58 if ($dataSet['context'] == 'builder') {
59 $contactID = $this->individualCreate(['first_name' => 'James', 'last_name' => 'Bond']);
60 if ('Search builder behaviour for Activity' == $dataSet['description']) {
61 $this->callAPISuccess('Activity', 'create', [
62 'activity_type_id' => 'Meeting',
64 'source_contact_id' => $contactID,
66 $rows = CRM_Core_DAO
::executeQuery(implode(' ', $sql))->fetchAll();
67 $this->assertEquals(1, count($rows));
68 $this->assertEquals($contactID, $rows[0]['source_contact_id']);
71 $this->callAPISuccess('Address', 'create', [
72 'contact_id' => $contactID,
73 'location_type_id' => "Home",
77 $rows = $selector->getRows(CRM_Core_Action
::VIEW
, 0, 50, '');
78 $this->assertEquals(1, count($rows));
80 CRM_Core_DAO
::reenableFullGroupByMode();
81 $rows = $selector->getRows(CRM_Core_Action
::VIEW
, 0, 50, '');
83 $sortChar = $selector->alphabetQuery()->fetchAll();
84 // sort name is stored in '<last_name>, <first_name>' format, as per which the first character would be B of Bond
85 $this->assertEquals('B', $sortChar[0]['sort_name']);
86 $this->assertEquals($contactID, key($rows));
88 CRM_Core_DAO
::reenableFullGroupByMode();
89 $selector->getQueryObject()->getCachedContacts([$contactID], FALSE);
95 * Test the civicrm_prevnext_cache entry if it correctly stores the search query result
97 public function testPrevNextCache() {
98 $contactID = $this->individualCreate(['email' => 'mickey@mouseville.com']);
100 'description' => 'Normal default behaviour',
101 'class' => 'CRM_Contact_Selector',
103 'form_values' => ['email' => 'mickey@mouseville.com'],
105 'return_properties' => NULL,
106 'context' => 'advanced',
107 'action' => CRM_Core_Action
::ADVANCED
,
108 'includeContactIds' => NULL,
109 'searchDescendentGroups' => FALSE,
110 'expected_query' => [
113 2 => "WHERE ( civicrm_email.email LIKE '%mickey@mouseville.com%' ) AND (contact_a.is_deleted = 0)",
116 $params = CRM_Contact_BAO_Query
::convertFormValues($dataSet['form_values'], 0, FALSE, NULL, []);
118 // create CRM_Contact_Selector instance and set desired query params
119 $selector = new CRM_Contact_Selector(
121 $dataSet['form_values'],
123 $dataSet['return_properties'],
125 $dataSet['includeContactIds'],
126 $dataSet['searchDescendentGroups'],
130 $key = substr(sha1(rand()), 0, 7);
131 $selector->setKey($key);
133 // fetch row and check the result
134 $rows = $selector->getRows(CRM_Core_Action
::VIEW
, 0, 1, NULL);
135 $this->assertEquals(1, count($rows));
136 $this->assertEquals($contactID, key($rows));
138 // build cache key and use to it to fetch prev-next cache record
139 $cacheKey = 'civicrm search ' . $key;
140 $contacts = CRM_Utils_SQL_Select
::from('civicrm_prevnext_cache')
141 ->select(['entity_id1', 'cachekey'])
142 ->where("cachekey = @key")
143 ->param('key', $cacheKey)
146 $this->assertEquals(1, count($contacts));
147 // check the prevNext record matches
149 'entity_id1' => $contactID,
150 'cachekey' => $cacheKey,
152 $this->checkArrayEquals($contacts[0], $expectedEntry);
156 * Data sets for testing.
158 public function querySets() {
162 'description' => 'Empty group test',
163 'class' => 'CRM_Contact_Selector',
165 'form_values' => [['contact_type', '=', 'Individual', 1, 0], ['group', 'IS NULL', '', 1, 0]],
167 'return_properties' => NULL,
168 'context' => 'builder',
169 'action' => CRM_Core_Action
::NONE
,
170 'includeContactIds' => NULL,
171 'searchDescendentGroups' => FALSE,
172 'expected_query' => [],
177 'description' => 'Normal default behaviour',
178 'class' => 'CRM_Contact_Selector',
180 'form_values' => ['email' => 'mickey@mouseville.com'],
182 'return_properties' => NULL,
183 'context' => 'advanced',
184 'action' => CRM_Core_Action
::ADVANCED
,
185 'includeContactIds' => NULL,
186 'searchDescendentGroups' => FALSE,
187 'expected_query' => [
190 2 => "WHERE ( civicrm_email.email LIKE '%mickey@mouseville.com%' ) AND (contact_a.is_deleted = 0)",
196 'description' => 'Normal default + user added wildcard',
197 'class' => 'CRM_Contact_Selector',
199 'form_values' => ['email' => '%mickey@mouseville.com', 'sort_name' => 'Mouse'],
201 'return_properties' => NULL,
202 'context' => 'advanced',
203 'action' => CRM_Core_Action
::ADVANCED
,
204 'includeContactIds' => NULL,
205 'searchDescendentGroups' => FALSE,
206 'expected_query' => [
209 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)",
215 'description' => 'Site set to not pre-pend wildcard',
216 'class' => 'CRM_Contact_Selector',
217 'settings' => [['name' => 'includeWildCardInName', 'value' => FALSE]],
218 'form_values' => ['email' => 'mickey@mouseville.com', 'sort_name' => 'Mouse'],
220 'return_properties' => NULL,
221 'context' => 'advanced',
222 'action' => CRM_Core_Action
::ADVANCED
,
223 'includeContactIds' => NULL,
224 'searchDescendentGroups' => FALSE,
225 'expected_query' => [
228 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)",
234 'description' => 'Use of quotes for exact string',
235 'use_case_comments' => 'This is something that was in the code but seemingly not working. No UI info on it though!',
236 'class' => 'CRM_Contact_Selector',
237 'settings' => [['name' => 'includeWildCardInName', 'value' => FALSE]],
238 'form_values' => ['email' => '"mickey@mouseville.com"', 'sort_name' => 'Mouse'],
240 'return_properties' => NULL,
241 'context' => 'advanced',
242 'action' => CRM_Core_Action
::ADVANCED
,
243 'includeContactIds' => NULL,
244 'searchDescendentGroups' => FALSE,
245 'expected_query' => [
248 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)",
254 'description' => 'Normal search builder behaviour',
255 'class' => 'CRM_Contact_Selector',
257 'form_values' => ['contact_type' => 'Individual', 'country' => ['IS NOT NULL' => 1]],
259 'return_properties' => [
261 'contact_sub_type' => 1,
264 'context' => 'builder',
265 'action' => CRM_Core_Action
::NONE
,
266 'includeContactIds' => NULL,
267 'searchDescendentGroups' => FALSE,
268 'expected_query' => [
269 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',
270 1 => ' FROM civicrm_contact contact_a LEFT JOIN civicrm_address ON ( contact_a.id = civicrm_address.contact_id AND civicrm_address.is_primary = 1 )',
271 2 => 'WHERE ( contact_a.contact_type IN ("Individual") AND civicrm_address.country_id IS NOT NULL ) AND (contact_a.is_deleted = 0)',
277 'description' => 'Search builder behaviour for Activity',
278 'class' => 'CRM_Contact_Selector',
280 'form_values' => ['source_contact_id' => ['IS NOT NULL' => 1]],
282 'return_properties' => [
283 'source_contact_id' => 1,
285 'context' => 'builder',
286 'action' => CRM_Core_Action
::NONE
,
287 'includeContactIds' => NULL,
288 'searchDescendentGroups' => FALSE,
289 'expected_query' => [
290 0 => 'SELECT contact_a.id as contact_id, source_contact.id as source_contact_id',
291 2 => 'WHERE ( source_contact.id IS NOT NULL ) AND (contact_a.is_deleted = 0)',
297 'description' => 'Test display relationships',
298 'class' => 'CRM_Contact_Selector',
300 'form_values' => ['display_relationship_type' => '1_b_a'],
301 'return_properties' => NULL,
303 'context' => 'advanced',
304 'action' => CRM_Core_Action
::NONE
,
305 'includeContactIds' => NULL,
306 'searchDescendentGroups' => FALSE,
307 'expected_query' => [
308 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`',
309 2 => 'WHERE displayRelType.relationship_type_id = 1
310 AND displayRelType.is_active = 1
311 AND (contact_a.is_deleted = 0)',
319 * Test the contact ID query does not fail on country search.
321 public function testContactIDQuery() {
332 $searchOBJ = new CRM_Contact_Selector(NULL);
333 $searchOBJ->contactIDQuery($params, '1_u');
337 * Test the Search Builder using Non ASCII location type for email filter
339 public function testSelectorQueryOnNonASCIIlocationType() {
340 $contactID = $this->individualCreate();
341 $locationType = $this->locationTypeCreate([
342 'name' => 'Non ASCII Location Type',
343 'display_name' => 'Дом Location type',
344 'vcard_name' => 'Non ASCII Location Type',
347 $this->callAPISuccess('Email', 'create', [
348 'contact_id' => $contactID,
349 'location_type_id' => $locationType->id
,
350 'email' => 'test@test.com',
353 $selector = new CRM_Contact_Selector(
354 'CRM_Contact_Selector',
355 ['email' => ['IS NOT NULL' => 1]],
358 0 => 'email-' . $locationType->id
,
367 'contact_sub_type' => 1,
370 'Non ASCII Location Type' => [
371 'location_type' => $locationType->id
,
376 CRM_Core_Action
::NONE
,
382 $sql = $selector->getQueryObject()->query();
385 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`, `Non_ASCII_Location_Type-location_type`.id as `Non_ASCII_Location_Type-location_type_id`, `Non_ASCII_Location_Type-location_type`.name as `Non_ASCII_Location_Type-location_type`, `Non_ASCII_Location_Type-email`.id as `Non_ASCII_Location_Type-email_id`, `Non_ASCII_Location_Type-email`.email as `Non_ASCII_Location_Type-email`",
386 // @TODO these FROM clause doesn't matches due to extra spaces or special character
387 2 => "WHERE ( ( `Non_ASCII_Location_Type-email`.email IS NOT NULL ) ) AND (contact_a.is_deleted = 0)",
389 foreach ($expectedQuery as $index => $queryString) {
390 $this->assertEquals($this->strWrangle($queryString), $this->strWrangle($sql[$index]));
393 $rows = $selector->getRows(CRM_Core_Action
::VIEW
, 0, 1, NULL);
394 $this->assertEquals(1, count($rows));
395 $this->assertEquals($contactID, key($rows));
396 $this->assertEquals('test@test.com', $rows[$contactID]['Non_ASCII_Location_Type-email']);
400 * Test the value use in where clause if it's case sensitive or not against each MySQL operators
402 public function testWhereClauseByOperator() {
403 $contactID = $this->individualCreate(['first_name' => 'Adam']);
409 'RLIKE' => '^A[a-z]{3}$',
410 'IN' => ['IN' => ['Adam']],
412 $filtersByWhereClause = [
414 'IS NOT NULL' => '( contact_a.first_name IS NOT NULL )',
415 // case sensitive check
416 '=' => "( contact_a.first_name = 'Adam' )",
417 // case insensitive check
418 'LIKE' => "( contact_a.first_name LIKE '%Ad%' )",
419 // case sensitive check
420 'RLIKE' => "( contact_a.first_name RLIKE BINARY '^A[a-z]{3}$' )",
421 // case sensitive check
422 'IN' => '( contact_a.first_name IN ("Adam") )',
424 foreach ($filters as $op => $filter) {
425 $selector = new CRM_Contact_Selector(
426 'CRM_Contact_Selector',
427 ['first_name' => [$op => $filter]],
438 CRM_Core_Action
::NONE
,
444 $sql = $selector->getQueryObject()->query();
445 $this->assertEquals(TRUE, strpos($sql[2], $filtersByWhereClause[$op]));
447 $rows = $selector->getRows(CRM_Core_Action
::VIEW
, 0, 1, NULL);
448 $this->assertEquals(1, count($rows));
449 $this->assertEquals($contactID, key($rows));
454 * Test if custom table is added in from clause when
455 * search results are ordered by a custom field.
457 public function testSelectorQueryOrderByCustomField() {
458 //Search for any params.
469 //Create a test custom group and field.
470 $customGroup = $this->callAPISuccess('CustomGroup', 'create', [
471 'title' => "test custom group",
472 'extends' => "Individual",
474 $cgTableName = $customGroup['values'][$customGroup['id']]['table_name'];
475 $customField = $this->callAPISuccess('CustomField', 'create', [
476 'custom_group_id' => $customGroup['id'],
477 'label' => "test field",
478 'html_type' => "Text",
480 $customFieldId = $customField['id'];
482 //Sort by the custom field created above.
485 'name' => 'test field',
486 'sort' => "custom_{$customFieldId}",
489 $sort = new CRM_Utils_Sort($sortParams, '1_d');
491 //Form a query to order by a custom field.
492 $query = new CRM_Contact_BAO_Query($params,
493 CRM_Contact_BAO_Query
::NO_RETURN_PROPERTIES
,
494 NULL, FALSE, FALSE, 1,
495 FALSE, TRUE, TRUE, NULL,
498 $query->searchQuery(0, 0, $sort,
502 //Check if custom table is included in $query->_tables.
503 $this->assertTrue(in_array($cgTableName, array_keys($query->_tables
)));
504 //Assert if from clause joins the custom table.
505 $this->assertTrue(strpos($query->_fromClause
, $cgTableName) !== FALSE);
506 $this->callAPISuccess('CustomField', 'delete', ['id' => $customField['id']]);
507 $this->callAPISuccess('CustomGroup', 'delete', ['id' => $customGroup['id']]);
511 * Check where clause of a date custom field when 'IS NOT EMPTY' operator is used
513 public function testCustomDateField() {
514 $contactID = $this->individualCreate();
515 //Create a test custom group and field.
516 $customGroup = $this->callAPISuccess('CustomGroup', 'create', [
517 'title' => "test custom group",
518 'extends' => "Individual",
520 $customTableName = $this->callAPISuccess('CustomGroup', 'getValue', ['id' => $customGroup['id'], 'return' => 'table_name']);
521 $customGroupTableName = $customGroup['values'][$customGroup['id']]['table_name'];
523 $createdField = $this->callAPISuccess('customField', 'create', [
524 'data_type' => 'Date',
525 'html_type' => 'Select Date',
526 'date_format' => 'd M yy',
528 'label' => 'test field',
529 'custom_group_id' => $customGroup['id'],
531 $customFieldColumnName = $createdField['values'][$createdField['id']]['column_name'];
533 $this->callAPISuccess('Contact', 'create', [
535 'custom_' . $createdField['id'] => date('YmdHis'),
538 $selector = new CRM_Contact_Selector(
539 'CRM_Contact_Selector',
540 ['custom_' . $createdField['id'] => ['IS NOT EMPTY' => 1]],
543 0 => 'custom_' . $createdField['id'],
551 CRM_Core_Action
::NONE
,
557 $whereClause = $selector->getQueryObject()->query()[2];
558 $expectedClause = sprintf("( %s.%s IS NOT NULL )", $customGroupTableName, $customFieldColumnName);
559 // test the presence of expected date clause
560 $this->assertEquals(TRUE, strpos($whereClause, $expectedClause));
562 $rows = $selector->getRows(CRM_Core_Action
::VIEW
, 0, 1, NULL);
563 $this->assertEquals(1, count($rows));
567 * Get the default select string since this is generally consistent.
569 public function getDefaultSelectString() {
570 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`,'
571 . ' 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`,'
572 . ' 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`,'
573 . ' 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`,'
574 . ' contact_a.preferred_communication_method as `preferred_communication_method`, contact_a.preferred_language as `preferred_language`,'
575 . ' 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`,'
576 . ' 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`,'
577 . ' 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`,'
578 . ' contact_a.deceased_date as `deceased_date`, contact_a.household_name as `household_name`,'
579 . ' 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`,'
580 . ' IF ( contact_a.contact_type = \'Individual\', contact_a.organization_name, NULL ) as current_employer, civicrm_address.id as address_id,'
581 . ' civicrm_address.street_address as `street_address`, civicrm_address.supplemental_address_1 as `supplemental_address_1`, '
582 . '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`, '
583 . '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`, '
584 . '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, '
585 . '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, '
586 . 'civicrm_im.provider_id as provider_id, civicrm_im.name as `im`, civicrm_worldregion.id as worldregion_id, civicrm_worldregion.name as `world_region`';
590 * Get the default from string since this is generally consistent.
592 public function getDefaultFromString() {
593 return ' FROM civicrm_contact contact_a LEFT JOIN civicrm_address ON ( contact_a.id = civicrm_address.contact_id AND civicrm_address.is_primary = 1 )'
594 . ' LEFT JOIN civicrm_country ON ( civicrm_address.country_id = civicrm_country.id ) '
595 . ' LEFT JOIN civicrm_email ON (contact_a.id = civicrm_email.contact_id AND civicrm_email.is_primary = 1)'
596 . ' LEFT JOIN civicrm_phone ON (contact_a.id = civicrm_phone.contact_id AND civicrm_phone.is_primary = 1)'
597 . ' LEFT JOIN civicrm_im ON (contact_a.id = civicrm_im.contact_id AND civicrm_im.is_primary = 1) '
598 . 'LEFT JOIN civicrm_worldregion ON civicrm_country.region_id = civicrm_worldregion.id ';
602 * Strangle strings into a more matchable format.
604 * @param string $string
608 public function strWrangle($string) {
609 return trim(str_replace(' ', ' ', $string));
613 * Swap out default parts of the query for the actual string.
615 * Note that it seems to make more sense to resolve this earlier & pass it in from a clean code point of
616 * view, but the output on fail includes long sql statements that are of low relevance then.
618 * @param array $expectedQuery
620 public function wrangleDefaultClauses(&$expectedQuery) {
621 if (CRM_Utils_Array
::value(0, $expectedQuery) == 'default') {
622 $expectedQuery[0] = $this->getDefaultSelectString();
624 if (CRM_Utils_Array
::value(1, $expectedQuery) == 'default') {
625 $expectedQuery[1] = $this->getDefaultFromString();