6 class CRM_Contact_Page_AjaxTest
extends CiviUnitTestCase
{
9 public function setUp() {
10 $this->useTransaction(TRUE);
15 * Minimal test on the testGetDupes function to make sure it completes without error.
17 public function testGetDedupes() {
19 $_REQUEST['rgid'] = 1;
20 $_REQUEST['columns'] = array(
24 'src' => 'first_name',
30 $_REQUEST['is_unit_test'] = TRUE;
31 $result = CRM_Contact_Page_AJAX
::getDedupes();
32 $this->assertEquals(array('data' => array(), 'recordsTotal' => 0, 'recordsFiltered' => 0), $result);
35 public function testGetDedupesPostCode() {
37 $_REQUEST['rgid'] = 1;
38 $_REQUEST['snippet'] = 4;
39 $_REQUEST['draw'] = 3;
40 $_REQUEST['columns'] = array(
42 'data' => 'is_selected_input',
52 'data' => 'src_image',
74 'data' => 'dst_image',
96 'data' => 'src_email',
107 'data' => 'dst_email',
109 'searchable' => TRUE,
118 'data' => 'src_street',
120 'searchable' => TRUE,
129 'data' => 'dst_street',
131 'searchable' => TRUE,
140 'data' => 'src_postcode',
142 'searchable' => TRUE,
151 'data' => 'dst_postcode',
153 'searchable' => TRUE,
162 'data' => 'conflicts',
164 'searchable' => TRUE,
175 'searchable' => TRUE,
186 'searchable' => TRUE,
187 'orderable' => FALSE,
195 $_REQUEST['start'] = 0;
196 $_REQUEST['length'] = 10;
197 $_REQUEST['search'] = array(
202 $_REQUEST['_'] = 1466478641007;
203 $_REQUEST['Drupal_toolbar_collapsed'] = 0;
204 $_REQUEST['has_js'] = 1;
205 $_REQUEST['SESSa06550b3043ecca303761d968e3c846a'] = 'qxSxw0F_UmBITMM0JaVwTRcHV1bQqBSHNmBMY9AA8Wk';
207 $_REQUEST['is_unit_test'] = TRUE;
209 $result = CRM_Contact_Page_AJAX
::getDedupes();
210 $this->assertEquals(array('data' => array(), 'recordsTotal' => 0, 'recordsFiltered' => 0), $result);
214 * Test to check contact reference field
216 public function testContactReference() {
218 $groupId1 = $this->groupCreate();
219 $groupId2 = $this->groupCreate(array(
220 'name' => 'Test Group 2',
222 'title' => 'New Test Group2 Created',
223 'description' => 'New Test Group2 Created',
225 'visibility' => 'User and User Admin Only',
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));
233 $contactIds = CRM_Utils_Array
::collect('contact_id', $contactIds);
235 // create custom group with contact reference field
236 $customGroup = $this->customGroupCreate(array('extends' => 'Contact', 'title' => 'select_test_group'));
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',
246 'is_searchable' => 1,
249 $customField = $this->callAPISuccess('custom_field', 'create', $params);
252 'id' => $customField['id'],
253 'is_unit_test' => TRUE,
255 $contactList = CRM_Contact_Page_AJAX
::contactReference();
256 $contactList = CRM_Utils_Array
::collect('id', $contactList);
258 //assert each returned contact id to be present in group contact
259 foreach ($contactList as $contactId) {
260 $this->assertTrue(in_array($contactId, $contactIds));