$op = key($value);
$value = $value[$op];
}
-
- // Replace pseudo operators from search builder
- $op = str_replace('EMPTY', 'NULL', $op);
+ // Translate EMPTY to NULL as EMPTY is cannot be used in it's intended meaning here
+ // so has to be 'squashed into' NULL. (ie. group membership cannot be '').
+ // even one group might equate to multiple when looking at children so IN is simpler.
+ // @todo - also look at != casting but there are rows below to review.
+ $opReplacements = [
+ 'EMPTY' => 'NULL',
+ 'NOT EMPTY' => 'NOT NULL',
+ '=' => 'IN',
+ ];
+ if (isset($opReplacements[$op])) {
+ $op = $opReplacements[$op];
+ }
if (strpos($op, 'NULL')) {
$value = NULL;
$clause = "{$gcTable}.contact_id NOT IN (SELECT contact_id FROM civicrm_group_contact cgc WHERE cgc.group_id = $groupIds )";
}
else {
- $clause = self::buildClause("{$gcTable}.group_id", $op, ($op === '=' ? $regularGroupIDs[0] : $regularGroupIDs));
+ $clause = self::buildClause("{$gcTable}.group_id", $op, $regularGroupIDs);
}
$groupClause[] = "( {$clause} )";
/**
* Test case for contact search: CRM-6706, CRM-6586 Parent Group search should return contacts from child groups too.
+ *
+ * @throws \Exception
*/
public function testContactSearchByParentGroup() {
// create a parent group
$childContactParams = array(
'first_name' => 'Child1 Fname',
'last_name' => 'Child2 Lname',
- 'group' => array($childGroup['id'] => 1),
+ 'group' => [$childGroup['id'] => 1],
);
$childContact = $this->individualCreate($childContactParams);
*/
class CRM_Contact_SelectorTest extends CiviUnitTestCase {
- public function tearDown() {
-
- }
-
/**
* Test the query from the selector class is consistent with the dataset expectation.
*
'action' => CRM_Core_Action::NONE,
'includeContactIds' => NULL,
'searchDescendentGroups' => FALSE,
+ 'expected_query' => [],
),
),
array(