profile api test fixes (caching & case on entities)
[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 protected $_membershipTypeID;
43 protected $_contactID;
44 function get_info() {
45 return array(
46 'name' => 'Profile Test',
47 'description' => 'Test all profile API methods.',
48 'group' => 'CiviCRM API Tests',
49 );
50 }
51
52 function setUp() {
53 $this->_apiversion = 3;
54 parent::setUp();
55 $config = CRM_Core_Config::singleton();
56 $config->countryLimit[1] = 1013;
57 $config->stateLimit[1] = 1013;
58 $this->createLoggedInUser();
59 $this->_membershipTypeID = $this->membershipTypeCreate();
60 }
61
62 function tearDown() {
63
64 $this->quickCleanup(array(
65 'civicrm_contact',
66 'civicrm_phone',
67 'civicrm_address',
68 'civicrm_membership',
69 'civicrm_contribution',
70 ), TRUE);
71 $this->callAPISuccess('membership_type', 'delete', array('id' => $this->_membershipTypeID));
72 // ok can't be bothered wring an api to do this & truncating is crazy
73 CRM_Core_DAO::executeQuery(" DELETE FROM civicrm_uf_group WHERE id IN ($this->_profileID, 26)");
74 }
75
76 ////////////// test $this->callAPISuccess3_profile_get //////////////////
77
78 /**
79 * check Without ProfileId
80 */
81 function testProfileGetWithoutProfileId() {
82 $params = array(
83 'contact_id' => 1,
84 );
85 $result = $this->callAPIFailure('profile', 'get', $params,
86 'Mandatory key(s) missing from params array: profile_id'
87 );
88 }
89
90 /**
91 * check with no invalid profile Id
92 */
93 function testProfileGetInvalidProfileId() {
94 $params = array(
95 'contact_id' => 1,
96 'profile_id' => 1000,
97 );
98 $result = $this->callAPIFailure('profile', 'get', $params);
99 }
100
101 /**
102 * check with success
103 */
104 function testProfileGet() {
105 $pofileFieldValues = $this->_createIndividualContact();
106 $expected = current($pofileFieldValues);
107 $contactId = key($pofileFieldValues);
108 $params = array(
109 'profile_id' => $this->_profileID,
110 'contact_id' => $contactId,
111 );
112 $result = $this->callAPISuccess('profile', 'get', $params);
113 foreach ($expected as $profileField => $value) {
114 $this->assertEquals($value, CRM_Utils_Array::value($profileField, $result['values']));
115 }
116 }
117
118 function testProfileGetMultiple() {
119 $pofileFieldValues = $this->_createIndividualContact();
120 $expected = current($pofileFieldValues);
121 $contactId = key($pofileFieldValues);
122 $params = array(
123 'profile_id' => array($this->_profileID, 1, 'Billing'),
124 'contact_id' => $contactId,
125 );
126
127 $result = $this->callAPIAndDocument('profile', 'get', $params, __FUNCTION__, __FILE__);
128 foreach ($expected as $profileField => $value) {
129 $this->assertEquals($value, CRM_Utils_Array::value($profileField, $result['values'][$this->_profileID]), " error message: " . "missing/mismatching value for {$profileField}");
130 }
131 $this->assertEquals('abc1', $result['values'][1]['first_name'], " error message: " . "missing/mismatching value for {$profileField}");
132 $this->assertFalse(array_key_exists('email-Primary', $result['values'][1]), 'profile 1 doesn not include email');
133 $this->assertEquals($result['values']['Billing'], array(
134 'billing_first_name' => 'abc1',
135 'billing_middle_name' => 'J.',
136 'billing_last_name' => 'xyz1',
137 'billing_street_address-5' => '5 Saint Helier St',
138 'billing_city-5' => 'Gotham City',
139 'billing_state_province_id-5' => '1021',
140 'billing_country_id-5' => '1228',
141 'billing-email-5' => 'abc1.xyz1@yahoo.com',
142 'billing_postal_code-5' => '90210',
143 'billing-email-5' => 'abc1.xyz1@yahoo.com',
144 'email-5' => 'abc1.xyz1@yahoo.com',
145 ));
146 }
147
148 function testProfileGetBillingUseIsBillingLocation() {
149 $individual = $this->_createIndividualContact();
150 $contactId = key($individual);
151 $this->callAPISuccess('address', 'create', array(
152 'is_billing' => 1,
153 'street_address' => 'is billing st',
154 'location_type_id' => 2,
155 'contact_id' => $contactId,
156 ));
157
158 $expected = current($individual);
159
160 $params = array(
161 'profile_id' => array($this->_profileID, 1, 'Billing'),
162 'contact_id' => $contactId,
163 );
164
165 $result = $this->callAPISuccess('profile', 'get', $params);
166 $this->assertEquals('abc1', $result['values'][1]['first_name']);
167 $this->assertEquals(array(
168 'billing_first_name' => 'abc1',
169 'billing_middle_name' => 'J.',
170 'billing_last_name' => 'xyz1',
171 'billing_street_address-5' => 'is billing st',
172 'billing_city-5' => '',
173 'billing_state_province_id-5' => '',
174 'billing_country_id-5' => '',
175 'billing-email-5' => 'abc1.xyz1@yahoo.com',
176 'email-5' => 'abc1.xyz1@yahoo.com',
177 'billing_postal_code-5' => '',
178 ), $result['values']['Billing']);
179 }
180
181 function testProfileGetMultipleHasBillingLocation() {
182 $individual = $this->_createIndividualContact();
183 $contactId = key($individual);
184 $this->callAPISuccess('address', 'create', array('contact_id' => $contactId , 'street_address' => '25 Big Street', 'city' => 'big city', 'location_type_id' => 5));
185 $this->callAPISuccess('email', 'create', array('contact_id' => $contactId , 'email' => 'big@once.com', 'location_type_id' => 2, 'is_billing' => 1));
186
187 $expected = current($individual);
188
189 $params = array(
190 'profile_id' => array($this->_profileID, 1, 'Billing'),
191 'contact_id' => $contactId,
192 );
193
194 $result = $this->callAPISuccess('profile', 'get', $params, __FUNCTION__, __FILE__);
195 $this->assertEquals('abc1', $result['values'][1]['first_name']);
196 $this->assertEquals($result['values']['Billing'], array(
197 'billing_first_name' => 'abc1',
198 'billing_middle_name' => 'J.',
199 'billing_last_name' => 'xyz1',
200 'billing_street_address-5' => '25 Big Street',
201 'billing_city-5' => 'big city',
202 'billing_state_province_id-5' => '',
203 'billing_country_id-5' => '',
204 'billing-email-5' => 'big@once.com',
205 'email-5' => 'big@once.com',
206 'billing_postal_code-5' => '',
207 ));
208 }
209
210 /**
211 * get Billing empty contact - this will return generic defaults
212 */
213 function testProfileGetBillingEmptyContact() {
214
215 $params = array(
216 'profile_id' => array('Billing'),
217 );
218
219 $result = $this->callAPISuccess('profile', 'get', $params);
220 $this->assertEquals(array(
221 'billing_first_name' => '',
222 'billing_middle_name' => '',
223 'billing_last_name' => '',
224 'billing_street_address-5' => '',
225 'billing_city-5' => '',
226 'billing_state_province_id-5' => '',
227 'billing_country_id-5' => '1228',
228 'billing_email-5' => '',
229 'email-5' => '',
230 'billing_postal_code-5' => '',
231 ), $result['values']['Billing']);
232 }
233
234 /**
235 * check contact activity profile without activity id
236 */
237 function testContactActivityGetWithoutActivityId() {
238 list($params, $expected) = $this->_createContactWithActivity();
239
240 unset($params['activity_id']);
241 $result = $this->callAPIFailure('profile', 'get', $params,
242 'Mandatory key(s) missing from params array: activity_id');
243 }
244
245 /**
246 * check contact activity profile wrong activity id
247 */
248 function testContactActivityGetWrongActivityId() {
249 list($params, $expected) = $this->_createContactWithActivity();
250
251 $params['activity_id'] = 100001;
252 $result = $this->callAPIFailure('profile', 'get', $params,
253 'Invalid Activity Id (aid).');
254 }
255
256 /*
257 * check contact activity profile with wrong activity type
258 */
259 function testContactActivityGetWrongActivityType() {
260 //flush cache by calling with reset
261 $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, TRUE, 'name', TRUE);
262
263 $sourceContactId = $this->householdCreate();
264
265 $activityparams = array(
266 'source_contact_id' => $sourceContactId,
267 'activity_type_id' => '2',
268 'subject' => 'Test activity',
269 'activity_date_time' => '20110316',
270 'duration' => '120',
271 'location' => 'Pensulvania',
272 'details' => 'a test activity',
273 'status_id' => '1',
274 'priority_id' => '1',
275 );
276
277 $activity = $this->callAPISuccess('activity', 'create', $activityparams);
278
279 $activityValues = array_pop($activity['values']);
280
281 list($params, $expected) = $this->_createContactWithActivity();
282
283 $params['activity_id'] = $activityValues['id'];
284 $result = $this->callAPIFailure('profile', 'get', $params,
285 'This activity cannot be edited or viewed via this profile.'
286 );
287 }
288
289 /*
290 * check contact activity profile with success
291 */
292 function testContactActivityGetSuccess() {
293 list($params, $expected) = $this->_createContactWithActivity();
294
295 $result = $this->callAPISuccess('profile', 'get', $params);
296
297 foreach ($expected as $profileField => $value) {
298 $this->assertEquals($value, CRM_Utils_Array::value($profileField, $result['values']), "In line " . __LINE__ . " error message: " . "missing/mismatching value for {$profileField}"
299 );
300 }
301 }
302
303 /**
304 * Check getfields works & gives us our fields
305 */
306 function testGetFields() {
307 $this->_createIndividualProfile();
308 $this->_addCustomFieldToProfile($this->_profileID);
309 $result = $this->callAPIAndDocument('profile', 'getfields', array('action' => 'submit', 'profile_id' => $this->_profileID), __FUNCTION__, __FILE__,
310 'demonstrates retrieving profile fields passing in an id');
311 $this->assertArrayKeyExists('first_name', $result['values']);
312 $this->assertEquals('2', $result['values']['first_name']['type']);
313 $this->assertEquals('Email', $result['values']['email-primary']['title']);
314 $this->assertEquals('civicrm_state_province', $result['values']['state_province-1']['pseudoconstant']['table']);
315 $this->assertEquals('defaultValue', $result['values']['custom_1']['default_value']);
316 $this->assertFalse(array_key_exists('participant_status', $result['values']));
317 }
318 /**
319 * Check getfields works & gives us our fields - partipant profile
320 */
321 function testGetFieldsParticipantProfile() {
322 $result = $this->callAPISuccess('profile', 'getfields', array(
323 'action' => 'submit',
324 'profile_id' => 'participant_status',
325 'get_options' => 'all')
326 );
327 $this->assertTrue(array_key_exists('participant_status', $result['values']));
328 $this->assertEquals('Attended', $result['values']['participant_status']['options'][2]);
329 }
330
331 /**
332 * Check getfields works & gives us our fields - membership_batch_entry
333 * (getting to the end with no e-notices is pretty good evidence it's working)
334 */
335 function testGetFieldsMembershipBatchProfile() {
336 $result = $this->callAPISuccess('profile', 'getfields', array(
337 'action' => 'submit',
338 'profile_id' => 'membership_batch_entry',
339 'get_options' => 'all')
340 );
341 $this->assertTrue(array_key_exists('total_amount', $result['values']));
342 $this->assertEquals(12, $result['values']['receive_date']['type']);
343 }
344
345 /**
346 * Check getfields works & gives us our fields - do them all
347 * (getting to the end with no e-notices is pretty good evidence it's working)
348 */
349 function testGetFieldsAllProfiles() {
350 $result = $this->callAPISuccess('uf_group', 'get', array('return' => 'id'));
351 $profileIDs = array_keys($result['values']);
352 foreach ($profileIDs as $profileID) {
353 $result = $this->callAPISuccess('profile', 'getfields', array(
354 'action' => 'submit',
355 'profile_id' => $profileID,
356 'get_options' => 'all')
357 );
358 }
359 }
360 /////////////// test $this->callAPISuccess3_profile_set //////////////////
361
362 /**
363 * check Without ProfileId
364 */
365 function testProfileSubmitWithoutProfileId() {
366 $params = array(
367 'contact_id' => 1,
368 );
369 $result = $this->callAPIFailure('profile', 'submit', $params,
370 'Mandatory key(s) missing from params array: profile_id'
371 );
372 }
373
374 /**
375 * check with no invalid profile Id
376 */
377 function testProfileSubmitInvalidProfileId() {
378 $params = array(
379 'contact_id' => 1,
380 'profile_id' => 1000,
381 );
382 $result = $this->callAPIFailure('profile', 'submit', $params);
383 }
384
385 /**
386 * check with missing required field in profile
387 */
388 function testProfileSubmitCheckProfileRequired() {
389 $pofileFieldValues = $this->_createIndividualContact();
390 current($pofileFieldValues);
391 $contactId = key($pofileFieldValues);
392 $updateParams = array(
393 'first_name' => 'abc2',
394 'last_name' => 'xyz2',
395 'phone-1-1' => '022 321 826',
396 'country-1' => '1013',
397 'state_province-1' => '1000',
398 );
399
400 $params = array_merge(array('profile_id' => $this->_profileID, 'contact_id' => $contactId),
401 $updateParams
402 );
403
404 $result = $this->callAPIFailure('profile', 'submit', $params,
405 "Missing required parameters for profile id $this->_profileID: email-Primary"
406 );
407 }
408
409 /**
410 * check with success
411 */
412 function testProfileSubmit() {
413 $pofileFieldValues = $this->_createIndividualContact();
414 current($pofileFieldValues);
415 $contactId = key($pofileFieldValues);
416
417 $updateParams = array(
418 'first_name' => 'abc2',
419 'last_name' => 'xyz2',
420 'email-primary' => 'abc2.xyz2@gmail.com',
421 'phone-1-1' => '022 321 826',
422 'country-1' => '1013',
423 'state_province-1' => '1000',
424 );
425
426 $params = array_merge(array(
427 'profile_id' => $this->_profileID,
428 'contact_id' => $contactId,
429 ), $updateParams);
430
431 $result = $this->callAPIAndDocument('profile', 'submit', $params, __FUNCTION__, __FILE__);
432
433 $getParams = array(
434 'profile_id' => $this->_profileID,
435 'contact_id' => $contactId,
436 );
437 $profileDetails = $this->callAPISuccess('profile', 'get', $getParams);
438
439 foreach ($updateParams as $profileField => $value) {
440 $this->assertEquals($value, CRM_Utils_Array::value($profileField, $profileDetails['values']), "missing/mismatching value for {$profileField}"
441 );
442 }
443 unset($params['email-primary']);
444 $params['email-Primary'] = 'my@mail.com';
445 $this->callAPISuccess('profile', 'submit', $params);
446 $profileDetails = $this->callAPISuccess('profile', 'get', $getParams);
447 $this->assertEquals('my@mail.com', $profileDetails['values']['email-Primary']);
448 }
449
450 /**
451 * set is deprecated but we need to ensure it still works
452 */
453 function testLegacySet() {
454 $pofileFieldValues = $this->_createIndividualContact();
455 current($pofileFieldValues);
456 $contactId = key($pofileFieldValues);
457
458 $updateParams = array(
459 'first_name' => 'abc2',
460 'last_name' => 'xyz2',
461 'email-Primary' => 'abc2.xyz2@gmail.com',
462 'phone-1-1' => '022 321 826',
463 'country-1' => '1013',
464 'state_province-1' => '1000',
465 );
466
467 $params = array_merge(array(
468 'profile_id' => $this->_profileID,
469 'contact_id' => $contactId,
470 ), $updateParams);
471
472 $result = $this->callAPISuccess('profile', 'set', $params);
473 $this->assertArrayKeyExists('values', $result);
474 $getParams = array(
475 'profile_id' => $this->_profileID,
476 'contact_id' => $contactId,
477 );
478 $profileDetails = $this->callAPISuccess('profile', 'get', $getParams);
479
480 foreach ($updateParams as $profileField => $value) {
481 $this->assertEquals($value, CRM_Utils_Array::value($profileField, $profileDetails['values']), "In line " . __LINE__ . " error message: " . "missing/mismatching value for {$profileField}"
482 );
483 }
484 }
485 /*
486 * check contact activity profile without activity id
487 */
488 function testContactActivitySubmitWithoutActivityId() {
489 list($params, $expected) = $this->_createContactWithActivity();
490
491 $params = array_merge($params, $expected);
492 unset($params['activity_id']);
493 $result = $this->callAPIFailure('profile', 'submit', $params);
494 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: activity_id');
495 }
496
497 /*
498 * check contact activity profile wrong activity id
499 */
500 function testContactActivitySubmitWrongActivityId() {
501 list($params, $expected) = $this->_createContactWithActivity();
502 $params = array_merge($params, $expected);
503 $params['activity_id'] = 100001;
504 $result = $this->callAPIFailure('profile', 'submit', $params);
505 $this->assertEquals($result['error_message'], 'Invalid Activity Id (aid).');
506 }
507
508 /*
509 * check contact activity profile with wrong activity type
510 */
511 function testContactActivitySubmitWrongActivityType() {
512 //flush cache by calling with reset
513 $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, TRUE, 'name', TRUE);
514
515 $sourceContactId = $this->householdCreate();
516
517 $activityparams = array(
518 'source_contact_id' => $sourceContactId,
519 'activity_type_id' => '2',
520 'subject' => 'Test activity',
521 'activity_date_time' => '20110316',
522 'duration' => '120',
523 'location' => 'Pensulvania',
524 'details' => 'a test activity',
525 'status_id' => '1',
526 'priority_id' => '1',
527 );
528
529 $activity = $this->callAPISuccess('activity', 'create', $activityparams);
530
531 $activityValues = array_pop($activity['values']);
532
533 list($params, $expected) = $this->_createContactWithActivity();
534
535 $params = array_merge($params, $expected);
536 $params['activity_id'] = $activityValues['id'];
537 $result = $this->callAPIFailure('profile', 'submit', $params,
538 'This activity cannot be edited or viewed via this profile.');
539 }
540
541 /*
542 * check contact activity profile with success
543 */
544 function testContactActivitySubmitSuccess() {
545 list($params, $expected) = $this->_createContactWithActivity();
546
547 $updateParams = array(
548 'first_name' => 'abc2',
549 'last_name' => 'xyz2',
550 'email-Primary' => 'abc2.xyz2@yahoo.com',
551 'activity_subject' => 'Test Meeting',
552 'activity_details' => 'a test activity details',
553 'activity_duration' => '100',
554 'activity_date_time' => '03/08/2010',
555 'activity_status_id' => '2',
556 );
557 $profileParams = array_merge($params, $updateParams);
558 $this->callAPISuccess('profile', 'submit', $profileParams);
559 $result = $this->callAPISuccess('profile', 'get', $params);
560
561 foreach ($updateParams as $profileField => $value) {
562 $this->assertEquals($value, CRM_Utils_Array::value($profileField, $result['values']), "In line " . __LINE__ . " error message: " . "missing/mismatching value for {$profileField}"
563 );
564 }
565 }
566
567 /**
568 * check profile apply Without ProfileId
569 */
570 function testProfileApplyWithoutProfileId() {
571 $params = array(
572 'contact_id' => 1,
573 );
574 $result = $this->callAPIFailure('profile', 'apply', $params,
575 'Mandatory key(s) missing from params array: profile_id');
576 }
577
578 /**
579 * check profile apply with no invalid profile Id
580 */
581 function testProfileApplyInvalidProfileId() {
582 $params = array(
583 'contact_id' => 1,
584 'profile_id' => 1000,
585 );
586 $result = $this->callAPIFailure('profile', 'apply', $params);
587 }
588
589 /**
590 * check with success
591 */
592 function testProfileApply() {
593 $pofileFieldValues = $this->_createIndividualContact();
594 current($pofileFieldValues);
595 $contactId = key($pofileFieldValues);
596
597 $params = array(
598 'profile_id' => $this->_profileID,
599 'contact_id' => $contactId,
600 'first_name' => 'abc2',
601 'last_name' => 'xyz2',
602 'email-Primary' => 'abc2.xyz2@gmail.com',
603 'phone-1-1' => '022 321 826',
604 'country-1' => '1013',
605 'state_province-1' => '1000',
606 );
607
608 $result = $this->callAPIAndDocument('profile', 'apply', $params, __FUNCTION__, __FILE__);
609
610 // Expected field values
611 $expected['contact'] = array(
612 'contact_id' => $contactId,
613 'contact_type' => 'Individual',
614 'first_name' => 'abc2',
615 'last_name' => 'xyz2',
616 );
617 $expected['email'] = array(
618 'location_type_id' => 1,
619 'is_primary' => 1,
620 'email' => 'abc2.xyz2@gmail.com',
621 );
622
623 $expected['phone'] = array(
624 'location_type_id' => 1,
625 'is_primary' => 1,
626 'phone_type_id' => 1,
627 'phone' => '022 321 826',
628 );
629 $expected['address'] = array(
630 'location_type_id' => 1,
631 'is_primary' => 1,
632 'country_id' => 1013,
633 'state_province_id' => 1000,
634 );
635
636 foreach ($expected['contact'] as $field => $value) {
637 $this->assertEquals($value, CRM_Utils_Array::value($field, $result['values']), "In line " . __LINE__ . " error message: " . "missing/mismatching value for {$field}"
638 );
639 }
640
641 foreach (array(
642 'email', 'phone', 'address') as $fieldType) {
643 $typeValues = array_pop($result['values'][$fieldType]);
644 foreach ($expected[$fieldType] as $field => $value) {
645 $this->assertEquals($value, CRM_Utils_Array::value($field, $typeValues), "In line " . __LINE__ . " error message: " . "missing/mismatching value for {$field} ({$fieldType})"
646 );
647 }
648 }
649 }
650
651 /*
652 * Helper function to create an Individual with address/email/phone info. Import UF Group and UF Fields
653 */
654 function _createIndividualContact($params = array()) {
655 $contactParams = array_merge(array(
656 'first_name' => 'abc1',
657 'last_name' => 'xyz1',
658 'email' => 'abc1.xyz1@yahoo.com',
659 'api.address.create' => array(
660 'location_type_id' => 1,
661 'is_primary' => 1,
662 'street_address' => '5 Saint Helier St',
663 'county' => 'Marin',
664 'country' => 'United States',
665 'state_province' => 'Michigan',
666 'supplemental_address_1' => 'Hallmark Ct',
667 'supplemental_address_2' => 'Jersey Village',
668 'postal_code' => '90210',
669 'city' => 'Gotham City',
670 'is_billing' => 0,
671 ),
672 'api.phone.create' => array(
673 'location_type_id' => '1',
674 'phone' => '021 512 755',
675 'phone_type_id' => '1',
676 'is_primary' => '1',
677 ),
678 ), $params
679 );
680
681 $this->_contactID = $this->individualCreate($contactParams);
682 $this->_createIndividualProfile();
683 // expected result of above created profile with contact Id $contactId
684 $profileData[$this->_contactID] = array(
685 'first_name' => 'abc1',
686 'last_name' => 'xyz1',
687 'email-primary' => 'abc1.xyz1@yahoo.com',
688 'phone-1-1' => '021 512 755',
689 'country-1' => '1228',
690 'state_province-1' => '1021',
691 );
692
693 return $profileData;
694 }
695
696 function _createContactWithActivity() {
697 // @TODO: Create profile with custom fields
698 $op = new PHPUnit_Extensions_Database_Operation_Insert();
699 $op->execute($this->_dbconn,
700 new PHPUnit_Extensions_Database_DataSet_FlatXMLDataSet(
701 dirname(__FILE__) . '/dataset/uf_group_contact_activity_26.xml'
702 )
703 );
704 // hack: xml data set do not accept \ 1 (CRM_Core_DAO::VALUE_SEPARATOR)
705 CRM_Core_DAO::setFieldValue('CRM_Core_DAO_UFGroup', '26', 'group_type', 'Individual,Contact,Activity' . CRM_Core_DAO::VALUE_SEPARATOR . 'ActivityType:1');
706
707 $sourceContactId = $this->individualCreate();
708 $contactParams = array(
709 'first_name' => 'abc1',
710 'last_name' => 'xyz1',
711 'contact_type' => 'Individual',
712 'email' => 'abc1.xyz1@yahoo.com',
713 'api.address.create' => array(
714 'location_type_id' => 1,
715 'is_primary' => 1,
716 'name' => 'Saint Helier St',
717 'county' => 'Marin',
718 'country' => 'United States',
719 'state_province' => 'Michigan',
720 'supplemental_address_1' => 'Hallmark Ct',
721 'supplemental_address_2' => 'Jersey Village',
722 ),
723 );
724
725 $contact = $this->callAPISuccess('contact', 'create', $contactParams);
726
727 $keys = array_keys($contact['values']);
728 $contactId = array_pop($keys);
729
730 $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'])
731 );
732
733 $activityParams = array(
734 'source_contact_id' => $sourceContactId,
735 'assignee_contact_id' => $contactId,
736 'activity_type_id' => '1',
737 'subject' => 'Make-it-Happen Meeting',
738 'activity_date_time' => '20110316',
739 'duration' => '120',
740 'location' => 'Pensulvania',
741 'details' => 'a test activity',
742 'status_id' => '1',
743 'priority_id' => '1',
744 );
745 $activity = $this->callAPISuccess('activity', 'create', $activityParams);
746
747 $activityValues = array_pop($activity['values']);
748
749 // valid parameters for above profile
750 $profileParams = array(
751 'profile_id' => 26,
752 'contact_id' => $contactId,
753 'activity_id' => $activityValues['id'],
754 );
755
756 // expected result of above created profile
757 $expected = array(
758 'first_name' => 'abc1',
759 'last_name' => 'xyz1',
760 'email-Primary' => 'abc1.xyz1@yahoo.com',
761 'activity_subject' => 'Make-it-Happen Meeting',
762 'activity_details' => 'a test activity',
763 'activity_duration' => '120',
764 'activity_date_time_time' => '12:00AM',
765 'activity_date_time' => '03/16/2011',
766 'activity_status_id' => '1',
767 );
768
769 return array($profileParams, $expected);
770 }
771 /**
772 * Create a profile
773 */
774 function _createIndividualProfile() {
775
776 // creating these via the api as we want to utilise & test the flushing of caches when fields created
777 // via the api
778
779 $ufGroupParams = array(
780 'group_type' => 'Individual,Contact',// really we should remove this & test the ufField create sets it
781 'name' => 'test_individual_contact_profile',
782 'title' => 'Flat Coffee',
783 'api.uf_field.create' => array(
784 array(
785 'field_name' => 'first_name',
786 'is_required' => 1,
787 'visibility' => 'Public Pages and Listings',
788 'field_type' => 'Individual',
789 'label' => 'First Name',
790 ),
791 array(
792 'field_name' => 'last_name',
793 'is_required' => 1,
794 'visibility' => 'Public Pages and Listings',
795 'field_type' => 'Individual',
796 'label' => 'Last Name',
797 ),
798 array(
799 'field_name' => 'email',
800 'is_required' => 1,
801 'visibility' => 'Public Pages and Listings',
802 'field_type' => 'Contact',
803 'label' => 'Email',
804 ),
805 array(
806 'field_name' => 'phone',
807 'is_required' => 1,
808 'visibility' => 'Public Pages and Listings',
809 'field_type' => 'Contact',
810 'location_type_id' => 1,
811 'phone_type_id' => 1,
812 'label' => 'Phone'
813 ),
814 array(
815 'field_name' => 'country',
816 'is_required' => 1,
817 'visibility' => 'Public Pages and Listings',
818 'field_type' => 'Contact',
819 'location_type_id' => 1,
820 'label' => 'Country'
821 ),
822 array(
823 'field_name' => 'state_province',
824 'is_required' => 1,
825 'visibility' => 'Public Pages and Listings',
826 'field_type' => 'Contact',
827 'location_type_id' => 1,
828 'label' => 'State Province'
829 ),
830 array(
831 'field_name' => 'postal_code',
832 'is_required' => 0,
833 'field_type' => 'Contact',
834 'location_type_id' => 1,
835 'label' => 'State Province'
836 ),
837 ),
838 );
839 $profile = $this->callAPISuccess('uf_group', 'create', $ufGroupParams);
840 $this->_profileID = $profile['id'];
841 }
842
843 function _addCustomFieldToProfile($profileID) {
844 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, '');
845 $this->uFFieldCreate(array('uf_group_id' => $profileID, 'field_name' => 'custom_' . $ids['custom_field_id'], 'contact_type' => 'Contact'));
846 }
847 }
848