* @return CRM_Contact_BAO_Group|NULL
* The new group BAO (if created)
*/
- public static function &create(&$params) {
+ public static function create(&$params) {
if (!empty($params['id'])) {
CRM_Utils_Hook::pre('edit', 'Group', $params['id'], $params);
}
/**
- * Where / qill clause for groups
+ * Where / qill clause for groups.
*
* @param $values
*/
- public function group(&$values) {
+ public function group($values) {
list($name, $op, $value, $grouping, $wildcard) = $values;
// If the $value is in OK (operator as key) array format we need to extract the key as operator and value first
}
$groupIds = NULL;
- $names = array();
+
$isSmart = FALSE;
$isNotOp = ($op == 'NOT IN' || $op == '!=');
*/
public function testContactSearchByParentGroup() {
// create a parent group
- // TODO: This is not an API test!!
$groupParams1 = array(
'title' => 'Parent Group',
'description' => 'Parent Group',
'parents' => '',
'is_active' => 1,
);
- $parentGroup = CRM_Contact_BAO_Group::create($groupParams1);
+ $parentGroup = $this->callAPISuccess('Group', 'create', $groupParams1);
// create a child group
$groupParams2 = array(
'parents' => $parentGroup->id,
'is_active' => 1,
);
- $childGroup = CRM_Contact_BAO_Group::create($groupParams2);
+ $childGroup = $this->callAPISuccess('Group', 'create', $groupParams2);
// Create a contact within parent group
$parentContactParams = array(
// Check if searching by parent group returns both parent and child group contacts
$searchParams = array(
'group' => $parentGroup->id,
- 'version' => 3,
);
- $result = civicrm_api('contact', 'get', $searchParams);
+ $result = $this->callAPISuccess('contact', 'get', $searchParams);
$validContactIds = array($parentContact, $childContact);
$resultContactIds = array();
foreach ($result['values'] as $k => $v) {
// Check if searching by child group returns just child group contacts
$searchParams = array(
'group' => $childGroup->id,
- 'version' => 3,
);
- $result = civicrm_api('contact', 'get', $searchParams);
+ $result = $this->callAPISuccess('contact', 'get', $searchParams);
$validChildContactIds = array($childContact);
$resultChildContactIds = array();
foreach ($result['values'] as $k => $v) {
}
+ /**
+ * Test the group contact clause does not contain an OR.
+ *
+ * The search should return 3 contacts - 2 households in the smart group of
+ * Contact Type = Household and one Individual hard-added to it. The
+ * Household that meets both criteria should be returned once.
+ */
+ public function testGroupClause() {
+ $this->householdCreate();
+ $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'));
+
+ $query = new CRM_Contact_BAO_Query(
+ array(array('group', 'IN', array($groupID), 0, 0)),
+ array('contact_id')
+ );
+
+ $sql = $query->query();
+ $queryString = implode(' ', $sql);
+ $dao = CRM_Core_DAO::executeQuery($queryString);
+ $this->assertEquals(3, $dao->N);
+ }
+
}
return $result['id'];
}
+ /**
+ * Create a smart group.
+ *
+ * By default it will be a group of households.
+ *
+ * @param array $smartGroupParams
+ * @param array $groupParams
+ * @return int
+ */
+ public function smartGroupCreate($smartGroupParams = array(), $groupParams = array()) {
+ $smartGroupParams = array_merge(array(
+ 'formValues' => array('contact_type' => array('IN' => array('Household'))),
+ ),
+ $smartGroupParams);
+ $savedSearch = CRM_Contact_BAO_SavedSearch::create($smartGroupParams);
+
+ $groupParams['saved_search_id'] = $savedSearch->id;
+ return $this->groupCreate($groupParams);
+ }
/**
* Function to add a Group.