Merge branch 'CRM-13187' of git://github.com/vivekarora/civicrm-core into vivekarora...
[civicrm-core.git] / tests / phpunit / api / v3 / ProfileTest.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.4 |
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 */
28
29 /**
30 * Include class definitions
31 */
32 require_once 'tests/phpunit/CiviTest/CiviUnitTestCase.php';
33
34 /**
35 * Test APIv3 civicrm_profile_* functions
36 *
37 * @package CiviCRM
38 */
39 class api_v3_ProfileTest extends CiviUnitTestCase {
40 protected $_apiversion;
41 protected $_profileID;
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() {
59
60 $this->quickCleanup(array(
61 'civicrm_contact',
62 'civicrm_phone',
63 'civicrm_address',
64 ), TRUE);
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)');
67 }
68
69 ////////////// test $this->callAPISuccess3_profile_get //////////////////
70
71 /**
72 * check Without ProfileId
73 */
74 function testProfileGetWithoutProfileId() {
75 $params = array(
76 'contact_id' => 1,
77 );
78 $result = $this->callAPIFailure('profile', 'get', $params,
79 'Mandatory key(s) missing from params array: profile_id'
80 );
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,
90 );
91 $result = $this->callAPIFailure('profile', 'get', $params);
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,
104 );
105 $result = $this->callAPISuccess('profile', 'get', $params);
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 }
110 }
111
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',
129 'billing_middle_name' => 'J.',
130 'billing_last_name' => 'xyz1',
131 'billing_street_address-5' => '5 Saint Helier St',
132 'billing_city-5' => 'Gotham City',
133 'billing_state_province_id-5' => '1021',
134 'billing_country_id-5' => '1228',
135 'billing-email-5' => 'abc1.xyz1@yahoo.com',
136 'billing_postal_code-5' => '90210',
137 'billing-email-5' => 'abc1.xyz1@yahoo.com',
138 'email-5' => 'abc1.xyz1@yahoo.com',
139 ));
140 }
141
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
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',
192 'billing_middle_name' => 'J.',
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',
199 'email-5' => 'big@once.com',
200 'billing_postal_code-5' => '',
201 ));
202 }
203
204 /**
205 * get Billing empty contact - this will return generic defaults
206 */
207 function testProfileGetBillingEmptyContact() {
208
209 $params = array(
210 'profile_id' => array('Billing'),
211 );
212
213 $result = $this->callAPISuccess('profile', 'get', $params);
214 $this->assertEquals(array(
215 'billing_first_name' => '',
216 'billing_middle_name' => '',
217 'billing_last_name' => '',
218 'billing_street_address-5' => '',
219 'billing_city-5' => '',
220 'billing_state_province_id-5' => '',
221 'billing_country_id-5' => '1228',
222 'billing_email-5' => '',
223 'email-5' => '',
224 'billing_postal_code-5' => '',
225 ), $result['values']['Billing']);
226 }
227
228 /**
229 * check contact activity profile without activity id
230 */
231 function testContactActivityGetWithoutActivityId() {
232 list($params, $expected) = $this->_createContactWithActivity();
233
234 unset($params['activity_id']);
235 $result = $this->callAPIFailure('profile', 'get', $params,
236 'Mandatory key(s) missing from params array: activity_id');
237 }
238
239 /**
240 * check contact activity profile wrong activity id
241 */
242 function testContactActivityGetWrongActivityId() {
243 list($params, $expected) = $this->_createContactWithActivity();
244
245 $params['activity_id'] = 100001;
246 $result = $this->callAPIFailure('profile', 'get', $params,
247 'Invalid Activity Id (aid).');
248 }
249
250 /*
251 * check contact activity profile with wrong activity type
252 */
253 function testContactActivityGetWrongActivityType() {
254 //flush cache by calling with reset
255 $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, TRUE, 'name', TRUE);
256
257 $sourceContactId = $this->householdCreate();
258
259 $activityparams = array(
260 'source_contact_id' => $sourceContactId,
261 'activity_type_id' => '2',
262 'subject' => 'Test activity',
263 'activity_date_time' => '20110316',
264 'duration' => '120',
265 'location' => 'Pensulvania',
266 'details' => 'a test activity',
267 'status_id' => '1',
268 'priority_id' => '1',
269 );
270
271 $activity = $this->callAPISuccess('activity', 'create', $activityparams);
272
273 $activityValues = array_pop($activity['values']);
274
275 list($params, $expected) = $this->_createContactWithActivity();
276
277 $params['activity_id'] = $activityValues['id'];
278 $result = $this->callAPIFailure('profile', 'get', $params,
279 'This activity cannot be edited or viewed via this profile.'
280 );
281 }
282
283 /*
284 * check contact activity profile with success
285 */
286 function testContactActivityGetSuccess() {
287 list($params, $expected) = $this->_createContactWithActivity();
288
289 $result = $this->callAPISuccess('profile', 'get', $params);
290
291 foreach ($expected as $profileField => $value) {
292 $this->assertEquals($value, CRM_Utils_Array::value($profileField, $result['values']), "In line " . __LINE__ . " error message: " . "missing/mismatching value for {$profileField}"
293 );
294 }
295 }
296
297 /**
298 * Check getfields works & gives us our fields
299 */
300 function testGetFields() {
301 $this->_createIndividualProfile();
302 $this->_addCustomFieldToProfile($this->_profileID);
303 $result = $this->callAPIAndDocument('profile', 'getfields', array('action' => 'submit', 'profile_id' => 25), __FUNCTION__, __FILE__,
304 'demonstrates retrieving profile fields passing in an id');
305 $this->assertArrayKeyExists('first_name', $result['values']);
306 $this->assertEquals('2', $result['values']['first_name']['type']);
307 $this->assertEquals('Email', $result['values']['email']['title']);
308 $this->assertEquals('civicrm_state_province', $result['values']['state_province-1']['pseudoconstant']['table']);
309 $this->assertEquals('defaultValue', $result['values']['custom_1']['default_value']);
310 $this->assertFalse(array_key_exists('participant_status', $result['values']));
311 }
312 /**
313 * Check getfields works & gives us our fields - partipant profile
314 */
315 function testGetFieldsParticipantProfile() {
316 $result = $this->callAPISuccess('profile', 'getfields', array(
317 'action' => 'submit',
318 'profile_id' => 'participant_status',
319 'get_options' => 'all')
320 );
321 $this->assertTrue(array_key_exists('participant_status', $result['values']));
322 $this->assertEquals('Attended', $result['values']['participant_status']['options'][2]);
323 }
324
325 /**
326 * Check getfields works & gives us our fields - membership_batch_entry
327 * (getting to the end with no e-notices is pretty good evidence it's working)
328 */
329 function testGetFieldsMembershipBatchProfile() {
330 $result = $this->callAPISuccess('profile', 'getfields', array(
331 'action' => 'submit',
332 'profile_id' => 'membership_batch_entry',
333 'get_options' => 'all')
334 );
335 $this->assertTrue(array_key_exists('total_amount', $result['values']));
336 $this->assertEquals(12, $result['values']['receive_date']['type']);
337 }
338
339 /**
340 * Check getfields works & gives us our fields - do them all
341 * (getting to the end with no e-notices is pretty good evidence it's working)
342 */
343 function testGetFieldsAllProfiles() {
344 $result = $this->callAPISuccess('uf_group', 'get', array('return' => 'id'));
345 $profileIDs = array_keys($result['values']);
346 foreach ($profileIDs as $profileID) {
347 $result = $this->callAPISuccess('profile', 'getfields', array(
348 'action' => 'submit',
349 'profile_id' => $profileID,
350 'get_options' => 'all')
351 );
352 }
353 }
354 /////////////// test $this->callAPISuccess3_profile_set //////////////////
355
356 /**
357 * check Without ProfileId
358 */
359 function testProfileSubmitWithoutProfileId() {
360 $params = array(
361 'contact_id' => 1,
362 );
363 $result = $this->callAPIFailure('profile', 'submit', $params,
364 'Mandatory key(s) missing from params array: profile_id'
365 );
366 }
367
368 /**
369 * check with no invalid profile Id
370 */
371 function testProfileSubmitInvalidProfileId() {
372 $params = array(
373 'contact_id' => 1,
374 'profile_id' => 1000,
375 );
376 $result = $this->callAPIFailure('profile', 'submit', $params);
377 }
378
379 /**
380 * check with missing required field in profile
381 */
382 function testProfileSubmitCheckProfileRequired() {
383 $pofileFieldValues = $this->_createIndividualContact();
384 current($pofileFieldValues);
385 $contactId = key($pofileFieldValues);
386 $updateParams = array(
387 'first_name' => 'abc2',
388 'last_name' => 'xyz2',
389 'phone-1-1' => '022 321 826',
390 'country-1' => '1013',
391 'state_province-1' => '1000',
392 );
393
394 $params = array_merge(array('profile_id' => 25, 'contact_id' => $contactId),
395 $updateParams
396 );
397
398 $result = $this->callAPIFailure('profile', 'submit', $params,
399 'Missing required parameters for profile id 25: email-Primary'
400 );
401 }
402
403 /**
404 * check with success
405 */
406 function testProfileSubmit() {
407 $pofileFieldValues = $this->_createIndividualContact();
408 current($pofileFieldValues);
409 $contactId = key($pofileFieldValues);
410
411 $updateParams = array(
412 'first_name' => 'abc2',
413 'last_name' => 'xyz2',
414 'email-Primary' => 'abc2.xyz2@gmail.com',
415 'phone-1-1' => '022 321 826',
416 'country-1' => '1013',
417 'state_province-1' => '1000',
418 );
419
420 $params = array_merge(array(
421 'profile_id' => 25,
422 'contact_id' => $contactId,
423 ), $updateParams);
424
425 $result = $this->callAPIAndDocument('profile', 'submit', $params, __FUNCTION__, __FILE__);
426
427 $getParams = array(
428 'profile_id' => 25,
429 'contact_id' => $contactId,
430 );
431 $profileDetails = $this->callAPISuccess('profile', 'get', $getParams);
432
433 foreach ($updateParams as $profileField => $value) {
434 $this->assertEquals($value, CRM_Utils_Array::value($profileField, $profileDetails['values']), "In line " . __LINE__ . " error message: " . "missing/mismatching value for {$profileField}"
435 );
436 }
437 }
438
439 /**
440 * set is deprecated but we need to ensure it still works
441 */
442 function testLegacySet() {
443 $pofileFieldValues = $this->_createIndividualContact();
444 current($pofileFieldValues);
445 $contactId = key($pofileFieldValues);
446
447 $updateParams = array(
448 'first_name' => 'abc2',
449 'last_name' => 'xyz2',
450 'email-Primary' => 'abc2.xyz2@gmail.com',
451 'phone-1-1' => '022 321 826',
452 'country-1' => '1013',
453 'state_province-1' => '1000',
454 );
455
456 $params = array_merge(array(
457 'profile_id' => 25,
458 'contact_id' => $contactId,
459 ), $updateParams);
460
461 $result = $this->callAPISuccess('profile', 'set', $params);
462 $this->assertArrayKeyExists('values', $result);
463 $getParams = array(
464 'profile_id' => 25,
465 'contact_id' => $contactId,
466 );
467 $profileDetails = $this->callAPISuccess('profile', 'get', $getParams);
468
469 foreach ($updateParams as $profileField => $value) {
470 $this->assertEquals($value, CRM_Utils_Array::value($profileField, $profileDetails['values']), "In line " . __LINE__ . " error message: " . "missing/mismatching value for {$profileField}"
471 );
472 }
473 }
474 /*
475 * check contact activity profile without activity id
476 */
477 function testContactActivitySubmitWithoutActivityId() {
478 list($params, $expected) = $this->_createContactWithActivity();
479
480 $params = array_merge($params, $expected);
481 unset($params['activity_id']);
482 $result = $this->callAPIFailure('profile', 'submit', $params);
483 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: activity_id');
484 }
485
486 /*
487 * check contact activity profile wrong activity id
488 */
489 function testContactActivitySubmitWrongActivityId() {
490 list($params, $expected) = $this->_createContactWithActivity();
491 $params = array_merge($params, $expected);
492 $params['activity_id'] = 100001;
493 $result = $this->callAPIFailure('profile', 'submit', $params);
494 $this->assertEquals($result['error_message'], 'Invalid Activity Id (aid).');
495 }
496
497 /*
498 * check contact activity profile with wrong activity type
499 */
500 function testContactActivitySubmitWrongActivityType() {
501 //flush cache by calling with reset
502 $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, TRUE, 'name', TRUE);
503
504 $sourceContactId = $this->householdCreate();
505
506 $activityparams = array(
507 'source_contact_id' => $sourceContactId,
508 'activity_type_id' => '2',
509 'subject' => 'Test activity',
510 'activity_date_time' => '20110316',
511 'duration' => '120',
512 'location' => 'Pensulvania',
513 'details' => 'a test activity',
514 'status_id' => '1',
515 'priority_id' => '1',
516 );
517
518 $activity = $this->callAPISuccess('activity', 'create', $activityparams);
519
520 $activityValues = array_pop($activity['values']);
521
522 list($params, $expected) = $this->_createContactWithActivity();
523
524 $params = array_merge($params, $expected);
525 $params['activity_id'] = $activityValues['id'];
526 $result = $this->callAPIFailure('profile', 'submit', $params,
527 'This activity cannot be edited or viewed via this profile.');
528 }
529
530 /*
531 * check contact activity profile with success
532 */
533 function testContactActivitySubmitSuccess() {
534 list($params, $expected) = $this->_createContactWithActivity();
535
536 $updateParams = array(
537 'first_name' => 'abc2',
538 'last_name' => 'xyz2',
539 'email-Primary' => 'abc2.xyz2@yahoo.com',
540 'activity_subject' => 'Test Meeting',
541 'activity_details' => 'a test activity details',
542 'activity_duration' => '100',
543 'activity_date_time' => '03/08/2010',
544 'activity_status_id' => '2',
545 );
546 $profileParams = array_merge($params, $updateParams);
547 $profile = $this->callAPISuccess('profile', 'submit', $profileParams);
548 $result = $this->callAPISuccess('profile', 'get', $params);
549
550 foreach ($updateParams as $profileField => $value) {
551 $this->assertEquals($value, CRM_Utils_Array::value($profileField, $result['values']), "In line " . __LINE__ . " error message: " . "missing/mismatching value for {$profileField}"
552 );
553 }
554 }
555
556 /**
557 * check profile apply Without ProfileId
558 */
559 function testProfileApplyWithoutProfileId() {
560 $params = array(
561 'contact_id' => 1,
562 );
563 $result = $this->callAPIFailure('profile', 'apply', $params,
564 'Mandatory key(s) missing from params array: profile_id');
565 }
566
567 /**
568 * check profile apply with no invalid profile Id
569 */
570 function testProfileApplyInvalidProfileId() {
571 $params = array(
572 'contact_id' => 1,
573 'profile_id' => 1000,
574 );
575 $result = $this->callAPIFailure('profile', 'apply', $params);
576 }
577
578 /**
579 * check with success
580 */
581 function testProfileApply() {
582 $pofileFieldValues = $this->_createIndividualContact();
583 current($pofileFieldValues);
584 $contactId = key($pofileFieldValues);
585
586 $params = array(
587 'profile_id' => 25,
588 'contact_id' => $contactId,
589 'first_name' => 'abc2',
590 'last_name' => 'xyz2',
591 'email-Primary' => 'abc2.xyz2@gmail.com',
592 'phone-1-1' => '022 321 826',
593 'country-1' => '1013',
594 'state_province-1' => '1000',
595 );
596
597 $result = $this->callAPIAndDocument('profile', 'apply', $params, __FUNCTION__, __FILE__);
598
599 // Expected field values
600 $expected['contact'] = array(
601 'contact_id' => $contactId,
602 'contact_type' => 'Individual',
603 'first_name' => 'abc2',
604 'last_name' => 'xyz2',
605 );
606 $expected['email'] = array(
607 'location_type_id' => 1,
608 'is_primary' => 1,
609 'email' => 'abc2.xyz2@gmail.com',
610 );
611
612 $expected['phone'] = array(
613 'location_type_id' => 1,
614 'is_primary' => 1,
615 'phone_type_id' => 1,
616 'phone' => '022 321 826',
617 );
618 $expected['address'] = array(
619 'location_type_id' => 1,
620 'is_primary' => 1,
621 'country_id' => 1013,
622 'state_province_id' => 1000,
623 );
624
625 foreach ($expected['contact'] as $field => $value) {
626 $this->assertEquals($value, CRM_Utils_Array::value($field, $result['values']), "In line " . __LINE__ . " error message: " . "missing/mismatching value for {$field}"
627 );
628 }
629
630 foreach (array(
631 'email', 'phone', 'address') as $fieldType) {
632 $typeValues = array_pop($result['values'][$fieldType]);
633 foreach ($expected[$fieldType] as $field => $value) {
634 $this->assertEquals($value, CRM_Utils_Array::value($field, $typeValues), "In line " . __LINE__ . " error message: " . "missing/mismatching value for {$field} ({$fieldType})"
635 );
636 }
637 }
638 }
639
640 /*
641 * Helper function to create an Individual with address/email/phone info. Import UF Group and UF Fields
642 */
643 function _createIndividualContact($params = array()) {
644 $contactParams = array_merge(array(
645 'first_name' => 'abc1',
646 'last_name' => 'xyz1',
647 'email' => 'abc1.xyz1@yahoo.com',
648 'api.address.create' => array(
649 'location_type_id' => 1,
650 'is_primary' => 1,
651 'street_address' => '5 Saint Helier St',
652 'county' => 'Marin',
653 'country' => 'United States',
654 'state_province' => 'Michigan',
655 'supplemental_address_1' => 'Hallmark Ct',
656 'supplemental_address_2' => 'Jersey Village',
657 'postal_code' => '90210',
658 'city' => 'Gotham City',
659 'is_billing' => 0,
660 ),
661 'api.phone.create' => array(
662 'location_type_id' => '1',
663 'phone' => '021 512 755',
664 'phone_type_id' => '1',
665 'is_primary' => '1',
666 ),
667 ), $params
668 );
669
670 $contactID = $this->individualCreate($contactParams);
671 $this->_createIndividualProfile();
672 // expected result of above created profile with contact Id $contactId
673 $profileData[$contactID] = array(
674 'first_name' => 'abc1',
675 'last_name' => 'xyz1',
676 'email-Primary' => 'abc1.xyz1@yahoo.com',
677 'phone-1-1' => '021 512 755',
678 'country-1' => '1228',
679 'state_province-1' => '1021',
680 );
681
682 return $profileData;
683 }
684
685 function _createContactWithActivity() {
686 // @TODO: Create profile with custom fields
687 $op = new PHPUnit_Extensions_Database_Operation_Insert();
688 $op->execute($this->_dbconn,
689 new PHPUnit_Extensions_Database_DataSet_FlatXMLDataSet(
690 dirname(__FILE__) . '/dataset/uf_group_contact_activity_26.xml'
691 )
692 );
693 // hack: xml data set do not accept \ 1 (CRM_Core_DAO::VALUE_SEPARATOR)
694 CRM_Core_DAO::setFieldValue('CRM_Core_DAO_UFGroup', '26', 'group_type', 'Individual,Contact,Activity' . CRM_Core_DAO::VALUE_SEPARATOR . 'ActivityType:1');
695
696 $sourceContactId = $this->individualCreate();
697 $contactParams = array(
698 'first_name' => 'abc1',
699 'last_name' => 'xyz1',
700 'contact_type' => 'Individual',
701 'email' => 'abc1.xyz1@yahoo.com',
702 'api.address.create' => array(
703 'location_type_id' => 1,
704 'is_primary' => 1,
705 'name' => 'Saint Helier St',
706 'county' => 'Marin',
707 'country' => 'United States',
708 'state_province' => 'Michigan',
709 'supplemental_address_1' => 'Hallmark Ct',
710 'supplemental_address_2' => 'Jersey Village',
711 ),
712 );
713
714 $contact = $this->callAPISuccess('contact', 'create', $contactParams);
715
716 $keys = array_keys($contact['values']);
717 $contactId = array_pop($keys);
718
719 $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'])
720 );
721
722 $activityParams = array(
723 'source_contact_id' => $sourceContactId,
724 'assignee_contact_id' => $contactId,
725 'activity_type_id' => '1',
726 'subject' => 'Make-it-Happen Meeting',
727 'activity_date_time' => '20110316',
728 'duration' => '120',
729 'location' => 'Pensulvania',
730 'details' => 'a test activity',
731 'status_id' => '1',
732 'priority_id' => '1',
733 );
734 $activity = $this->callAPISuccess('activity', 'create', $activityParams);
735
736 $activityValues = array_pop($activity['values']);
737
738 // valid parameters for above profile
739 $profileParams = array(
740 'profile_id' => 26,
741 'contact_id' => $contactId,
742 'activity_id' => $activityValues['id'],
743 );
744
745 // expected result of above created profile
746 $expected = array(
747 'first_name' => 'abc1',
748 'last_name' => 'xyz1',
749 'email-Primary' => 'abc1.xyz1@yahoo.com',
750 'activity_subject' => 'Make-it-Happen Meeting',
751 'activity_details' => 'a test activity',
752 'activity_duration' => '120',
753 'activity_date_time_time' => '12:00AM',
754 'activity_date_time' => '03/16/2011',
755 'activity_status_id' => '1',
756 );
757
758 return array($profileParams, $expected);
759 }
760 /**
761 * Create a profile
762 */
763 function _createIndividualProfile() {
764 // Create new profile having group_type: Contact,Individual
765 $op = new PHPUnit_Extensions_Database_Operation_Insert();
766 $op->execute($this->_dbconn,
767 new PHPUnit_Extensions_Database_DataSet_XMLDataSet(
768 dirname(__FILE__) . "/dataset/uf_group_25.xml"
769 )
770 );
771 // Create Contact + Idividual fields for profile
772 $op = new PHPUnit_Extensions_Database_Operation_Insert();
773 $op->execute($this->_dbconn,
774 new PHPUnit_Extensions_Database_DataSet_XMLDataSet(
775 dirname(__FILE__) . "/dataset/uf_field_uf_group_25.xml"
776 )
777 );
778 $this->_profileID = 25;
779 }
780
781 function _addCustomFieldToProfile($profileID) {
782 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, '');
783 $this->uFFieldCreate(array('uf_group_id' => $profileID, 'field_name' => 'custom_' . $ids['custom_field_id'], 'contact_type' => 'Contact'));
784 }
785 }
786