*
* @access protected
*/
- protected function tearDown() {}
+ protected function tearDown() {
+ $this->quickCleanup(array('civicrm_mapping_field', 'civicrm_mapping', 'civicrm_group', 'civicrm_saved_search'));
+ }
/**
* test case for add( )
$checkParams
);
}
+
+ /**
+ * Load all sql data sets & return an array of saved searches
+ * @return array
+ */
+ function dataProviderSavedSearch() {
+
+ $this->loadSavedSearches();
+ $results = CRM_Core_DAO::singleValueQuery('SELECT GROUP_CONCAT(id) FROM civicrm_group WHERE saved_search_id IS NOT NULL');
+ return array(explode(',', $results));
+ }
+
+ /**
+ * Load saved search sql files into the DB
+ */
+ function loadSavedSearches() {
+ $dsn = CRM_Core_Config::singleton()->dsn;
+ foreach (glob(dirname(__FILE__) . "/SavedSearchDataSets/*.sql") as $file) {
+ CRM_Utils_File::sourceSQLFile($dsn, $file);
+ }
+ }
+
+ /**
+ * Check we can load smart groups based on config from 'real DBs' without fatal errors - note that we are only testing lack of errors at this stage
+ * @todo - for some reason the data was getting truncated from the group table using dataprovider - would be preferable to get that working
+ * //@notdataProvider dataProviderSavedSearch
+ * //@notparam integer $groupID
+ *
+ * To add to this dataset do
+ *
+ * SET @groupID = x;
+ * SELECT mapping_id FROM civicrm_group g LEFT JOIN civicrm_saved_search s ON saved_search_id = s.id WHERE g.id = @groupID INTO @mappingID;
+
+ * SELECT * FROM civicrm_mapping WHERE id = @mappingID;
+ * SELECT * FROM civicrm_mapping_field WHERE mapping_id = @mappingID;
+ * SELECT * FROM civicrm_saved_search WHERE mapping_id = @mappingID;
+ * SELECT g.* FROM civicrm_saved_search s LEFT JOIN civicrm_group g ON g.saved_search_id = s.id WHERE mapping_id = @mappingID;
+ *
+ * Copy the output to a single xml file and place in the SavedSearchDataSets folder - use the group number as the prefix.
+ * Try to keep as much of the real world irregular glory as you can! Don't change the table ids to be number 1 as this can hide errors
+ */
+ function testGroupData() {
+ $groups = $this->dataProviderSavedSearch();
+ foreach ($groups[0] as $groupID) {
+ $group = new CRM_Contact_BAO_Group();
+ $group->id = $groupID;
+ $group->find(TRUE);
+ CRM_Contact_BAO_GroupContactCache::load($group, TRUE);
+ }
+ }
}
}
}
+ /**
+ * CRM-14263 search builder failure with search profile & address in criteria
+ * We are retrieving primary here - checking the actual sql seems super prescriptive - but since the massive query object has
+ * so few tests detecting any change seems good here :-)
+ */
+ function testSearchProfilePrimaryCityCRM14263()
+ {
+ $contactID = $this->individualCreate();
+ CRM_Core_Config::singleton()->defaultSearchProfileID = 1;
+ $this->callAPISuccess('address', 'create', array('contact_id' => $contactID, 'city' => 'Cool City', 'location_type_id' => 1,));
+ $params = array(
+ 0 => array(
+ 0 => 'city',
+ 1 => '=',
+ 2 => 'Cool City',
+ 3 => 1,
+ 4 => 0,
+ )
+ );
+ $returnProperties = array(
+ '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, civicrm_address.city as `city` FROM civicrm_contact contact_a LEFT JOIN civicrm_address ON ( contact_a.id = civicrm_address.contact_id AND civicrm_address.is_primary = 1 ) WHERE ( ( LOWER(civicrm_address.city) = 'cool city' ) ) 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 {
+ $this->assertEquals($expectedSQL ,$queryObj->searchQuery(0, 0, NULL,
+ FALSE, FALSE,
+ FALSE, FALSE,
+ TRUE));
+ }
+ catch (PEAR_Exception $e) {
+ $err = $e->getCause();
+ $this->fail('invalid SQL created' . $e->getMessage() . " " . $err->userinfo);
+
+ }
+ }
}
--- /dev/null
+INSERT IGNORE INTO `civicrm_mapping` (`id`, `name`, `description`, `mapping_type_id`) VALUES (315, NULL, NULL, NULL);
+
+INSERT IGNORE INTO `civicrm_mapping_field` (`id`, `mapping_id`, `name`, `contact_type`, `column_number`, `location_type_id`, `phone_type_id`, `im_provider_id`, `relationship_type_id`, `relationship_direction`, `grouping`, `operator`, `value`, `website_type_id`) VALUES (7455, 315, 'email', 'Individual', 0, 5, NULL, NULL, NULL, NULL, 1, 'IS NOT EMPTY', '', NULL);
+INSERT IGNORE INTO `civicrm_mapping_field` (`id`, `mapping_id`, `name`, `contact_type`, `column_number`, `location_type_id`, `phone_type_id`, `im_provider_id`, `relationship_type_id`, `relationship_direction`, `grouping`, `operator`, `value`, `website_type_id`) VALUES (7456, 315, 'do_not_email', 'Individual', 1, NULL, NULL, NULL, NULL, NULL, 1, '=', '0', NULL);
+INSERT IGNORE INTO `civicrm_mapping_field` (`id`, `mapping_id`, `name`, `contact_type`, `column_number`, `location_type_id`, `phone_type_id`, `im_provider_id`, `relationship_type_id`, `relationship_direction`, `grouping`, `operator`, `value`, `website_type_id`) VALUES (7457, 315, 'state_province', 'Individual', 2, 5, NULL, NULL, NULL, NULL, 1, '=', 'Idaho', NULL);
+INSERT IGNORE INTO `civicrm_mapping_field` (`id`, `mapping_id`, `name`, `contact_type`, `column_number`, `location_type_id`, `phone_type_id`, `im_provider_id`, `relationship_type_id`, `relationship_direction`, `grouping`, `operator`, `value`, `website_type_id`) VALUES (7458, 315, 'is_opt_out', 'Individual', 3, NULL, NULL, NULL, NULL, NULL, 1, '=', '0', NULL);
+INSERT IGNORE INTO `civicrm_mapping_field` (`id`, `mapping_id`, `name`, `contact_type`, `column_number`, `location_type_id`, `phone_type_id`, `im_provider_id`, `relationship_type_id`, `relationship_direction`, `grouping`, `operator`, `value`, `website_type_id`) VALUES (7459, 315, 'on_hold', 'Individual', 4, 5, NULL, NULL, NULL, NULL, 1, '=', '0', NULL);
+
+
+INSERT IGNORE INTO `civicrm_saved_search` (`id`, `form_values`, `mapping_id`, `search_custom_id`, `where_clause`, `select_tables`, `where_tables`) VALUES (286, 'a:8:{s:5:"qfKey";s:37:"92bf8874b4cd856436833fba5526a10f_9684";s:6:"mapper";a:2:{i:1;a:5:{i:0;a:3:{i:0;s:10:"Individual";i:1;s:5:"email";i:2;s:1:"5";}i:1;a:2:{i:0;s:10:"Individual";i:1;s:12:"do_not_email";}i:2;a:3:{i:0;s:10:"Individual";i:1;s:14:"state_province";i:2;s:1:"5";}i:3;a:2:{i:0;s:10:"Individual";i:1;s:10:"is_opt_out";}i:4;a:3:{i:0;s:10:"Individual";i:1;s:7:"on_hold";i:2;s:1:"5";}}i:2;a:1:{i:0;a:1:{i:0;s:0:"";}}}s:8:"operator";a:2:{i:1;a:5:{i:0;s:11:"IS NOT NULL";i:1;s:1:"=";i:2;s:1:"=";i:3;s:1:"=";i:4;s:1:"=";}i:2;a:1:{i:0;s:0:"";}}s:5:"value";a:2:{i:1;a:5:{i:0;s:0:"";i:1;s:1:"0";i:2;s:5:"Idaho";i:3;s:1:"0";i:4;s:1:"0";}i:2;a:1:{i:0;s:0:"";}}s:4:"task";s:2:"13";s:8:"radio_ts";s:6:"ts_all";s:11:"uf_group_id";s:0:"";s:14:"component_mode";i:1;}', 315, NULL, ' ( ( ( civicrm_email.email IS NOT NULL ) AND contact_a.do_not_email = 0 AND civicrm_state_province.name IN (\'Idaho\') AND contact_a.is_opt_out = 0 AND LOWER(civicrm_email.on_hold) = \'0\' AND contact_a.contact_type IN (\'Individual\') ) ) ', 'a:11:{s:15:"civicrm_contact";i:1;s:15:"civicrm_address";i:1;s:22:"civicrm_state_province";i:1;s:15:"civicrm_country";i:1;s:13:"civicrm_email";i:1;s:13:"civicrm_phone";i:1;s:10:"civicrm_im";i:1;s:19:"civicrm_worldregion";i:1;s:6:"gender";i:1;s:17:"individual_prefix";i:1;s:17:"individual_suffix";i:1;}', 'a:4:{s:15:"civicrm_contact";i:1;s:15:"civicrm_address";i:1;s:22:"civicrm_state_province";i:1;s:13:"civicrm_email";i:1;}');
+
+INSERT IGNORE INTO `civicrm_group` (`id`, `name`, `title`, `description`, `source`, `saved_search_id`, `is_active`, `visibility`, `where_clause`, `select_tables`, `where_tables`, `group_type`, `cache_date`, `refresh_date`, `parents`, `children`, `is_hidden`, `is_reserved`, `created_id`) VALUES (801, 'Idaho EmailContacts', 'Idaho Email Contacts', NULL, NULL, 286, 1, 'User and User Admin Only', ' ( `civicrm_group_contact_cache_801`.group_id = 801 ) ', 'a:12:{s:15:"civicrm_contact";i:1;s:15:"civicrm_address";i:1;s:22:"civicrm_state_province";i:1;s:15:"civicrm_country";i:1;s:13:"civicrm_email";i:1;s:13:"civicrm_phone";i:1;s:10:"civicrm_im";i:1;s:19:"civicrm_worldregion";i:1;s:33:"`civicrm_group_contact_cache_801`";s:136:" LEFT JOIN civicrm_group_contact_cache `civicrm_group_contact_cache_801` ON contact_a.id = `civicrm_group_contact_cache_801`.contact_id ";s:6:"gender";i:1;s:17:"individual_prefix";i:1;s:17:"individual_suffix";i:1;}', 'a:2:{s:15:"civicrm_contact";i:1;s:33:"`civicrm_group_contact_cache_801`";s:136:" LEFT JOIN civicrm_group_contact_cache `civicrm_group_contact_cache_801` ON contact_a.id = `civicrm_group_contact_cache_801`.contact_id ";}', '\ 12\ 1', '2014-06-26 03:31:03', NULL, NULL, NULL, 0, 0, NULL);
+