X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=tests%2Fphpunit%2FCRM%2FContact%2FBAO%2FQueryTest.php;h=b0233c1c5b9650d7128196c387529423118fdaee;hb=c3137c08168665e27a18cd6a5f41ec3b5375b205;hp=fa989ae0ad695737f908567e588a7b931f05a78e;hpb=25d95f38e877adc852b7fee2e27b59f96ab654a8;p=civicrm-core.git diff --git a/tests/phpunit/CRM/Contact/BAO/QueryTest.php b/tests/phpunit/CRM/Contact/BAO/QueryTest.php index fa989ae0ad..b0233c1c5b 100644 --- a/tests/phpunit/CRM/Contact/BAO/QueryTest.php +++ b/tests/phpunit/CRM/Contact/BAO/QueryTest.php @@ -1,9 +1,8 @@ 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 "; + $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, @@ -276,4 +275,30 @@ class CRM_Contact_BAO_QueryTest extends CiviUnitTestCase { } + /** + * 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); + } + }