From 8d710ea56681a50a4cf3734882ace9cdc680b931 Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 2 May 2019 17:58:04 +1200 Subject: [PATCH] Add unit test for group_contact_status in search This currently works for non-smart groups so this will pass. --- tests/phpunit/CRM/Contact/BAO/QueryTest.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/phpunit/CRM/Contact/BAO/QueryTest.php b/tests/phpunit/CRM/Contact/BAO/QueryTest.php index 95ea92894a..632e389793 100644 --- a/tests/phpunit/CRM/Contact/BAO/QueryTest.php +++ b/tests/phpunit/CRM/Contact/BAO/QueryTest.php @@ -624,6 +624,27 @@ civicrm_relationship.is_active = 1 AND $this->assertEquals($where2, $sql5[2]); } + /** + * Test we can narrow a group get by status. + */ + public function testGetByGroupWithStatus() { + $groupID = $this->groupCreate(); + $this->groupContactCreate($groupID , 3); + $groupContactID = $this->callAPISuccessGetSingle('GroupContact', ['group_id' => $groupID, 'options' => ['limit' => 1]])['id']; + $this->callAPISuccess('GroupContact', 'create', ['id' => $groupContactID, 'status' => 'Removed']); + $queryObj = new CRM_Contact_BAO_Query([['group', '=', $groupID, 0, 0], ['group_contact_status', 'IN', ['Removed' => 1], 0, 0]]); + $resultDAO = $queryObj->searchQuery(); + $this->assertEquals(1, $resultDAO->N); + + $queryObj = new CRM_Contact_BAO_Query([['group', '=', $groupID, 0, 0], ['group_contact_status', 'IN', ['Added' => 1], 0, 0]]); + $resultDAO = $queryObj->searchQuery(); + $this->assertEquals(2, $resultDAO->N); + + $queryObj = new CRM_Contact_BAO_Query([['group', '=', $groupID, 0, 0]]); + $resultDAO = $queryObj->searchQuery(); + $this->assertEquals(2, $resultDAO->N); + } + /** * Test the group contact clause does not contain an OR. * -- 2.25.1