Merge pull request #1471 from eileenmcnaughton/CRM-13254
[civicrm-core.git] / tests / phpunit / api / v3 / ProfileTest.php
CommitLineData
6a488035 1<?php
b6708aeb 2
3/*
4 +--------------------------------------------------------------------+
232624b1 5| CiviCRM version 4.4 |
b6708aeb 6+--------------------------------------------------------------------+
7| Copyright CiviCRM LLC (c) 2004-2013 |
8+--------------------------------------------------------------------+
9| This file is a part of CiviCRM. |
10| |
11| CiviCRM is free software; you can copy, modify, and distribute it |
12| under the terms of the GNU Affero General Public License |
13| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14| |
15| CiviCRM is distributed in the hope that it will be useful, but |
16| WITHOUT ANY WARRANTY; without even the implied warranty of |
17| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18| See the GNU Affero General Public License for more details. |
19| |
20| You should have received a copy of the GNU Affero General Public |
21| License and the CiviCRM Licensing Exception along |
22| with this program; if not, contact CiviCRM LLC |
23| at info[AT]civicrm[DOT]org. If you have questions about the |
24| GNU Affero General Public License or the licensing of CiviCRM, |
25| see the CiviCRM license FAQ at http://civicrm.org/licensing |
26+--------------------------------------------------------------------+
27*/
6a488035
TO
28
29/**
30 * Include class definitions
31 */
32require_once 'tests/phpunit/CiviTest/CiviUnitTestCase.php';
33
34/**
35 * Test APIv3 civicrm_profile_* functions
36 *
37 * @package CiviCRM
38 */
39class api_v3_ProfileTest extends CiviUnitTestCase {
40 protected $_apiversion;
9dec4e61 41 protected $_profileID;
6a488035
TO
42 function get_info() {
43 return array(
44 'name' => 'Profile Test',
45 'description' => 'Test all profile API methods.',
46 'group' => 'CiviCRM API Tests',
47 );
48 }
49
50 function setUp() {
51 $this->_apiversion = 3;
52 parent::setUp();
53 $config = CRM_Core_Config::singleton();
54 $config->countryLimit[1] = 1013;
55 $config->stateLimit[1] = 1013;
56 }
57
58 function tearDown() {
7fbb4198 59
6a488035 60 $this->quickCleanup(array(
6a488035
TO
61 'civicrm_contact',
62 'civicrm_phone',
63 'civicrm_address',
7fbb4198 64 ), TRUE);
f01ce56b 65 // ok can't be bothered wring an api to do this & truncating is crazy
66 CRM_Core_DAO::executeQuery(' DELETE FROM civicrm_uf_group WHERE id IN (25, 26)');
6a488035
TO
67 }
68
7fbb4198 69 ////////////// test $this->callAPISuccess3_profile_get //////////////////
6a488035
TO
70
71 /**
72 * check Without ProfileId
73 */
74 function testProfileGetWithoutProfileId() {
75 $params = array(
76 'contact_id' => 1,
6a488035 77 );
7fbb4198 78 $result = $this->callAPIFailure('profile', 'get', $params,
79 'Mandatory key(s) missing from params array: profile_id'
80 );
6a488035
TO
81 }
82
83 /**
84 * check with no invalid profile Id
85 */
86 function testProfileGetInvalidProfileId() {
87 $params = array(
88 'contact_id' => 1,
89 'profile_id' => 1000,
6a488035 90 );
d0e1eff2 91 $result = $this->callAPIFailure('profile', 'get', $params);
6a488035
TO
92 }
93
94 /**
95 * check with success
96 */
97 function testProfileGet() {
98 $pofileFieldValues = $this->_createIndividualContact();
99 $expected = current($pofileFieldValues);
100 $contactId = key($pofileFieldValues);
101 $params = array(
102 'profile_id' => 25,
103 'contact_id' => $contactId,
6a488035 104 );
f01ce56b 105 $result = $this->callAPISuccess('profile', 'get', $params);
6a488035
TO
106 foreach ($expected as $profileField => $value) {
107 $this->assertEquals($value, CRM_Utils_Array::value($profileField, $result['values']), "In line " . __LINE__ . " error message: " . "missing/mismatching value for {$profileField}"
108 );
109 }
6a488035
TO
110 }
111
f01ce56b 112 function testProfileGetMultiple() {
113 $pofileFieldValues = $this->_createIndividualContact();
114 $expected = current($pofileFieldValues);
115 $contactId = key($pofileFieldValues);
116 $params = array(
117 'profile_id' => array(25, 1, 'Billing'),
118 'contact_id' => $contactId,
119 );
120
121 $result = $this->callAPIAndDocument('profile', 'get', $params, __FUNCTION__, __FILE__);
122 foreach ($expected as $profileField => $value) {
123 $this->assertEquals($value, CRM_Utils_Array::value($profileField, $result['values'][25]), " error message: " . "missing/mismatching value for {$profileField}");
124 }
125 $this->assertEquals('abc1', $result['values'][1]['first_name'], " error message: " . "missing/mismatching value for {$profileField}");
126 $this->assertFalse(array_key_exists('email-Primary', $result['values'][1]), 'profile 1 doesn not include email');
127 $this->assertEquals($result['values']['Billing'], array(
128 'billing_first_name' => 'abc1',
e0efd2d0 129 'billing_middle_name' => 'J.',
f01ce56b 130 'billing_last_name' => 'xyz1',
b29f74b6 131 'billing_street_address-5' => '5 Saint Helier St',
132 'billing_city-5' => 'Gotham City',
e0efd2d0 133 'billing_state_province_id-5' => '1021',
f01ce56b 134 'billing_country_id-5' => '',
135 'billing-email-5' => 'abc1.xyz1@yahoo.com',
e0efd2d0 136 'billing_postal_code-5' => '90210',
137 'billing-email-5' => 'abc1.xyz1@yahoo.com',
138 'email-5' => 'abc1.xyz1@yahoo.com',
f01ce56b 139 ));
140 }
141
b29f74b6 142 function testProfileGetBillingUseIsBillingLocation() {
143 $individual = $this->_createIndividualContact();
144 $contactId = key($individual);
145 $this->callAPISuccess('address', 'create', array(
146 'is_billing' => 1,
147 'street_address' => 'is billing st',
148 'location_type_id' => 2,
149 'contact_id' => $contactId,
150 ));
151
152 $expected = current($individual);
153
154 $params = array(
155 'profile_id' => array(25, 1, 'Billing'),
156 'contact_id' => $contactId,
157 );
158
159 $result = $this->callAPISuccess('profile', 'get', $params);
160 $this->assertEquals('abc1', $result['values'][1]['first_name']);
161 $this->assertEquals(array(
162 'billing_first_name' => 'abc1',
163 'billing_middle_name' => 'J.',
164 'billing_last_name' => 'xyz1',
165 'billing_street_address-5' => 'is billing st',
166 'billing_city-5' => '',
167 'billing_state_province_id-5' => '',
168 'billing_country_id-5' => '',
169 'billing-email-5' => 'abc1.xyz1@yahoo.com',
170 'email-5' => 'abc1.xyz1@yahoo.com',
171 'billing_postal_code-5' => '',
172 ), $result['values']['Billing']);
173 }
174
f01ce56b 175 function testProfileGetMultipleHasBillingLocation() {
176 $individual = $this->_createIndividualContact();
177 $contactId = key($individual);
178 $this->callAPISuccess('address', 'create', array('contact_id' => $contactId , 'street_address' => '25 Big Street', 'city' => 'big city', 'location_type_id' => 5));
179 $this->callAPISuccess('email', 'create', array('contact_id' => $contactId , 'email' => 'big@once.com', 'location_type_id' => 2, 'is_billing' => 1));
180
181 $expected = current($individual);
182
183 $params = array(
184 'profile_id' => array(25, 1, 'Billing'),
185 'contact_id' => $contactId,
186 );
187
188 $result = $this->callAPISuccess('profile', 'get', $params, __FUNCTION__, __FILE__);
189 $this->assertEquals('abc1', $result['values'][1]['first_name']);
190 $this->assertEquals($result['values']['Billing'], array(
191 'billing_first_name' => 'abc1',
e0efd2d0 192 'billing_middle_name' => 'J.',
f01ce56b 193 'billing_last_name' => 'xyz1',
194 'billing_street_address-5' => '25 Big Street',
195 'billing_city-5' => 'big city',
196 'billing_state_province_id-5' => '',
197 'billing_country_id-5' => '',
198 'billing-email-5' => 'big@once.com',
e0efd2d0 199 'email-5' => 'big@once.com',
200 'billing_postal_code-5' => '',
f01ce56b 201 ));
202 }
b29f74b6 203
204
7fbb4198 205 /**
206 * check contact activity profile without activity id
207 */
6a488035
TO
208 function testContactActivityGetWithoutActivityId() {
209 list($params, $expected) = $this->_createContactWithActivity();
210
211 unset($params['activity_id']);
7fbb4198 212 $result = $this->callAPIFailure('profile', 'get', $params,
213 'Mandatory key(s) missing from params array: activity_id');
6a488035
TO
214 }
215
7fbb4198 216 /**
217 * check contact activity profile wrong activity id
218 */
6a488035
TO
219 function testContactActivityGetWrongActivityId() {
220 list($params, $expected) = $this->_createContactWithActivity();
221
222 $params['activity_id'] = 100001;
7fbb4198 223 $result = $this->callAPIFailure('profile', 'get', $params,
224 'Invalid Activity Id (aid).');
6a488035
TO
225 }
226
227 /*
228 * check contact activity profile with wrong activity type
229 */
230 function testContactActivityGetWrongActivityType() {
231 //flush cache by calling with reset
232 $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, TRUE, 'name', TRUE);
233
234 $sourceContactId = $this->householdCreate();
235
236 $activityparams = array(
237 'source_contact_id' => $sourceContactId,
238 'activity_type_id' => '2',
239 'subject' => 'Test activity',
240 'activity_date_time' => '20110316',
241 'duration' => '120',
242 'location' => 'Pensulvania',
243 'details' => 'a test activity',
244 'status_id' => '1',
6a488035
TO
245 'priority_id' => '1',
246 );
247
7fbb4198 248 $activity = $this->callAPISuccess('activity', 'create', $activityparams);
6a488035
TO
249
250 $activityValues = array_pop($activity['values']);
251
252 list($params, $expected) = $this->_createContactWithActivity();
253
254 $params['activity_id'] = $activityValues['id'];
7fbb4198 255 $result = $this->callAPIFailure('profile', 'get', $params,
256 'This activity cannot be edited or viewed via this profile.'
257 );
6a488035
TO
258 }
259
260 /*
261 * check contact activity profile with success
262 */
263 function testContactActivityGetSuccess() {
264 list($params, $expected) = $this->_createContactWithActivity();
265
7fbb4198 266 $result = $this->callAPISuccess('profile', 'get', $params);
6a488035
TO
267
268 foreach ($expected as $profileField => $value) {
269 $this->assertEquals($value, CRM_Utils_Array::value($profileField, $result['values']), "In line " . __LINE__ . " error message: " . "missing/mismatching value for {$profileField}"
270 );
271 }
6a488035
TO
272 }
273
6a488035 274 /**
9dec4e61 275 * Check getfields works & gives us our fields
276 */
277 function testGetFields() {
278 $this->_createIndividualProfile();
279 $this->_addCustomFieldToProfile($this->_profileID);
280 $result = $this->callAPIAndDocument('profile', 'getfields', array('action' => 'submit', 'profile_id' => 25), __FUNCTION__, __FILE__,
281 'demonstrates retrieving profile fields passing in an id');
282 $this->assertArrayKeyExists('first_name', $result['values']);
283 $this->assertEquals('2', $result['values']['first_name']['type']);
284 $this->assertEquals('Email', $result['values']['email']['title']);
285 $this->assertEquals('civicrm_state_province', $result['values']['state_province-1']['pseudoconstant']['table']);
286 $this->assertEquals('defaultValue', $result['values']['custom_1']['default_value']);
287 $this->assertFalse(array_key_exists('participant_status', $result['values']));
288 }
289 /**
b0b44427 290 * Check getfields works & gives us our fields - partipant profile
6a488035 291 */
9dec4e61 292 function testGetFieldsParticipantProfile() {
293 $result = $this->callAPISuccess('profile', 'getfields', array(
294 'action' => 'submit',
295 'profile_id' => 'participant_status',
296 'get_options' => 'all')
297 );
298 $this->assertTrue(array_key_exists('participant_status', $result['values']));
299 $this->assertEquals('Attended', $result['values']['participant_status']['options'][2]);
6a488035 300 }
b0b44427 301
302 /**
303 * Check getfields works & gives us our fields - membership_batch_entry
304 * (getting to the end with no e-notices is pretty good evidence it's working)
305 */
306 function testGetFieldsMembershipBatchProfile() {
307 $result = $this->callAPISuccess('profile', 'getfields', array(
308 'action' => 'submit',
309 'profile_id' => 'membership_batch_entry',
310 'get_options' => 'all')
311 );
312 $this->assertTrue(array_key_exists('total_amount', $result['values']));
313 $this->assertEquals(12, $result['values']['receive_date']['type']);
314 }
315
316 /**
317 * Check getfields works & gives us our fields - do them all
318 * (getting to the end with no e-notices is pretty good evidence it's working)
319 */
320 function testGetFieldsAllProfiles() {
321 $result = $this->callAPISuccess('uf_group', 'get', array('return' => 'id'));
322 $profileIDs = array_keys($result['values']);
323 foreach ($profileIDs as $profileID) {
324 $result = $this->callAPISuccess('profile', 'getfields', array(
325 'action' => 'submit',
326 'profile_id' => $profileID,
327 'get_options' => 'all')
328 );
329 }
330 }
9dec4e61 331 /////////////// test $this->callAPISuccess3_profile_set //////////////////
6a488035
TO
332
333 /**
334 * check Without ProfileId
335 */
9dec4e61 336 function testProfileSubmitWithoutProfileId() {
6a488035
TO
337 $params = array(
338 'contact_id' => 1,
6a488035 339 );
9dec4e61 340 $result = $this->callAPIFailure('profile', 'submit', $params,
7fbb4198 341 'Mandatory key(s) missing from params array: profile_id'
342 );
6a488035
TO
343 }
344
345 /**
346 * check with no invalid profile Id
347 */
9dec4e61 348 function testProfileSubmitInvalidProfileId() {
6a488035
TO
349 $params = array(
350 'contact_id' => 1,
351 'profile_id' => 1000,
6a488035 352 );
9dec4e61 353 $result = $this->callAPIFailure('profile', 'submit', $params);
6a488035
TO
354 }
355
356 /**
357 * check with missing required field in profile
358 */
9dec4e61 359 function testProfileSubmitCheckProfileRequired() {
6a488035
TO
360 $pofileFieldValues = $this->_createIndividualContact();
361 current($pofileFieldValues);
362 $contactId = key($pofileFieldValues);
363 $updateParams = array(
364 'first_name' => 'abc2',
365 'last_name' => 'xyz2',
366 'phone-1-1' => '022 321 826',
367 'country-1' => '1013',
368 'state_province-1' => '1000',
369 );
370
7fbb4198 371 $params = array_merge(array('profile_id' => 25, 'contact_id' => $contactId),
6a488035
TO
372 $updateParams
373 );
374
9dec4e61 375 $result = $this->callAPIFailure('profile', 'submit', $params,
7fbb4198 376 'Missing required parameters for profile id 25: email-Primary'
377 );
6a488035
TO
378 }
379
380 /**
381 * check with success
382 */
9dec4e61 383 function testProfileSubmit() {
6a488035
TO
384 $pofileFieldValues = $this->_createIndividualContact();
385 current($pofileFieldValues);
386 $contactId = key($pofileFieldValues);
387
388 $updateParams = array(
389 'first_name' => 'abc2',
390 'last_name' => 'xyz2',
391 'email-Primary' => 'abc2.xyz2@gmail.com',
392 'phone-1-1' => '022 321 826',
393 'country-1' => '1013',
394 'state_province-1' => '1000',
395 );
396
397 $params = array_merge(array(
398 'profile_id' => 25,
399 'contact_id' => $contactId,
6a488035
TO
400 ), $updateParams);
401
9dec4e61 402 $result = $this->callAPIAndDocument('profile', 'submit', $params, __FUNCTION__, __FILE__);
6a488035
TO
403
404 $getParams = array(
405 'profile_id' => 25,
406 'contact_id' => $contactId,
6a488035 407 );
7fbb4198 408 $profileDetails = $this->callAPISuccess('profile', 'get', $getParams);
6a488035
TO
409
410 foreach ($updateParams as $profileField => $value) {
411 $this->assertEquals($value, CRM_Utils_Array::value($profileField, $profileDetails['values']), "In line " . __LINE__ . " error message: " . "missing/mismatching value for {$profileField}"
412 );
413 }
414 }
415
158d3e03 416 /**
417 * set is deprecated but we need to ensure it still works
418 */
419 function testLegacySet() {
420 $pofileFieldValues = $this->_createIndividualContact();
421 current($pofileFieldValues);
422 $contactId = key($pofileFieldValues);
423
424 $updateParams = array(
425 'first_name' => 'abc2',
426 'last_name' => 'xyz2',
427 'email-Primary' => 'abc2.xyz2@gmail.com',
428 'phone-1-1' => '022 321 826',
429 'country-1' => '1013',
430 'state_province-1' => '1000',
431 );
432
433 $params = array_merge(array(
434 'profile_id' => 25,
435 'contact_id' => $contactId,
436 ), $updateParams);
437
438 $result = $this->callAPISuccess('profile', 'set', $params);
439 $this->assertArrayKeyExists('values', $result);
440 $getParams = array(
441 'profile_id' => 25,
442 'contact_id' => $contactId,
443 );
444 $profileDetails = $this->callAPISuccess('profile', 'get', $getParams);
445
446 foreach ($updateParams as $profileField => $value) {
447 $this->assertEquals($value, CRM_Utils_Array::value($profileField, $profileDetails['values']), "In line " . __LINE__ . " error message: " . "missing/mismatching value for {$profileField}"
448 );
449 }
450 }
6a488035
TO
451 /*
452 * check contact activity profile without activity id
453 */
9dec4e61 454 function testContactActivitySubmitWithoutActivityId() {
6a488035
TO
455 list($params, $expected) = $this->_createContactWithActivity();
456
457 $params = array_merge($params, $expected);
458 unset($params['activity_id']);
9dec4e61 459 $result = $this->callAPIFailure('profile', 'submit', $params);
6a488035 460 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: activity_id');
6a488035
TO
461 }
462
463 /*
464 * check contact activity profile wrong activity id
465 */
9dec4e61 466 function testContactActivitySubmitWrongActivityId() {
6a488035 467 list($params, $expected) = $this->_createContactWithActivity();
6a488035
TO
468 $params = array_merge($params, $expected);
469 $params['activity_id'] = 100001;
9dec4e61 470 $result = $this->callAPIFailure('profile', 'submit', $params);
6a488035 471 $this->assertEquals($result['error_message'], 'Invalid Activity Id (aid).');
6a488035
TO
472 }
473
474 /*
475 * check contact activity profile with wrong activity type
476 */
9dec4e61 477 function testContactActivitySubmitWrongActivityType() {
6a488035
TO
478 //flush cache by calling with reset
479 $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, TRUE, 'name', TRUE);
480
481 $sourceContactId = $this->householdCreate();
482
483 $activityparams = array(
484 'source_contact_id' => $sourceContactId,
485 'activity_type_id' => '2',
486 'subject' => 'Test activity',
487 'activity_date_time' => '20110316',
488 'duration' => '120',
489 'location' => 'Pensulvania',
490 'details' => 'a test activity',
491 'status_id' => '1',
6a488035
TO
492 'priority_id' => '1',
493 );
494
7fbb4198 495 $activity = $this->callAPISuccess('activity', 'create', $activityparams);
6a488035
TO
496
497 $activityValues = array_pop($activity['values']);
498
499 list($params, $expected) = $this->_createContactWithActivity();
500
501 $params = array_merge($params, $expected);
502 $params['activity_id'] = $activityValues['id'];
9dec4e61 503 $result = $this->callAPIFailure('profile', 'submit', $params,
7fbb4198 504 'This activity cannot be edited or viewed via this profile.');
6a488035
TO
505 }
506
507 /*
508 * check contact activity profile with success
509 */
9dec4e61 510 function testContactActivitySubmitSuccess() {
6a488035
TO
511 list($params, $expected) = $this->_createContactWithActivity();
512
513 $updateParams = array(
514 'first_name' => 'abc2',
515 'last_name' => 'xyz2',
516 'email-Primary' => 'abc2.xyz2@yahoo.com',
517 'activity_subject' => 'Test Meeting',
518 'activity_details' => 'a test activity details',
519 'activity_duration' => '100',
520 'activity_date_time' => '03/08/2010',
521 'activity_status_id' => '2',
522 );
523 $profileParams = array_merge($params, $updateParams);
9dec4e61 524 $profile = $this->callAPISuccess('profile', 'submit', $profileParams);
7fbb4198 525 $result = $this->callAPISuccess('profile', 'get', $params);
6a488035
TO
526
527 foreach ($updateParams as $profileField => $value) {
528 $this->assertEquals($value, CRM_Utils_Array::value($profileField, $result['values']), "In line " . __LINE__ . " error message: " . "missing/mismatching value for {$profileField}"
529 );
530 }
6a488035
TO
531 }
532
6a488035 533 /**
7fbb4198 534 * check profile apply Without ProfileId
6a488035
TO
535 */
536 function testProfileApplyWithoutProfileId() {
537 $params = array(
538 'contact_id' => 1,
6a488035 539 );
7fbb4198 540 $result = $this->callAPIFailure('profile', 'apply', $params,
541 'Mandatory key(s) missing from params array: profile_id');
6a488035
TO
542 }
543
544 /**
7fbb4198 545 * check profile apply with no invalid profile Id
6a488035
TO
546 */
547 function testProfileApplyInvalidProfileId() {
548 $params = array(
549 'contact_id' => 1,
550 'profile_id' => 1000,
6a488035 551 );
d0e1eff2 552 $result = $this->callAPIFailure('profile', 'apply', $params);
6a488035
TO
553 }
554
555 /**
556 * check with success
557 */
558 function testProfileApply() {
559 $pofileFieldValues = $this->_createIndividualContact();
560 current($pofileFieldValues);
561 $contactId = key($pofileFieldValues);
562
563 $params = array(
564 'profile_id' => 25,
565 'contact_id' => $contactId,
6a488035
TO
566 'first_name' => 'abc2',
567 'last_name' => 'xyz2',
568 'email-Primary' => 'abc2.xyz2@gmail.com',
569 'phone-1-1' => '022 321 826',
570 'country-1' => '1013',
571 'state_province-1' => '1000',
572 );
573
7fbb4198 574 $result = $this->callAPIAndDocument('profile', 'apply', $params, __FUNCTION__, __FILE__);
6a488035
TO
575
576 // Expected field values
577 $expected['contact'] = array(
578 'contact_id' => $contactId,
579 'contact_type' => 'Individual',
580 'first_name' => 'abc2',
581 'last_name' => 'xyz2',
582 );
583 $expected['email'] = array(
584 'location_type_id' => 1,
585 'is_primary' => 1,
586 'email' => 'abc2.xyz2@gmail.com',
587 );
588
589 $expected['phone'] = array(
590 'location_type_id' => 1,
591 'is_primary' => 1,
592 'phone_type_id' => 1,
593 'phone' => '022 321 826',
594 );
595 $expected['address'] = array(
596 'location_type_id' => 1,
597 'is_primary' => 1,
598 'country_id' => 1013,
599 'state_province_id' => 1000,
600 );
601
602 foreach ($expected['contact'] as $field => $value) {
603 $this->assertEquals($value, CRM_Utils_Array::value($field, $result['values']), "In line " . __LINE__ . " error message: " . "missing/mismatching value for {$field}"
604 );
605 }
606
607 foreach (array(
608 'email', 'phone', 'address') as $fieldType) {
609 $typeValues = array_pop($result['values'][$fieldType]);
610 foreach ($expected[$fieldType] as $field => $value) {
611 $this->assertEquals($value, CRM_Utils_Array::value($field, $typeValues), "In line " . __LINE__ . " error message: " . "missing/mismatching value for {$field} ({$fieldType})"
612 );
613 }
614 }
615 }
616
617 /*
618 * Helper function to create an Individual with address/email/phone info. Import UF Group and UF Fields
619 */
e0efd2d0 620 function _createIndividualContact($params = array()) {
621 $contactParams = array_merge(array(
6a488035
TO
622 'first_name' => 'abc1',
623 'last_name' => 'xyz1',
6a488035 624 'email' => 'abc1.xyz1@yahoo.com',
6a488035
TO
625 'api.address.create' => array(
626 'location_type_id' => 1,
627 'is_primary' => 1,
b29f74b6 628 'street_address' => '5 Saint Helier St',
6a488035
TO
629 'county' => 'Marin',
630 'country' => 'United States',
631 'state_province' => 'Michigan',
632 'supplemental_address_1' => 'Hallmark Ct',
633 'supplemental_address_2' => 'Jersey Village',
e0efd2d0 634 'postal_code' => '90210',
b29f74b6 635 'city' => 'Gotham City',
636 'is_billing' => 0,
6a488035
TO
637 ),
638 'api.phone.create' => array(
639 'location_type_id' => '1',
640 'phone' => '021 512 755',
641 'phone_type_id' => '1',
642 'is_primary' => '1',
643 ),
e0efd2d0 644 ), $params
6a488035
TO
645 );
646
e0efd2d0 647 $contactID = $this->individualCreate($contactParams);
9dec4e61 648 $this->_createIndividualProfile();
6a488035 649 // expected result of above created profile with contact Id $contactId
e0efd2d0 650 $profileData[$contactID] = array(
6a488035
TO
651 'first_name' => 'abc1',
652 'last_name' => 'xyz1',
653 'email-Primary' => 'abc1.xyz1@yahoo.com',
654 'phone-1-1' => '021 512 755',
655 'country-1' => '1228',
656 'state_province-1' => '1021',
657 );
658
659 return $profileData;
660 }
661
662 function _createContactWithActivity() {
663 // @TODO: Create profile with custom fields
664 $op = new PHPUnit_Extensions_Database_Operation_Insert();
665 $op->execute($this->_dbconn,
666 new PHPUnit_Extensions_Database_DataSet_FlatXMLDataSet(
667 dirname(__FILE__) . '/dataset/uf_group_contact_activity_26.xml'
668 )
669 );
670 // hack: xml data set do not accept \ 1 (CRM_Core_DAO::VALUE_SEPARATOR)
671 CRM_Core_DAO::setFieldValue('CRM_Core_DAO_UFGroup', '26', 'group_type', 'Individual,Contact,Activity' . CRM_Core_DAO::VALUE_SEPARATOR . 'ActivityType:1');
672
673 $sourceContactId = $this->individualCreate();
674 $contactParams = array(
675 'first_name' => 'abc1',
676 'last_name' => 'xyz1',
677 'contact_type' => 'Individual',
678 'email' => 'abc1.xyz1@yahoo.com',
6a488035
TO
679 'api.address.create' => array(
680 'location_type_id' => 1,
681 'is_primary' => 1,
682 'name' => 'Saint Helier St',
683 'county' => 'Marin',
684 'country' => 'United States',
685 'state_province' => 'Michigan',
686 'supplemental_address_1' => 'Hallmark Ct',
687 'supplemental_address_2' => 'Jersey Village',
688 ),
689 );
690
7fbb4198 691 $contact = $this->callAPISuccess('contact', 'create', $contactParams);
6a488035
TO
692
693 $keys = array_keys($contact['values']);
694 $contactId = array_pop($keys);
695
696 $this->assertEquals(0, $contact['values'][$contactId]['api.address.create']['is_error'], "In line " . __LINE__ . " error message: " . CRM_Utils_Array::value('error_message', $contact['values'][$contactId]['api.address.create'])
697 );
698
699 $activityParams = array(
700 'source_contact_id' => $sourceContactId,
701 'assignee_contact_id' => $contactId,
702 'activity_type_id' => '1',
703 'subject' => 'Make-it-Happen Meeting',
704 'activity_date_time' => '20110316',
705 'duration' => '120',
706 'location' => 'Pensulvania',
707 'details' => 'a test activity',
708 'status_id' => '1',
6a488035
TO
709 'priority_id' => '1',
710 );
7fbb4198 711 $activity = $this->callAPISuccess('activity', 'create', $activityParams);
6a488035
TO
712
713 $activityValues = array_pop($activity['values']);
714
715 // valid parameters for above profile
716 $profileParams = array(
717 'profile_id' => 26,
718 'contact_id' => $contactId,
719 'activity_id' => $activityValues['id'],
7fbb4198 720 );
6a488035
TO
721
722 // expected result of above created profile
723 $expected = array(
724 'first_name' => 'abc1',
725 'last_name' => 'xyz1',
726 'email-Primary' => 'abc1.xyz1@yahoo.com',
727 'activity_subject' => 'Make-it-Happen Meeting',
728 'activity_details' => 'a test activity',
729 'activity_duration' => '120',
730 'activity_date_time_time' => '12:00AM',
731 'activity_date_time' => '03/16/2011',
732 'activity_status_id' => '1',
733 );
734
735 return array($profileParams, $expected);
736 }
9dec4e61 737 /**
738 * Create a profile
739 */
740 function _createIndividualProfile() {
741 // Create new profile having group_type: Contact,Individual
742 $op = new PHPUnit_Extensions_Database_Operation_Insert();
743 $op->execute($this->_dbconn,
744 new PHPUnit_Extensions_Database_DataSet_XMLDataSet(
745 dirname(__FILE__) . "/dataset/uf_group_25.xml"
746 )
747 );
748 // Create Contact + Idividual fields for profile
749 $op = new PHPUnit_Extensions_Database_Operation_Insert();
750 $op->execute($this->_dbconn,
751 new PHPUnit_Extensions_Database_DataSet_XMLDataSet(
752 dirname(__FILE__) . "/dataset/uf_field_uf_group_25.xml"
753 )
754 );
755 $this->_profileID = 25;
756 }
757
758 function _addCustomFieldToProfile($profileID) {
759 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, '');
760 $this->uFFieldCreate(array('uf_group_id' => $profileID, 'field_name' => 'custom_' . $ids['custom_field_id'], 'contact_type' => 'Contact'));
761 }
6a488035
TO
762}
763