3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 * Test APIv3 civicrm_profile_* functions
33 class api_v3_ProfileTest
extends CiviUnitTestCase
{
34 protected $_apiversion;
35 protected $_profileID = 0;
36 protected $_membershipTypeID;
37 protected $_contactID;
39 public function setUp() {
40 $this->_apiversion
= 3;
42 $config = CRM_Core_Config
::singleton();
43 $countryLimit = $config->countryLimit
;
44 $countryLimit[1] = 1013;
45 $config->countryLimit
= $countryLimit;
47 $this->createLoggedInUser();
48 $this->_membershipTypeID
= $this->membershipTypeCreate();
51 public function tearDown() {
53 $this->quickCleanup(array(
58 'civicrm_contribution',
61 $this->callAPISuccess('membership_type', 'delete', array('id' => $this->_membershipTypeID
));
62 // ok can't be bothered wring an api to do this & truncating is crazy
63 CRM_Core_DAO
::executeQuery(" DELETE FROM civicrm_uf_group WHERE id IN ($this->_profileID, 26)");
66 ////////////// test $this->callAPISuccess3_profile_get //////////////////
69 * Check Without ProfileId.
71 public function testProfileGetWithoutProfileId() {
75 $result = $this->callAPIFailure('profile', 'get', $params,
76 'Mandatory key(s) missing from params array: profile_id'
81 * Check with no invalid profile Id.
83 public function testProfileGetInvalidProfileId() {
88 $result = $this->callAPIFailure('profile', 'get', $params);
94 public function testProfileGet() {
95 $pofileFieldValues = $this->_createIndividualContact();
96 $expected = current($pofileFieldValues);
97 $contactId = key($pofileFieldValues);
99 'profile_id' => $this->_profileID
,
100 'contact_id' => $contactId,
102 $result = $this->callAPISuccess('profile', 'get', $params);
103 foreach ($expected as $profileField => $value) {
104 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $result['values']));
108 public function testProfileGetMultiple() {
109 $pofileFieldValues = $this->_createIndividualContact();
110 $expected = current($pofileFieldValues);
111 $contactId = key($pofileFieldValues);
113 'profile_id' => array($this->_profileID
, 1, 'Billing'),
114 'contact_id' => $contactId,
117 $result = $this->callAPIAndDocument('profile', 'get', $params, __FUNCTION__
, __FILE__
);
118 foreach ($expected as $profileField => $value) {
119 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $result['values'][$this->_profileID
]), " error message: " . "missing/mismatching value for {$profileField}");
121 $this->assertEquals('abc1', $result['values'][1]['first_name'], " error message: " . "missing/mismatching value for {$profileField}");
122 $this->assertFalse(array_key_exists('email-Primary', $result['values'][1]), 'profile 1 doesn not include email');
123 $this->assertEquals($result['values']['Billing'], array(
124 'billing_first_name' => 'abc1',
125 'billing_middle_name' => 'J.',
126 'billing_last_name' => 'xyz1',
127 'billing_street_address-5' => '5 Saint Helier St',
128 'billing_city-5' => 'Gotham City',
129 'billing_state_province_id-5' => '1021',
130 'billing_country_id-5' => '1228',
131 'billing_postal_code-5' => '90210',
132 'billing-email-5' => 'abc1.xyz1@yahoo.com',
133 'email-5' => 'abc1.xyz1@yahoo.com',
137 public function testProfileGetBillingUseIsBillingLocation() {
138 $individual = $this->_createIndividualContact();
139 $contactId = key($individual);
140 $this->callAPISuccess('address', 'create', array(
142 'street_address' => 'is billing st',
143 'location_type_id' => 2,
144 'contact_id' => $contactId,
147 $expected = current($individual);
150 'profile_id' => array($this->_profileID
, 1, 'Billing'),
151 'contact_id' => $contactId,
154 $result = $this->callAPISuccess('profile', 'get', $params);
155 $this->assertEquals('abc1', $result['values'][1]['first_name']);
156 $this->assertEquals(array(
157 'billing_first_name' => 'abc1',
158 'billing_middle_name' => 'J.',
159 'billing_last_name' => 'xyz1',
160 'billing_street_address-5' => 'is billing st',
161 'billing_city-5' => '',
162 'billing_state_province_id-5' => '',
163 'billing_country_id-5' => '',
164 'billing-email-5' => 'abc1.xyz1@yahoo.com',
165 'email-5' => 'abc1.xyz1@yahoo.com',
166 'billing_postal_code-5' => '',
167 ), $result['values']['Billing']);
170 public function testProfileGetMultipleHasBillingLocation() {
171 $individual = $this->_createIndividualContact();
172 $contactId = key($individual);
173 $this->callAPISuccess('address', 'create', array(
174 'contact_id' => $contactId,
175 'street_address' => '25 Big Street',
176 'city' => 'big city',
177 'location_type_id' => 5,
179 $this->callAPISuccess('email', 'create', array(
180 'contact_id' => $contactId,
181 'email' => 'big@once.com',
182 'location_type_id' => 2,
186 $expected = current($individual);
189 'profile_id' => array($this->_profileID
, 1, 'Billing'),
190 'contact_id' => $contactId,
193 $result = $this->callAPISuccess('profile', 'get', $params, __FUNCTION__
, __FILE__
);
194 $this->assertEquals('abc1', $result['values'][1]['first_name']);
195 $this->assertEquals($result['values']['Billing'], array(
196 'billing_first_name' => 'abc1',
197 'billing_middle_name' => 'J.',
198 'billing_last_name' => 'xyz1',
199 'billing_street_address-5' => '25 Big Street',
200 'billing_city-5' => 'big city',
201 'billing_state_province_id-5' => '',
202 'billing_country_id-5' => '',
203 'billing-email-5' => 'big@once.com',
204 'email-5' => 'big@once.com',
205 'billing_postal_code-5' => '',
210 * Get Billing empty contact - this will return generic defaults
212 public function testProfileGetBillingEmptyContact() {
215 'profile_id' => array('Billing'),
218 $result = $this->callAPISuccess('profile', 'get', $params);
219 $this->assertEquals(array(
220 'billing_first_name' => '',
221 'billing_middle_name' => '',
222 'billing_last_name' => '',
223 'billing_street_address-5' => '',
224 'billing_city-5' => '',
225 'billing_state_province_id-5' => '',
226 'billing_country_id-5' => '1228',
227 'billing_email-5' => '',
229 'billing_postal_code-5' => '',
230 ), $result['values']['Billing']);
234 * Check contact activity profile without activity id.
236 public function testContactActivityGetWithoutActivityId() {
237 list($params, $expected) = $this->_createContactWithActivity();
239 unset($params['activity_id']);
240 $result = $this->callAPIFailure('profile', 'get', $params,
241 'Mandatory key(s) missing from params array: activity_id');
245 * Check contact activity profile wrong activity id.
247 public function testContactActivityGetWrongActivityId() {
248 list($params, $expected) = $this->_createContactWithActivity();
250 $params['activity_id'] = 100001;
251 $result = $this->callAPIFailure('profile', 'get', $params,
252 'Invalid Activity Id (aid).');
256 * Check contact activity profile with wrong activity type.
258 public function testContactActivityGetWrongActivityType() {
259 //flush cache by calling with reset
260 $activityTypes = CRM_Core_PseudoConstant
::activityType(TRUE, TRUE, TRUE, 'name', TRUE);
262 $sourceContactId = $this->householdCreate();
264 $activityparams = array(
265 'source_contact_id' => $sourceContactId,
266 'activity_type_id' => '2',
267 'subject' => 'Test activity',
268 'activity_date_time' => '20110316',
270 'location' => 'Pensulvania',
271 'details' => 'a test activity',
273 'priority_id' => '1',
276 $activity = $this->callAPISuccess('activity', 'create', $activityparams);
278 $activityValues = array_pop($activity['values']);
280 list($params, $expected) = $this->_createContactWithActivity();
282 $params['activity_id'] = $activityValues['id'];
283 $result = $this->callAPIFailure('profile', 'get', $params,
284 'This activity cannot be edited or viewed via this profile.'
289 * Check contact activity profile with success.
291 public function testContactActivityGetSuccess() {
292 list($params, $expected) = $this->_createContactWithActivity();
294 $result = $this->callAPISuccess('profile', 'get', $params);
296 foreach ($expected as $profileField => $value) {
297 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $result['values']), "In line " . __LINE__
. " error message: " . "missing/mismatching value for {$profileField}"
303 * Check getfields works & gives us our fields
305 public function testGetFields() {
306 $this->_createIndividualProfile();
307 $this->_addCustomFieldToProfile($this->_profileID
);
308 $result = $this->callAPIAndDocument('profile', 'getfields', array(
309 'action' => 'submit',
310 'profile_id' => $this->_profileID
,
311 ), __FUNCTION__
, __FILE__
,
312 'demonstrates retrieving profile fields passing in an id');
313 $this->assertArrayKeyExists('first_name', $result['values']);
314 $this->assertEquals('2', $result['values']['first_name']['type']);
315 $this->assertEquals('Email', $result['values']['email-primary']['title']);
316 $this->assertEquals('civicrm_state_province', $result['values']['state_province-1']['pseudoconstant']['table']);
317 $this->assertEquals('defaultValue', $result['values']['custom_1']['default_value']);
318 $this->assertFalse(array_key_exists('participant_status', $result['values']));
322 * Check getfields works & gives us our fields - partipant profile
324 public function testGetFieldsParticipantProfile() {
325 $result = $this->callAPISuccess('profile', 'getfields', array(
326 'action' => 'submit',
327 'profile_id' => 'participant_status',
328 'get_options' => 'all',
331 $this->assertTrue(array_key_exists('participant_status_id', $result['values']));
332 $this->assertEquals('Attended', $result['values']['participant_status_id']['options'][2]);
333 $this->assertEquals(array('participant_status'), $result['values']['participant_status_id']['api.aliases']);
337 * Check getfields works & gives us our fields - membership_batch_entry
338 * (getting to the end with no e-notices is pretty good evidence it's working)
340 public function testGetFieldsMembershipBatchProfile() {
341 $result = $this->callAPISuccess('profile', 'getfields', array(
342 'action' => 'submit',
343 'profile_id' => 'membership_batch_entry',
344 'get_options' => 'all',
347 $this->assertTrue(array_key_exists('total_amount', $result['values']));
348 $this->assertTrue(array_key_exists('financial_type_id', $result['values']));
349 $this->assertEquals(array(
350 'contribution_type_id',
353 ), $result['values']['financial_type_id']['api.aliases']);
354 $this->assertTrue(!array_key_exists('financial_type', $result['values']));
355 $this->assertEquals(12, $result['values']['receive_date']['type']);
359 * Check getfields works & gives us our fields - do them all
360 * (getting to the end with no e-notices is pretty good evidence it's working)
362 public function testGetFieldsAllProfiles() {
363 $result = $this->callAPISuccess('uf_group', 'get', array('return' => 'id'));
364 $profileIDs = array_keys($result['values']);
365 foreach ($profileIDs as $profileID) {
366 $result = $this->callAPISuccess('profile', 'getfields', array(
367 'action' => 'submit',
368 'profile_id' => $profileID,
369 'get_options' => 'all',
374 /////////////// test $this->callAPISuccess3_profile_set //////////////////
377 * Check Without ProfileId.
379 public function testProfileSubmitWithoutProfileId() {
383 $result = $this->callAPIFailure('profile', 'submit', $params,
384 'Mandatory key(s) missing from params array: profile_id'
389 * Check with no invalid profile Id.
391 public function testProfileSubmitInvalidProfileId() {
394 'profile_id' => 1000,
396 $result = $this->callAPIFailure('profile', 'submit', $params);
400 * Check with missing required field in profile.
402 public function testProfileSubmitCheckProfileRequired() {
403 $pofileFieldValues = $this->_createIndividualContact();
404 current($pofileFieldValues);
405 $contactId = key($pofileFieldValues);
406 $updateParams = array(
407 'first_name' => 'abc2',
408 'last_name' => 'xyz2',
409 'phone-1-1' => '022 321 826',
410 'country-1' => '1013',
411 'state_province-1' => '1000',
414 $params = array_merge(array('profile_id' => $this->_profileID
, 'contact_id' => $contactId),
418 $result = $this->callAPIFailure('profile', 'submit', $params,
419 "Missing required parameters for profile id $this->_profileID: email-Primary"
424 * Check with success.
426 public function testProfileSubmit() {
427 $pofileFieldValues = $this->_createIndividualContact();
428 current($pofileFieldValues);
429 $contactId = key($pofileFieldValues);
431 $updateParams = array(
432 'first_name' => 'abc2',
433 'last_name' => 'xyz2',
434 'email-primary' => 'abc2.xyz2@gmail.com',
435 'phone-1-1' => '022 321 826',
436 'country-1' => '1013',
437 'state_province-1' => '1000',
440 $params = array_merge(array(
441 'profile_id' => $this->_profileID
,
442 'contact_id' => $contactId,
445 $result = $this->callAPIAndDocument('profile', 'submit', $params, __FUNCTION__
, __FILE__
);
448 'profile_id' => $this->_profileID
,
449 'contact_id' => $contactId,
451 $profileDetails = $this->callAPISuccess('profile', 'get', $getParams);
453 foreach ($updateParams as $profileField => $value) {
454 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $profileDetails['values']), "missing/mismatching value for {$profileField}"
457 unset($params['email-primary']);
458 $params['email-Primary'] = 'my@mail.com';
459 $this->callAPISuccess('profile', 'submit', $params);
460 $profileDetails = $this->callAPISuccess('profile', 'get', $getParams);
461 $this->assertEquals('my@mail.com', $profileDetails['values']['email-Primary']);
465 * Ensure caches are being cleared so we don't get into a debugging trap because of cached metadata
466 * First we delete & create to increment the version & then check for caching probs
468 public function testProfileSubmitCheckCaching() {
469 $this->callAPISuccess('membership_type', 'delete', array('id' => $this->_membershipTypeID
));
470 $this->_membershipTypeID
= $this->membershipTypeCreate();
472 $membershipTypes = $this->callAPISuccess('membership_type', 'get', array());
473 $profileFields = $this->callAPISuccess('profile', 'getfields', array(
474 'get_options' => 'all',
475 'action' => 'submit',
476 'profile_id' => 'membership_batch_entry',
478 $getoptions = $this->callAPISuccess('membership', 'getoptions', array(
479 'field' => 'membership_type',
480 'context' => 'validate',
482 $this->assertEquals(array_keys($membershipTypes['values']), array_keys($getoptions['values']));
483 $this->assertEquals(array_keys($membershipTypes['values']), array_keys($profileFields['values']['membership_type_id']['options']));
488 * Test that the fields are returned in the right order despite the faffing around that goes on.
490 public function testMembershipGetFieldsOrder() {
491 $result = $this->callAPISuccess('profile', 'getfields', array(
492 'action' => 'submit',
493 'profile_id' => 'membership_batch_entry',
496 foreach ($result['values'] as $fieldName => $field) {
497 if ($fieldName == 'profile_id') {
500 $this->assertEquals($field['weight'], $weight);
506 * Check we can submit membership batch profiles (create mode)
508 public function testProfileSubmitMembershipBatch() {
509 $this->_contactID
= $this->individualCreate();
510 $this->callAPISuccess('profile', 'submit', array(
511 'profile_id' => 'membership_batch_entry',
512 'financial_type_id' => 1,
513 'membership_type' => $this->_membershipTypeID
,
514 'join_date' => 'now',
515 'total_amount' => 10,
516 'contribution_status_id' => 1,
517 'receive_date' => 'now',
518 'contact_id' => $this->_contactID
,
523 * Set is deprecated but we need to ensure it still works.
525 public function testLegacySet() {
526 $pofileFieldValues = $this->_createIndividualContact();
527 current($pofileFieldValues);
528 $contactId = key($pofileFieldValues);
530 $updateParams = array(
531 'first_name' => 'abc2',
532 'last_name' => 'xyz2',
533 'email-Primary' => 'abc2.xyz2@gmail.com',
534 'phone-1-1' => '022 321 826',
535 'country-1' => '1013',
536 'state_province-1' => '1000',
539 $params = array_merge(array(
540 'profile_id' => $this->_profileID
,
541 'contact_id' => $contactId,
544 $result = $this->callAPISuccess('profile', 'set', $params);
545 $this->assertArrayKeyExists('values', $result);
547 'profile_id' => $this->_profileID
,
548 'contact_id' => $contactId,
550 $profileDetails = $this->callAPISuccess('profile', 'get', $getParams);
552 foreach ($updateParams as $profileField => $value) {
553 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $profileDetails['values']), "In line " . __LINE__
. " error message: " . "missing/mismatching value for {$profileField}"
559 * Check contact activity profile without activity id.
561 public function testContactActivitySubmitWithoutActivityId() {
562 list($params, $expected) = $this->_createContactWithActivity();
564 $params = array_merge($params, $expected);
565 unset($params['activity_id']);
566 $result = $this->callAPIFailure('profile', 'submit', $params);
567 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: activity_id');
571 * Check contact activity profile wrong activity id.
573 public function testContactActivitySubmitWrongActivityId() {
574 list($params, $expected) = $this->_createContactWithActivity();
575 $params = array_merge($params, $expected);
576 $params['activity_id'] = 100001;
577 $result = $this->callAPIFailure('profile', 'submit', $params);
578 $this->assertEquals($result['error_message'], 'Invalid Activity Id (aid).');
582 * Check contact activity profile with wrong activity type.
584 public function testContactActivitySubmitWrongActivityType() {
585 //flush cache by calling with reset
586 $activityTypes = CRM_Core_PseudoConstant
::activityType(TRUE, TRUE, TRUE, 'name', TRUE);
588 $sourceContactId = $this->householdCreate();
590 $activityparams = array(
591 'source_contact_id' => $sourceContactId,
592 'activity_type_id' => '2',
593 'subject' => 'Test activity',
594 'activity_date_time' => '20110316',
596 'location' => 'Pensulvania',
597 'details' => 'a test activity',
599 'priority_id' => '1',
602 $activity = $this->callAPISuccess('activity', 'create', $activityparams);
604 $activityValues = array_pop($activity['values']);
606 list($params, $expected) = $this->_createContactWithActivity();
608 $params = array_merge($params, $expected);
609 $params['activity_id'] = $activityValues['id'];
610 $result = $this->callAPIFailure('profile', 'submit', $params,
611 'This activity cannot be edited or viewed via this profile.');
615 * Check contact activity profile with success.
617 public function testContactActivitySubmitSuccess() {
618 list($params, $expected) = $this->_createContactWithActivity();
620 $updateParams = array(
621 'first_name' => 'abc2',
622 'last_name' => 'xyz2',
623 'email-Primary' => 'abc2.xyz2@yahoo.com',
624 'activity_subject' => 'Test Meeting',
625 'activity_details' => 'a test activity details',
626 'activity_duration' => '100',
627 'activity_date_time' => '03/08/2010',
628 'activity_status_id' => '2',
630 $profileParams = array_merge($params, $updateParams);
631 $this->callAPISuccess('profile', 'submit', $profileParams);
632 $result = $this->callAPISuccess('profile', 'get', $params);
634 foreach ($updateParams as $profileField => $value) {
635 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $result['values']), "In line " . __LINE__
. " error message: " . "missing/mismatching value for {$profileField}"
641 * Check profile apply Without ProfileId.
643 public function testProfileApplyWithoutProfileId() {
647 $result = $this->callAPIFailure('profile', 'apply', $params,
648 'Mandatory key(s) missing from params array: profile_id');
652 * Check profile apply with no invalid profile Id.
654 public function testProfileApplyInvalidProfileId() {
657 'profile_id' => 1000,
659 $result = $this->callAPIFailure('profile', 'apply', $params);
663 * Check with success.
665 public function testProfileApply() {
666 $pofileFieldValues = $this->_createIndividualContact();
667 current($pofileFieldValues);
668 $contactId = key($pofileFieldValues);
671 'profile_id' => $this->_profileID
,
672 'contact_id' => $contactId,
673 'first_name' => 'abc2',
674 'last_name' => 'xyz2',
675 'email-Primary' => 'abc2.xyz2@gmail.com',
676 'phone-1-1' => '022 321 826',
677 'country-1' => '1013',
678 'state_province-1' => '1000',
681 $result = $this->callAPIAndDocument('profile', 'apply', $params, __FUNCTION__
, __FILE__
);
683 // Expected field values
684 $expected['contact'] = array(
685 'contact_id' => $contactId,
686 'contact_type' => 'Individual',
687 'first_name' => 'abc2',
688 'last_name' => 'xyz2',
690 $expected['email'] = array(
691 'location_type_id' => 1,
693 'email' => 'abc2.xyz2@gmail.com',
696 $expected['phone'] = array(
697 'location_type_id' => 1,
699 'phone_type_id' => 1,
700 'phone' => '022 321 826',
702 $expected['address'] = array(
703 'location_type_id' => 1,
705 'country_id' => 1013,
706 'state_province_id' => 1000,
709 foreach ($expected['contact'] as $field => $value) {
710 $this->assertEquals($value, CRM_Utils_Array
::value($field, $result['values']), "In line " . __LINE__
. " error message: " . "missing/mismatching value for {$field}"
719 $typeValues = array_pop($result['values'][$fieldType]);
720 foreach ($expected[$fieldType] as $field => $value) {
721 $this->assertEquals($value, CRM_Utils_Array
::value($field, $typeValues), "In line " . __LINE__
. " error message: " . "missing/mismatching value for {$field} ({$fieldType})"
728 * Helper function to create an Individual with address/email/phone info. Import UF Group and UF Fields
729 * @param array $params
733 public function _createIndividualContact($params = array()) {
734 $contactParams = array_merge(array(
735 'first_name' => 'abc1',
736 'last_name' => 'xyz1',
737 'email' => 'abc1.xyz1@yahoo.com',
738 'api.address.create' => array(
739 'location_type_id' => 1,
741 'street_address' => '5 Saint Helier St',
743 'country' => 'UNITED STATES',
744 'state_province' => 'Michigan',
745 'supplemental_address_1' => 'Hallmark Ct',
746 'supplemental_address_2' => 'Jersey Village',
747 'postal_code' => '90210',
748 'city' => 'Gotham City',
751 'api.phone.create' => array(
752 'location_type_id' => '1',
753 'phone' => '021 512 755',
754 'phone_type_id' => '1',
760 $this->_contactID
= $this->individualCreate($contactParams);
761 $this->_createIndividualProfile();
762 // expected result of above created profile with contact Id $contactId
763 $profileData[$this->_contactID
] = array(
764 'first_name' => 'abc1',
765 'last_name' => 'xyz1',
766 'email-primary' => 'abc1.xyz1@yahoo.com',
767 'phone-1-1' => '021 512 755',
768 'country-1' => '1228',
769 'state_province-1' => '1021',
778 public function _createContactWithActivity() {
779 // @TODO: Create profile with custom fields
780 $op = new PHPUnit_Extensions_Database_Operation_Insert();
781 $op->execute($this->_dbconn
,
782 $this->createFlatXMLDataSet(
783 dirname(__FILE__
) . '/dataset/uf_group_contact_activity_26.xml'
786 // hack: xml data set do not accept \ 1 (CRM_Core_DAO::VALUE_SEPARATOR)
787 CRM_Core_DAO
::setFieldValue('CRM_Core_DAO_UFGroup', '26', 'group_type', 'Individual,Contact,Activity' . CRM_Core_DAO
::VALUE_SEPARATOR
. 'ActivityType:1');
789 $sourceContactId = $this->individualCreate();
790 $contactParams = array(
791 'first_name' => 'abc1',
792 'last_name' => 'xyz1',
793 'contact_type' => 'Individual',
794 'email' => 'abc1.xyz1@yahoo.com',
795 'api.address.create' => array(
796 'location_type_id' => 1,
798 'name' => 'Saint Helier St',
800 'country' => 'UNITED STATES',
801 'state_province' => 'Michigan',
802 'supplemental_address_1' => 'Hallmark Ct',
803 'supplemental_address_2' => 'Jersey Village',
807 $contact = $this->callAPISuccess('contact', 'create', $contactParams);
809 $keys = array_keys($contact['values']);
810 $contactId = array_pop($keys);
812 $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'])
815 $activityParams = array(
816 'source_contact_id' => $sourceContactId,
817 'assignee_contact_id' => $contactId,
818 'activity_type_id' => '1',
819 'subject' => 'Make-it-Happen Meeting',
820 'activity_date_time' => '20110316',
822 'location' => 'Pensulvania',
823 'details' => 'a test activity',
825 'priority_id' => '1',
827 $activity = $this->callAPISuccess('activity', 'create', $activityParams);
829 $activityValues = array_pop($activity['values']);
831 // valid parameters for above profile
832 $profileParams = array(
834 'contact_id' => $contactId,
835 'activity_id' => $activityValues['id'],
838 // expected result of above created profile
840 'first_name' => 'abc1',
841 'last_name' => 'xyz1',
842 'email-Primary' => 'abc1.xyz1@yahoo.com',
843 'activity_subject' => 'Make-it-Happen Meeting',
844 'activity_details' => 'a test activity',
845 'activity_duration' => '120',
846 'activity_date_time_time' => '12:00AM',
847 'activity_date_time' => '03/16/2011',
848 'activity_status_id' => '1',
851 return array($profileParams, $expected);
857 public function _createIndividualProfile() {
859 // creating these via the api as we want to utilise & test the flushing of caches when fields created
862 $ufGroupParams = array(
863 'group_type' => 'Individual,Contact', // really we should remove this & test the ufField create sets it
864 'name' => 'test_individual_contact_profile',
865 'title' => 'Flat Coffee',
866 'api.uf_field.create' => array(
868 'field_name' => 'first_name',
870 'visibility' => 'Public Pages and Listings',
871 'field_type' => 'Individual',
872 'label' => 'First Name',
875 'field_name' => 'last_name',
877 'visibility' => 'Public Pages and Listings',
878 'field_type' => 'Individual',
879 'label' => 'Last Name',
882 'field_name' => 'email',
884 'visibility' => 'Public Pages and Listings',
885 'field_type' => 'Contact',
889 'field_name' => 'phone',
891 'visibility' => 'Public Pages and Listings',
892 'field_type' => 'Contact',
893 'location_type_id' => 1,
894 'phone_type_id' => 1,
898 'field_name' => 'country',
900 'visibility' => 'Public Pages and Listings',
901 'field_type' => 'Contact',
902 'location_type_id' => 1,
903 'label' => 'Country',
906 'field_name' => 'state_province',
908 'visibility' => 'Public Pages and Listings',
909 'field_type' => 'Contact',
910 'location_type_id' => 1,
911 'label' => 'State Province',
914 'field_name' => 'postal_code',
916 'field_type' => 'Contact',
917 'location_type_id' => 1,
918 'label' => 'State Province',
922 $profile = $this->callAPISuccess('uf_group', 'create', $ufGroupParams);
923 $this->_profileID
= $profile['id'];
927 * @param int $profileID
929 public function _addCustomFieldToProfile($profileID) {
930 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, '');
931 $this->uFFieldCreate(array(
932 'uf_group_id' => $profileID,
933 'field_name' => 'custom_' . $ids['custom_field_id'],
934 'contact_type' => 'Contact',