Merge pull request #9070 from xurizaemon/tmp-cleanups-20160919a
[civicrm-core.git] / tests / phpunit / CRM / Contact / Page / AjaxTest.php
1 <?php
2
3 /**
4 * @group headless
5 */
6 class CRM_Contact_Page_AjaxTest extends CiviUnitTestCase {
7
8
9 public function setUp() {
10 $this->useTransaction(TRUE);
11 parent::setUp();
12 }
13
14 /**
15 * Minimal test on the testGetDupes function to make sure it completes without error.
16 */
17 public function testGetDedupes() {
18 $_REQUEST['gid'] = 1;
19 $_REQUEST['rgid'] = 1;
20 $_REQUEST['columns'] = array(
21 array(
22 'search' => array(
23 'value' => array(
24 'src' => 'first_name',
25 ),
26 ),
27 'data' => 'src',
28 ),
29 );
30 $_REQUEST['is_unit_test'] = TRUE;
31 $result = CRM_Contact_Page_AJAX::getDedupes();
32 $this->assertEquals(array('data' => array(), 'recordsTotal' => 0, 'recordsFiltered' => 0), $result);
33 }
34
35 public function testGetDedupesPostCode() {
36 $_REQUEST['gid'] = 1;
37 $_REQUEST['rgid'] = 1;
38 $_REQUEST['snippet'] = 4;
39 $_REQUEST['draw'] = 3;
40 $_REQUEST['columns'] = array(
41 0 => array(
42 'data' => 'is_selected_input',
43 'name' => '',
44 'searchable' => TRUE,
45 'search' => array(
46 'value' => '',
47 'regex' => FALSE,
48 ),
49 ),
50
51 1 => array(
52 'data' => 'src_image',
53 'name' => '',
54 'searchable' => TRUE,
55 'orderable' => FALSE,
56 'search' => array(
57 'value' => '',
58 'regex' => FALSE,
59 ),
60 ),
61
62 2 => array(
63 'data' => 'src',
64 'name' => '',
65 'searchable' => TRUE,
66 'orderable' => TRUE,
67 'search' => array(
68 'value' => '',
69 'regex' => FALSE,
70 ),
71 ),
72
73 3 => array(
74 'data' => 'dst_image',
75 'name' => '',
76 'searchable' => TRUE,
77 'orderable' => FALSE,
78 'search' => array(
79 'value' => '',
80 'regex' => FALSE,
81 ),
82 ),
83
84 4 => array(
85 'data' => 'dst',
86 'name' => '',
87 'searchable' => TRUE,
88 'orderable' => TRUE,
89 'search' => array(
90 'value' => '',
91 'regex' => FALSE,
92 ),
93 ),
94
95 5 => array(
96 'data' => 'src_email',
97 'name' => '',
98 'searchable' => TRUE,
99 'orderable' => TRUE,
100 'search' => array(
101 'value' => '',
102 'regex' => FALSE,
103 ),
104 ),
105
106 6 => array(
107 'data' => 'dst_email',
108 'name' => '',
109 'searchable' => TRUE,
110 'orderable' => TRUE,
111 'search' => array(
112 'value' => '',
113 'regex' => FALSE,
114 ),
115 ),
116
117 7 => array(
118 'data' => 'src_street',
119 'name' => '',
120 'searchable' => TRUE,
121 'orderable' => TRUE,
122 'search' => array(
123 'value' => '',
124 'regex' => FALSE,
125 ),
126 ),
127
128 8 => array(
129 'data' => 'dst_street',
130 'name' => '',
131 'searchable' => TRUE,
132 'orderable' => TRUE,
133 'search' => array(
134 'value' => '',
135 'regex' => FALSE,
136 ),
137 ),
138
139 9 => array(
140 'data' => 'src_postcode',
141 'name' => '',
142 'searchable' => TRUE,
143 'orderable' => TRUE,
144 'search' => array(
145 'value' => 123,
146 'regex' => FALSE,
147 ),
148 ),
149
150 10 => array(
151 'data' => 'dst_postcode',
152 'name' => '',
153 'searchable' => TRUE,
154 'orderable' => TRUE,
155 'search' => array(
156 'value' => '',
157 'regex' => FALSE,
158 ),
159 ),
160
161 11 => array(
162 'data' => 'conflicts',
163 'name' => '',
164 'searchable' => TRUE,
165 'orderable' => TRUE,
166 'search' => array(
167 'value' => '',
168 'regex' => FALSE,
169 ),
170 ),
171
172 12 => array(
173 'data' => 'weight',
174 'name' => '',
175 'searchable' => TRUE,
176 'orderable' => TRUE,
177 'search' => array(
178 'value' => '',
179 'regex' => FALSE,
180 ),
181 ),
182
183 13 => array(
184 'data' => 'actions',
185 'name' => '',
186 'searchable' => TRUE,
187 'orderable' => FALSE,
188 'search' => array(
189 'value' => '',
190 'regex' => FALSE,
191 ),
192 ),
193 );
194
195 $_REQUEST['start'] = 0;
196 $_REQUEST['length'] = 10;
197 $_REQUEST['search'] = array(
198 'value' => '',
199 'regex' => FALSE,
200 );
201
202 $_REQUEST['_'] = 1466478641007;
203 $_REQUEST['Drupal_toolbar_collapsed'] = 0;
204 $_REQUEST['has_js'] = 1;
205 $_REQUEST['SESSa06550b3043ecca303761d968e3c846a'] = 'qxSxw0F_UmBITMM0JaVwTRcHV1bQqBSHNmBMY9AA8Wk';
206
207 $_REQUEST['is_unit_test'] = TRUE;
208
209 $result = CRM_Contact_Page_AJAX::getDedupes();
210 $this->assertEquals(array('data' => array(), 'recordsTotal' => 0, 'recordsFiltered' => 0), $result);
211 }
212
213 /**
214 * Test to check contact reference field
215 */
216 public function testContactReference() {
217 //create group
218 $groupId1 = $this->groupCreate();
219 $groupId2 = $this->groupCreate(array(
220 'name' => 'Test Group 2',
221 'domain_id' => 1,
222 'title' => 'New Test Group2 Created',
223 'description' => 'New Test Group2 Created',
224 'is_active' => 1,
225 'visibility' => 'User and User Admin Only',
226 ));
227
228 $contactIds = array();
229 foreach (array($groupId1, $groupId2) as $groupId) {
230 $this->groupContactCreate($groupId);
231 $contactIds = array_merge($contactIds, CRM_Contact_BAO_Group::getGroupContacts($groupId));
232 }
233 $contactIds = CRM_Utils_Array::collect('contact_id', $contactIds);
234
235 // create custom group with contact reference field
236 $customGroup = $this->customGroupCreate(array('extends' => 'Contact', 'title' => 'select_test_group'));
237 $params = array(
238 'custom_group_id' => $customGroup['id'],
239 'name' => 'Worker_Lookup',
240 'label' => 'Worker Lookup',
241 // limit this field to two groups created above
242 'filter' => "action=lookup&group={$groupId1},{$groupId2}",
243 'html_type' => 'Autocomplete-Select',
244 'data_type' => 'ContactReference',
245 'weight' => 4,
246 'is_searchable' => 1,
247 'is_active' => 1,
248 );
249 $customField = $this->callAPISuccess('custom_field', 'create', $params);
250
251 $_GET = array(
252 'id' => $customField['id'],
253 'is_unit_test' => TRUE,
254 );
255 $contactList = CRM_Contact_Page_AJAX::contactReference();
256 $contactList = CRM_Utils_Array::collect('id', $contactList);
257
258 //assert each returned contact id to be present in group contact
259 foreach ($contactList as $contactId) {
260 $this->assertTrue(in_array($contactId, $contactIds));
261 }
262 }
263
264 }