Skip to content

Commit

Permalink
Merge pull request #13888 from pradpnayak/AdvMailin
Browse files Browse the repository at this point in the history
Added unit test for dev/core/issues/726
  • Loading branch information
eileenmcnaughton authored Mar 25, 2019
2 parents f9a6d90 + 3fa6f2a commit 030b2d3
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/phpunit/CRM/Contact/Form/Search/SearchContactTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,45 @@ protected function searchContacts($contactSubType) {
$this->assertEquals("Contact Type In IndividualANDContact Subtype Like {$contactSubType}", $qill);
}

/**
* Test to search based on Group type.
* https://lab.civicrm.org/dev/core/issues/726
*/
public function testContactSearchOnGroupType() {
$groupTypes = $this->callAPISuccess('OptionValue', 'get', [
'return' => ["id", "name"],
'option_group_id' => "group_type",
])['values'];
$groupTypes = array_column($groupTypes, 'id', 'name');

// Create group with empty group type as Access Control.
$groupId = $this->groupCreate([
'group_type' => [
$groupTypes['Access Control'] => 1,
]
]);
// Add random 5 contacts to a group.
$this->groupContactCreate($groupId, 5);

// Find Contacts of Group type == Access Control
$formValues['group_type'] = $groupTypes['Access Control'];
CRM_Contact_BAO_Query::convertFormValues($formValues);
$query = new CRM_Contact_BAO_Query(CRM_Contact_BAO_Query::convertFormValues($formValues));
list($select, $from, $where, $having) = $query->query();
// get and assert contact count
$contactsResult = CRM_Core_DAO::executeQuery(sprintf('SELECT DISTINCT contact_a.id %s %s', $from, $where));
// assert the contacts count
$this->assertEquals(5, $contactsResult->N);

// Find Contacts of Group type == Mailing List
$formValues['group_type'] = $groupTypes['Mailing List'];
CRM_Contact_BAO_Query::convertFormValues($formValues);
$query = new CRM_Contact_BAO_Query(CRM_Contact_BAO_Query::convertFormValues($formValues));
list($select, $from, $where, $having) = $query->query();
// get and assert contact count
$contactsResult = CRM_Core_DAO::executeQuery(sprintf('SELECT DISTINCT contact_a.id %s %s', $from, $where));
// assert the contacts count
$this->assertEquals(0, $contactsResult->N);
}

}

0 comments on commit 030b2d3

Please sign in to comment.