Merge pull request #1636 from pratik-joshi/CRM-13380
[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 = 0;
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 $this->createLoggedInUser();
57 }
58
59 function tearDown() {
60
61 $this->quickCleanup(array(
62 'civicrm_contact',
63 'civicrm_phone',
64 'civicrm_address',
65 ), TRUE);
66 // ok can't be bothered wring an api to do this & truncating is crazy
67 CRM_Core_DAO::executeQuery(" DELETE FROM civicrm_uf_group WHERE id IN ($this->_profileID, 26)");
68 }
69
70 ////////////// test $this->callAPISuccess3_profile_get //////////////////
71
72 /**
73 * check Without ProfileId
74 */
75 function testProfileGetWithoutProfileId() {
76 $params = array(
77 'contact_id' => 1,
78 );
79 $result = $this->callAPIFailure('profile', 'get', $params,
80 'Mandatory key(s) missing from params array: profile_id'
81 );
82 }
83
84 /**
85 * check with no invalid profile Id
86 */
87 function testProfileGetInvalidProfileId() {
88 $params = array(
89 'contact_id' => 1,
90 'profile_id' => 1000,
91 );
92 $result = $this->callAPIFailure('profile', 'get', $params);
93 }
94
95 /**
96 * check with success
97 */
98 function testProfileGet() {
99 $pofileFieldValues = $this->_createIndividualContact();
100 $expected = current($pofileFieldValues);
101 $contactId = key($pofileFieldValues);
102 $params = array(
103 'profile_id' => $this->_profileID,
104 'contact_id' => $contactId,
105 );
106 $result = $this->callAPISuccess('profile', 'get', $params);
107 foreach ($expected as $profileField => $value) {
108 $this->assertEquals($value, CRM_Utils_Array::value($profileField, $result['values']));
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($this->_profileID, 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'][$this->_profileID]), " 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($this->_profileID, 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($this->_profileID, 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' => $this->_profileID), __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-primary']['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' => $this->_profileID, 'contact_id' => $contactId),
395 $updateParams
396 );
397
398 $result = $this->callAPIFailure('profile', 'submit', $params,
399 "Missing required parameters for profile id $this->_profileID: 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' => $this->_profileID,
422 'contact_id' => $contactId,
423 ), $updateParams);
424
425 $result = $this->callAPIAndDocument('profile', 'submit', $params, __FUNCTION__, __FILE__);
426
427 $getParams = array(
428 'profile_id' => $this->_profileID,
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']), "missing/mismatching value for {$profileField}"
435 );
436 }
437 unset($params['email-primary']);
438 $params['email-Primary'] = 'my@mail.com';
439 $this->callAPISuccess('profile', 'submit', $params);
440 $profileDetails = $this->callAPISuccess('profile', 'get', $getParams);
441 $this->assertEquals('my@mail.com', $profileDetails['values']['email-Primary']);
442 }
443
444 /**
445 * set is deprecated but we need to ensure it still works
446 */
447 function testLegacySet() {
448 $pofileFieldValues = $this->_createIndividualContact();
449 current($pofileFieldValues);
450 $contactId = key($pofileFieldValues);
451
452 $updateParams = array(
453 'first_name' => 'abc2',
454 'last_name' => 'xyz2',
455 'email-Primary' => 'abc2.xyz2@gmail.com',
456 'phone-1-1' => '022 321 826',
457 'country-1' => '1013',
458 'state_province-1' => '1000',
459 );
460
461 $params = array_merge(array(
462 'profile_id' => $this->_profileID,
463 'contact_id' => $contactId,
464 ), $updateParams);
465
466 $result = $this->callAPISuccess('profile', 'set', $params);
467 $this->assertArrayKeyExists('values', $result);
468 $getParams = array(
469 'profile_id' => $this->_profileID,
470 'contact_id' => $contactId,
471 );
472 $profileDetails = $this->callAPISuccess('profile', 'get', $getParams);
473
474 foreach ($updateParams as $profileField => $value) {
475 $this->assertEquals($value, CRM_Utils_Array::value($profileField, $profileDetails['values']), "In line " . __LINE__ . " error message: " . "missing/mismatching value for {$profileField}"
476 );
477 }
478 }
479 /*
480 * check contact activity profile without activity id
481 */
482 function testContactActivitySubmitWithoutActivityId() {
483 list($params, $expected) = $this->_createContactWithActivity();
484
485 $params = array_merge($params, $expected);
486 unset($params['activity_id']);
487 $result = $this->callAPIFailure('profile', 'submit', $params);
488 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: activity_id');
489 }
490
491 /*
492 * check contact activity profile wrong activity id
493 */
494 function testContactActivitySubmitWrongActivityId() {
495 list($params, $expected) = $this->_createContactWithActivity();
496 $params = array_merge($params, $expected);
497 $params['activity_id'] = 100001;
498 $result = $this->callAPIFailure('profile', 'submit', $params);
499 $this->assertEquals($result['error_message'], 'Invalid Activity Id (aid).');
500 }
501
502 /*
503 * check contact activity profile with wrong activity type
504 */
505 function testContactActivitySubmitWrongActivityType() {
506 //flush cache by calling with reset
507 $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, TRUE, 'name', TRUE);
508
509 $sourceContactId = $this->householdCreate();
510
511 $activityparams = array(
512 'source_contact_id' => $sourceContactId,
513 'activity_type_id' => '2',
514 'subject' => 'Test activity',
515 'activity_date_time' => '20110316',
516 'duration' => '120',
517 'location' => 'Pensulvania',
518 'details' => 'a test activity',
519 'status_id' => '1',
520 'priority_id' => '1',
521 );
522
523 $activity = $this->callAPISuccess('activity', 'create', $activityparams);
524
525 $activityValues = array_pop($activity['values']);
526
527 list($params, $expected) = $this->_createContactWithActivity();
528
529 $params = array_merge($params, $expected);
530 $params['activity_id'] = $activityValues['id'];
531 $result = $this->callAPIFailure('profile', 'submit', $params,
532 'This activity cannot be edited or viewed via this profile.');
533 }
534
535 /*
536 * check contact activity profile with success
537 */
538 function testContactActivitySubmitSuccess() {
539 list($params, $expected) = $this->_createContactWithActivity();
540
541 $updateParams = array(
542 'first_name' => 'abc2',
543 'last_name' => 'xyz2',
544 'email-Primary' => 'abc2.xyz2@yahoo.com',
545 'activity_subject' => 'Test Meeting',
546 'activity_details' => 'a test activity details',
547 'activity_duration' => '100',
548 'activity_date_time' => '03/08/2010',
549 'activity_status_id' => '2',
550 );
551 $profileParams = array_merge($params, $updateParams);
552 $this->callAPISuccess('profile', 'submit', $profileParams);
553 $result = $this->callAPISuccess('profile', 'get', $params);
554
555 foreach ($updateParams as $profileField => $value) {
556 $this->assertEquals($value, CRM_Utils_Array::value($profileField, $result['values']), "In line " . __LINE__ . " error message: " . "missing/mismatching value for {$profileField}"
557 );
558 }
559 }
560
561 /**
562 * check profile apply Without ProfileId
563 */
564 function testProfileApplyWithoutProfileId() {
565 $params = array(
566 'contact_id' => 1,
567 );
568 $result = $this->callAPIFailure('profile', 'apply', $params,
569 'Mandatory key(s) missing from params array: profile_id');
570 }
571
572 /**
573 * check profile apply with no invalid profile Id
574 */
575 function testProfileApplyInvalidProfileId() {
576 $params = array(
577 'contact_id' => 1,
578 'profile_id' => 1000,
579 );
580 $result = $this->callAPIFailure('profile', 'apply', $params);
581 }
582
583 /**
584 * check with success
585 */
586 function testProfileApply() {
587 $pofileFieldValues = $this->_createIndividualContact();
588 current($pofileFieldValues);
589 $contactId = key($pofileFieldValues);
590
591 $params = array(
592 'profile_id' => $this->_profileID,
593 'contact_id' => $contactId,
594 'first_name' => 'abc2',
595 'last_name' => 'xyz2',
596 'email-Primary' => 'abc2.xyz2@gmail.com',
597 'phone-1-1' => '022 321 826',
598 'country-1' => '1013',
599 'state_province-1' => '1000',
600 );
601
602 $result = $this->callAPIAndDocument('profile', 'apply', $params, __FUNCTION__, __FILE__);
603
604 // Expected field values
605 $expected['contact'] = array(
606 'contact_id' => $contactId,
607 'contact_type' => 'Individual',
608 'first_name' => 'abc2',
609 'last_name' => 'xyz2',
610 );
611 $expected['email'] = array(
612 'location_type_id' => 1,
613 'is_primary' => 1,
614 'email' => 'abc2.xyz2@gmail.com',
615 );
616
617 $expected['phone'] = array(
618 'location_type_id' => 1,
619 'is_primary' => 1,
620 'phone_type_id' => 1,
621 'phone' => '022 321 826',
622 );
623 $expected['address'] = array(
624 'location_type_id' => 1,
625 'is_primary' => 1,
626 'country_id' => 1013,
627 'state_province_id' => 1000,
628 );
629
630 foreach ($expected['contact'] as $field => $value) {
631 $this->assertEquals($value, CRM_Utils_Array::value($field, $result['values']), "In line " . __LINE__ . " error message: " . "missing/mismatching value for {$field}"
632 );
633 }
634
635 foreach (array(
636 'email', 'phone', 'address') as $fieldType) {
637 $typeValues = array_pop($result['values'][$fieldType]);
638 foreach ($expected[$fieldType] as $field => $value) {
639 $this->assertEquals($value, CRM_Utils_Array::value($field, $typeValues), "In line " . __LINE__ . " error message: " . "missing/mismatching value for {$field} ({$fieldType})"
640 );
641 }
642 }
643 }
644
645 /*
646 * Helper function to create an Individual with address/email/phone info. Import UF Group and UF Fields
647 */
648 function _createIndividualContact($params = array()) {
649 $contactParams = array_merge(array(
650 'first_name' => 'abc1',
651 'last_name' => 'xyz1',
652 'email' => 'abc1.xyz1@yahoo.com',
653 'api.address.create' => array(
654 'location_type_id' => 1,
655 'is_primary' => 1,
656 'street_address' => '5 Saint Helier St',
657 'county' => 'Marin',
658 'country' => 'United States',
659 'state_province' => 'Michigan',
660 'supplemental_address_1' => 'Hallmark Ct',
661 'supplemental_address_2' => 'Jersey Village',
662 'postal_code' => '90210',
663 'city' => 'Gotham City',
664 'is_billing' => 0,
665 ),
666 'api.phone.create' => array(
667 'location_type_id' => '1',
668 'phone' => '021 512 755',
669 'phone_type_id' => '1',
670 'is_primary' => '1',
671 ),
672 ), $params
673 );
674
675 $contactID = $this->individualCreate($contactParams);
676 $this->_createIndividualProfile();
677 // expected result of above created profile with contact Id $contactId
678 $profileData[$contactID] = array(
679 'first_name' => 'abc1',
680 'last_name' => 'xyz1',
681 'email-primary' => 'abc1.xyz1@yahoo.com',
682 'phone-1-1' => '021 512 755',
683 'country-1' => '1228',
684 'state_province-1' => '1021',
685 );
686
687 return $profileData;
688 }
689
690 function _createContactWithActivity() {
691 // @TODO: Create profile with custom fields
692 $op = new PHPUnit_Extensions_Database_Operation_Insert();
693 $op->execute($this->_dbconn,
694 new PHPUnit_Extensions_Database_DataSet_FlatXMLDataSet(
695 dirname(__FILE__) . '/dataset/uf_group_contact_activity_26.xml'
696 )
697 );
698 // hack: xml data set do not accept \ 1 (CRM_Core_DAO::VALUE_SEPARATOR)
699 CRM_Core_DAO::setFieldValue('CRM_Core_DAO_UFGroup', '26', 'group_type', 'Individual,Contact,Activity' . CRM_Core_DAO::VALUE_SEPARATOR . 'ActivityType:1');
700
701 $sourceContactId = $this->individualCreate();
702 $contactParams = array(
703 'first_name' => 'abc1',
704 'last_name' => 'xyz1',
705 'contact_type' => 'Individual',
706 'email' => 'abc1.xyz1@yahoo.com',
707 'api.address.create' => array(
708 'location_type_id' => 1,
709 'is_primary' => 1,
710 'name' => 'Saint Helier St',
711 'county' => 'Marin',
712 'country' => 'United States',
713 'state_province' => 'Michigan',
714 'supplemental_address_1' => 'Hallmark Ct',
715 'supplemental_address_2' => 'Jersey Village',
716 ),
717 );
718
719 $contact = $this->callAPISuccess('contact', 'create', $contactParams);
720
721 $keys = array_keys($contact['values']);
722 $contactId = array_pop($keys);
723
724 $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'])
725 );
726
727 $activityParams = array(
728 'source_contact_id' => $sourceContactId,
729 'assignee_contact_id' => $contactId,
730 'activity_type_id' => '1',
731 'subject' => 'Make-it-Happen Meeting',
732 'activity_date_time' => '20110316',
733 'duration' => '120',
734 'location' => 'Pensulvania',
735 'details' => 'a test activity',
736 'status_id' => '1',
737 'priority_id' => '1',
738 );
739 $activity = $this->callAPISuccess('activity', 'create', $activityParams);
740
741 $activityValues = array_pop($activity['values']);
742
743 // valid parameters for above profile
744 $profileParams = array(
745 'profile_id' => 26,
746 'contact_id' => $contactId,
747 'activity_id' => $activityValues['id'],
748 );
749
750 // expected result of above created profile
751 $expected = array(
752 'first_name' => 'abc1',
753 'last_name' => 'xyz1',
754 'email-Primary' => 'abc1.xyz1@yahoo.com',
755 'activity_subject' => 'Make-it-Happen Meeting',
756 'activity_details' => 'a test activity',
757 'activity_duration' => '120',
758 'activity_date_time_time' => '12:00AM',
759 'activity_date_time' => '03/16/2011',
760 'activity_status_id' => '1',
761 );
762
763 return array($profileParams, $expected);
764 }
765 /**
766 * Create a profile
767 */
768 function _createIndividualProfile() {
769
770 // creating these via the api as we want to utilise & test the flushing of caches when fields created
771 // via the api
772
773 $ufGroupParams = array(
774 'group_type' => 'Individual,Contact',// really we should remove this & test the ufField create sets it
775 'name' => 'test_individual_contact_profile',
776 'title' => 'Flat Coffee',
777 'api.uf_field.create' => array(
778 array(
779 'field_name' => 'first_name',
780 'is_required' => 1,
781 'visibility' => 'Public Pages and Listings',
782 'field_type' => 'Individual',
783 //is_active = 1, is_view 0, weight SHOULD be set by api (& tested), ditto is_reserved 0
784 ),
785 array(
786 'field_name' => 'last_name',
787 'is_required' => 1,
788 'visibility' => 'Public Pages and Listings',
789 'field_type' => 'Individual',
790 ),
791 array(
792 'field_name' => 'email',
793 'is_required' => 1,
794 'visibility' => 'Public Pages and Listings',
795 'field_type' => 'Contact',
796 'label' => 'Email',
797 ),
798 array(
799 'field_name' => 'phone',
800 'is_required' => 1,
801 'visibility' => 'Public Pages and Listings',
802 'field_type' => 'Contact',
803 'location_type_id' => 1,
804 'phone_type_id' => 1,
805 'label' => 'Phone'
806 ),
807 array(
808 'field_name' => 'country',
809 'is_required' => 1,
810 'visibility' => 'Public Pages and Listings',
811 'field_type' => 'Contact',
812 'location_type_id' => 1,
813 'label' => 'Country'
814 ),
815 array(
816 'field_name' => 'state_province',
817 'is_required' => 1,
818 'visibility' => 'Public Pages and Listings',
819 'field_type' => 'Contact',
820 'location_type_id' => 1,
821 'label' => 'State Province'
822 ),
823 array(
824 'field_name' => 'postal_code',
825 'is_required' => 0,
826 'field_type' => 'Contact',
827 'location_type_id' => 1,
828 'label' => 'State Province'
829 ),
830 ),
831 );
832 $profile = $this->callAPISuccess('uf_group', 'create', $ufGroupParams);
833 $this->_profileID = $profile['id'];
834 }
835
836 function _addCustomFieldToProfile($profileID) {
837 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, '');
838 $this->uFFieldCreate(array('uf_group_id' => $profileID, 'field_name' => 'custom_' . $ids['custom_field_id'], 'contact_type' => 'Contact'));
839 }
840 }
841