3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 * Test class for CRM_Contact_BAO_Group BAO
34 class CRM_Contact_Form_Search_SearchContactTest
extends CiviUnitTestCase
{
37 * Test contact sub type search.
39 public function testContactSubtype() {
40 foreach (['Contact_sub_type', 'Contact2__sub__type'] as $contactSubType) {
41 $subType = $this->callAPISuccess('ContactType', 'create', [
42 'name' => $contactSubType,
43 'label' => $contactSubType,
45 'parent_id' => "Individual",
47 // Contact Type api munge name in create mode
48 // Therefore updating the name in update mode
49 $this->callAPISuccess('ContactType', 'create', [
50 'name' => $contactSubType,
51 'id' => $subType['id'],
54 $this->searchContacts('Contact_sub_type');
55 $this->searchContacts('Contact2__sub__type');
58 protected function searchContacts($contactSubType) {
61 'first_name' => 'Peter' . substr(sha1(rand()), 0, 4),
62 'last_name' => 'Lastname',
63 'contact_type' => 'Individual',
64 'contact_sub_type' => $contactSubType,
66 $contacts = $this->callAPISuccess('Contact', 'create', $params);
67 $contactTypes = CRM_Contact_BAO_ContactType
::getSelectElements(TRUE);
68 foreach ($contactTypes as $contactType => $ignore) {
69 if (strpos($contactType, $contactSubType) !== FALSE) {
71 'contact_type' => $contactType,
76 CRM_Contact_BAO_Query
::convertFormValues($formValues);
77 $query = new CRM_Contact_BAO_Query(CRM_Contact_BAO_Query
::convertFormValues($formValues));
78 list($select, $from, $where, $having) = $query->query();
79 // get and assert contact count
80 $contactsResult = CRM_Core_DAO
::executeQuery(sprintf('SELECT DISTINCT contact_a.id %s %s', $from, $where))->fetchAll();
81 foreach ($contactsResult as $key => $value) {
82 $contactsResult[$key] = $value['id'];
84 // assert the contacts count
85 $this->assertEquals(1, count($contactsResult));
86 // assert the contact IDs
87 $expectedResult = [$contacts['id']];
88 $this->checkArrayEquals($expectedResult, $contactsResult);
89 // get and assert qill string
90 $qill = trim(implode($query->getOperator(), CRM_Utils_Array
::value(0, $query->qill())));
91 $this->assertEquals("Contact Type In IndividualANDContact Subtype Like {$contactSubType}", $qill);