4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.5 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2014 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
30 * Include class definitions
32 require_once 'tests/phpunit/CiviTest/CiviUnitTestCase.php';
35 * Test APIv3 civicrm_profile_* functions
39 class api_v3_ProfileTest
extends CiviUnitTestCase
{
40 protected $_apiversion;
41 protected $_profileID = 0;
42 protected $_membershipTypeID;
43 protected $_contactID;
50 'name' => 'Profile Test',
51 'description' => 'Test all profile API methods.',
52 'group' => 'CiviCRM API Tests',
57 $this->_apiversion
= 3;
59 $config = CRM_Core_Config
::singleton();
60 $config->countryLimit
[1] = 1013;
61 $config->stateLimit
[1] = 1013;
62 $this->createLoggedInUser();
63 $this->_membershipTypeID
= $this->membershipTypeCreate();
68 $this->quickCleanup(array(
73 'civicrm_contribution',
75 $this->callAPISuccess('membership_type', 'delete', array('id' => $this->_membershipTypeID
));
76 // ok can't be bothered wring an api to do this & truncating is crazy
77 CRM_Core_DAO
::executeQuery(" DELETE FROM civicrm_uf_group WHERE id IN ($this->_profileID, 26)");
80 ////////////// test $this->callAPISuccess3_profile_get //////////////////
83 * Check Without ProfileId
85 function testProfileGetWithoutProfileId() {
89 $result = $this->callAPIFailure('profile', 'get', $params,
90 'Mandatory key(s) missing from params array: profile_id'
95 * Check with no invalid profile Id
97 function testProfileGetInvalidProfileId() {
100 'profile_id' => 1000,
102 $result = $this->callAPIFailure('profile', 'get', $params);
108 function testProfileGet() {
109 $pofileFieldValues = $this->_createIndividualContact();
110 $expected = current($pofileFieldValues);
111 $contactId = key($pofileFieldValues);
113 'profile_id' => $this->_profileID
,
114 'contact_id' => $contactId,
116 $result = $this->callAPISuccess('profile', 'get', $params);
117 foreach ($expected as $profileField => $value) {
118 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $result['values']));
122 function testProfileGetMultiple() {
123 $pofileFieldValues = $this->_createIndividualContact();
124 $expected = current($pofileFieldValues);
125 $contactId = key($pofileFieldValues);
127 'profile_id' => array($this->_profileID
, 1, 'Billing'),
128 'contact_id' => $contactId,
131 $result = $this->callAPIAndDocument('profile', 'get', $params, __FUNCTION__
, __FILE__
);
132 foreach ($expected as $profileField => $value) {
133 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $result['values'][$this->_profileID
]), " error message: " . "missing/mismatching value for {$profileField}");
135 $this->assertEquals('abc1', $result['values'][1]['first_name'], " error message: " . "missing/mismatching value for {$profileField}");
136 $this->assertFalse(array_key_exists('email-Primary', $result['values'][1]), 'profile 1 doesn not include email');
137 $this->assertEquals($result['values']['Billing'], array(
138 'billing_first_name' => 'abc1',
139 'billing_middle_name' => 'J.',
140 'billing_last_name' => 'xyz1',
141 'billing_street_address-5' => '5 Saint Helier St',
142 'billing_city-5' => 'Gotham City',
143 'billing_state_province_id-5' => '1021',
144 'billing_country_id-5' => '1228',
145 'billing_postal_code-5' => '90210',
146 'billing-email-5' => 'abc1.xyz1@yahoo.com',
147 'email-5' => 'abc1.xyz1@yahoo.com',
151 function testProfileGetBillingUseIsBillingLocation() {
152 $individual = $this->_createIndividualContact();
153 $contactId = key($individual);
154 $this->callAPISuccess('address', 'create', array(
156 'street_address' => 'is billing st',
157 'location_type_id' => 2,
158 'contact_id' => $contactId,
161 $expected = current($individual);
164 'profile_id' => array($this->_profileID
, 1, 'Billing'),
165 'contact_id' => $contactId,
168 $result = $this->callAPISuccess('profile', 'get', $params);
169 $this->assertEquals('abc1', $result['values'][1]['first_name']);
170 $this->assertEquals(array(
171 'billing_first_name' => 'abc1',
172 'billing_middle_name' => 'J.',
173 'billing_last_name' => 'xyz1',
174 'billing_street_address-5' => 'is billing st',
175 'billing_city-5' => '',
176 'billing_state_province_id-5' => '',
177 'billing_country_id-5' => '',
178 'billing-email-5' => 'abc1.xyz1@yahoo.com',
179 'email-5' => 'abc1.xyz1@yahoo.com',
180 'billing_postal_code-5' => '',
181 ), $result['values']['Billing']);
184 function testProfileGetMultipleHasBillingLocation() {
185 $individual = $this->_createIndividualContact();
186 $contactId = key($individual);
187 $this->callAPISuccess('address', 'create', array('contact_id' => $contactId , 'street_address' => '25 Big Street', 'city' => 'big city', 'location_type_id' => 5));
188 $this->callAPISuccess('email', 'create', array('contact_id' => $contactId , 'email' => 'big@once.com', 'location_type_id' => 2, 'is_billing' => 1));
190 $expected = current($individual);
193 'profile_id' => array($this->_profileID
, 1, 'Billing'),
194 'contact_id' => $contactId,
197 $result = $this->callAPISuccess('profile', 'get', $params, __FUNCTION__
, __FILE__
);
198 $this->assertEquals('abc1', $result['values'][1]['first_name']);
199 $this->assertEquals($result['values']['Billing'], array(
200 'billing_first_name' => 'abc1',
201 'billing_middle_name' => 'J.',
202 'billing_last_name' => 'xyz1',
203 'billing_street_address-5' => '25 Big Street',
204 'billing_city-5' => 'big city',
205 'billing_state_province_id-5' => '',
206 'billing_country_id-5' => '',
207 'billing-email-5' => 'big@once.com',
208 'email-5' => 'big@once.com',
209 'billing_postal_code-5' => '',
214 * Get Billing empty contact - this will return generic defaults
216 function testProfileGetBillingEmptyContact() {
219 'profile_id' => array('Billing'),
222 $result = $this->callAPISuccess('profile', 'get', $params);
223 $this->assertEquals(array(
224 'billing_first_name' => '',
225 'billing_middle_name' => '',
226 'billing_last_name' => '',
227 'billing_street_address-5' => '',
228 'billing_city-5' => '',
229 'billing_state_province_id-5' => '',
230 'billing_country_id-5' => '1228',
231 'billing_email-5' => '',
233 'billing_postal_code-5' => '',
234 ), $result['values']['Billing']);
238 * Check contact activity profile without activity id
240 function testContactActivityGetWithoutActivityId() {
241 list($params, $expected) = $this->_createContactWithActivity();
243 unset($params['activity_id']);
244 $result = $this->callAPIFailure('profile', 'get', $params,
245 'Mandatory key(s) missing from params array: activity_id');
249 * Check contact activity profile wrong activity id
251 function testContactActivityGetWrongActivityId() {
252 list($params, $expected) = $this->_createContactWithActivity();
254 $params['activity_id'] = 100001;
255 $result = $this->callAPIFailure('profile', 'get', $params,
256 'Invalid Activity Id (aid).');
260 * Check contact activity profile with wrong activity type
262 function testContactActivityGetWrongActivityType() {
263 //flush cache by calling with reset
264 $activityTypes = CRM_Core_PseudoConstant
::activityType(TRUE, TRUE, TRUE, 'name', TRUE);
266 $sourceContactId = $this->householdCreate();
268 $activityparams = array(
269 'source_contact_id' => $sourceContactId,
270 'activity_type_id' => '2',
271 'subject' => 'Test activity',
272 'activity_date_time' => '20110316',
274 'location' => 'Pensulvania',
275 'details' => 'a test activity',
277 'priority_id' => '1',
280 $activity = $this->callAPISuccess('activity', 'create', $activityparams);
282 $activityValues = array_pop($activity['values']);
284 list($params, $expected) = $this->_createContactWithActivity();
286 $params['activity_id'] = $activityValues['id'];
287 $result = $this->callAPIFailure('profile', 'get', $params,
288 'This activity cannot be edited or viewed via this profile.'
293 * Check contact activity profile with success
295 function testContactActivityGetSuccess() {
296 list($params, $expected) = $this->_createContactWithActivity();
298 $result = $this->callAPISuccess('profile', 'get', $params);
300 foreach ($expected as $profileField => $value) {
301 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $result['values']), "In line " . __LINE__
. " error message: " . "missing/mismatching value for {$profileField}"
307 * Check getfields works & gives us our fields
309 function testGetFields() {
310 $this->_createIndividualProfile();
311 $this->_addCustomFieldToProfile($this->_profileID
);
312 $result = $this->callAPIAndDocument('profile', 'getfields', array('action' => 'submit', 'profile_id' => $this->_profileID
), __FUNCTION__
, __FILE__
,
313 'demonstrates retrieving profile fields passing in an id');
314 $this->assertArrayKeyExists('first_name', $result['values']);
315 $this->assertEquals('2', $result['values']['first_name']['type']);
316 $this->assertEquals('Email', $result['values']['email-primary']['title']);
317 $this->assertEquals('civicrm_state_province', $result['values']['state_province-1']['pseudoconstant']['table']);
318 $this->assertEquals('defaultValue', $result['values']['custom_1']['default_value']);
319 $this->assertFalse(array_key_exists('participant_status', $result['values']));
323 * Check getfields works & gives us our fields - partipant profile
325 function testGetFieldsParticipantProfile() {
326 $result = $this->callAPISuccess('profile', 'getfields', array(
327 'action' => 'submit',
328 'profile_id' => 'participant_status',
329 '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 function testGetFieldsMembershipBatchProfile() {
341 $result = $this->callAPISuccess('profile', 'getfields', array(
342 'action' => 'submit',
343 'profile_id' => 'membership_batch_entry',
344 'get_options' => 'all')
346 $this->assertTrue(array_key_exists('total_amount', $result['values']));
347 $this->assertTrue(array_key_exists('financial_type_id', $result['values']));
348 $this->assertEquals(array('contribution_type_id', 'contribution_type', 'financial_type'), $result['values']['financial_type_id']['api.aliases']);
349 $this->assertTrue(!array_key_exists('financial_type', $result['values']));
350 $this->assertEquals(12, $result['values']['receive_date']['type']);
354 * Check getfields works & gives us our fields - do them all
355 * (getting to the end with no e-notices is pretty good evidence it's working)
357 function testGetFieldsAllProfiles() {
358 $result = $this->callAPISuccess('uf_group', 'get', array('return' => 'id'));
359 $profileIDs = array_keys($result['values']);
360 foreach ($profileIDs as $profileID) {
361 $result = $this->callAPISuccess('profile', 'getfields', array(
362 'action' => 'submit',
363 'profile_id' => $profileID,
364 'get_options' => 'all')
368 /////////////// test $this->callAPISuccess3_profile_set //////////////////
371 * Check Without ProfileId
373 function testProfileSubmitWithoutProfileId() {
377 $result = $this->callAPIFailure('profile', 'submit', $params,
378 'Mandatory key(s) missing from params array: profile_id'
383 * Check with no invalid profile Id
385 function testProfileSubmitInvalidProfileId() {
388 'profile_id' => 1000,
390 $result = $this->callAPIFailure('profile', 'submit', $params);
394 * Check with missing required field in profile
396 function testProfileSubmitCheckProfileRequired() {
397 $pofileFieldValues = $this->_createIndividualContact();
398 current($pofileFieldValues);
399 $contactId = key($pofileFieldValues);
400 $updateParams = array(
401 'first_name' => 'abc2',
402 'last_name' => 'xyz2',
403 'phone-1-1' => '022 321 826',
404 'country-1' => '1013',
405 'state_province-1' => '1000',
408 $params = array_merge(array('profile_id' => $this->_profileID
, 'contact_id' => $contactId),
412 $result = $this->callAPIFailure('profile', 'submit', $params,
413 "Missing required parameters for profile id $this->_profileID: email-Primary"
420 function testProfileSubmit() {
421 $pofileFieldValues = $this->_createIndividualContact();
422 current($pofileFieldValues);
423 $contactId = key($pofileFieldValues);
425 $updateParams = array(
426 'first_name' => 'abc2',
427 'last_name' => 'xyz2',
428 'email-primary' => 'abc2.xyz2@gmail.com',
429 'phone-1-1' => '022 321 826',
430 'country-1' => '1013',
431 'state_province-1' => '1000',
434 $params = array_merge(array(
435 'profile_id' => $this->_profileID
,
436 'contact_id' => $contactId,
439 $result = $this->callAPIAndDocument('profile', 'submit', $params, __FUNCTION__
, __FILE__
);
442 'profile_id' => $this->_profileID
,
443 'contact_id' => $contactId,
445 $profileDetails = $this->callAPISuccess('profile', 'get', $getParams);
447 foreach ($updateParams as $profileField => $value) {
448 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $profileDetails['values']), "missing/mismatching value for {$profileField}"
451 unset($params['email-primary']);
452 $params['email-Primary'] = 'my@mail.com';
453 $this->callAPISuccess('profile', 'submit', $params);
454 $profileDetails = $this->callAPISuccess('profile', 'get', $getParams);
455 $this->assertEquals('my@mail.com', $profileDetails['values']['email-Primary']);
459 * Ensure caches are being cleared so we don't get into a debugging trap because of cached metadata
460 * First we delete & create to increment the version & then check for caching probs
462 function testProfileSubmitCheckCaching() {
463 $this->callAPISuccess('membership_type', 'delete', array('id' => $this->_membershipTypeID
));
464 $this->_membershipTypeID
= $this->membershipTypeCreate();
466 $membershipTypes = $this->callAPISuccess('membership_type', 'get', array());
467 $profileFields = $this->callAPISuccess('profile', 'getfields', array('get_options' => 'all', 'action' => 'submit', 'profile_id' => 'membership_batch_entry'));
468 $getoptions = $this->callAPISuccess('membership', 'getoptions', array('field' => 'membership_type', 'context' => 'validate'));
469 $this->assertEquals(array_keys($membershipTypes['values']), array_keys($getoptions['values']));
470 $this->assertEquals(array_keys($membershipTypes['values']), array_keys($profileFields['values']['membership_type_id']['options']));
475 * Test that the fields are returned in the right order despite the faffing around that goes on
477 function testMembershipGetFieldsOrder() {
478 $result = $this->callAPISuccess('profile', 'getfields', array('action' => 'submit', 'profile_id' => 'membership_batch_entry'));
480 foreach($result['values'] as $fieldName => $field) {
481 if($fieldName == 'profile_id') {
484 $this->assertEquals($field['weight'], $weight);
489 * Check we can submit membership batch profiles (create mode)
491 function testProfileSubmitMembershipBatch() {
492 $this->_contactID
= $this->individualCreate();
493 $this->callAPISuccess('profile', 'submit', array(
494 'profile_id' => 'membership_batch_entry',
495 'financial_type_id' => 1,
496 'membership_type' => $this->_membershipTypeID
,
497 'join_date' => 'now',
498 'total_amount' => 10,
499 'contribution_status_id' => 1,
500 'receive_date' => 'now',
501 'contact_id' => $this->_contactID
,
505 * Set is deprecated but we need to ensure it still works
507 function testLegacySet() {
508 $pofileFieldValues = $this->_createIndividualContact();
509 current($pofileFieldValues);
510 $contactId = key($pofileFieldValues);
512 $updateParams = array(
513 'first_name' => 'abc2',
514 'last_name' => 'xyz2',
515 'email-Primary' => 'abc2.xyz2@gmail.com',
516 'phone-1-1' => '022 321 826',
517 'country-1' => '1013',
518 'state_province-1' => '1000',
521 $params = array_merge(array(
522 'profile_id' => $this->_profileID
,
523 'contact_id' => $contactId,
526 $result = $this->callAPISuccess('profile', 'set', $params);
527 $this->assertArrayKeyExists('values', $result);
529 'profile_id' => $this->_profileID
,
530 'contact_id' => $contactId,
532 $profileDetails = $this->callAPISuccess('profile', 'get', $getParams);
534 foreach ($updateParams as $profileField => $value) {
535 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $profileDetails['values']), "In line " . __LINE__
. " error message: " . "missing/mismatching value for {$profileField}"
541 * Check contact activity profile without activity id
543 function testContactActivitySubmitWithoutActivityId() {
544 list($params, $expected) = $this->_createContactWithActivity();
546 $params = array_merge($params, $expected);
547 unset($params['activity_id']);
548 $result = $this->callAPIFailure('profile', 'submit', $params);
549 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: activity_id');
553 * Check contact activity profile wrong activity id
555 function testContactActivitySubmitWrongActivityId() {
556 list($params, $expected) = $this->_createContactWithActivity();
557 $params = array_merge($params, $expected);
558 $params['activity_id'] = 100001;
559 $result = $this->callAPIFailure('profile', 'submit', $params);
560 $this->assertEquals($result['error_message'], 'Invalid Activity Id (aid).');
564 * Check contact activity profile with wrong activity type
566 function testContactActivitySubmitWrongActivityType() {
567 //flush cache by calling with reset
568 $activityTypes = CRM_Core_PseudoConstant
::activityType(TRUE, TRUE, TRUE, 'name', TRUE);
570 $sourceContactId = $this->householdCreate();
572 $activityparams = array(
573 'source_contact_id' => $sourceContactId,
574 'activity_type_id' => '2',
575 'subject' => 'Test activity',
576 'activity_date_time' => '20110316',
578 'location' => 'Pensulvania',
579 'details' => 'a test activity',
581 'priority_id' => '1',
584 $activity = $this->callAPISuccess('activity', 'create', $activityparams);
586 $activityValues = array_pop($activity['values']);
588 list($params, $expected) = $this->_createContactWithActivity();
590 $params = array_merge($params, $expected);
591 $params['activity_id'] = $activityValues['id'];
592 $result = $this->callAPIFailure('profile', 'submit', $params,
593 'This activity cannot be edited or viewed via this profile.');
597 * Check contact activity profile with success
599 function testContactActivitySubmitSuccess() {
600 list($params, $expected) = $this->_createContactWithActivity();
602 $updateParams = array(
603 'first_name' => 'abc2',
604 'last_name' => 'xyz2',
605 'email-Primary' => 'abc2.xyz2@yahoo.com',
606 'activity_subject' => 'Test Meeting',
607 'activity_details' => 'a test activity details',
608 'activity_duration' => '100',
609 'activity_date_time' => '03/08/2010',
610 'activity_status_id' => '2',
612 $profileParams = array_merge($params, $updateParams);
613 $this->callAPISuccess('profile', 'submit', $profileParams);
614 $result = $this->callAPISuccess('profile', 'get', $params);
616 foreach ($updateParams as $profileField => $value) {
617 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $result['values']), "In line " . __LINE__
. " error message: " . "missing/mismatching value for {$profileField}"
623 * Check profile apply Without ProfileId
625 function testProfileApplyWithoutProfileId() {
629 $result = $this->callAPIFailure('profile', 'apply', $params,
630 'Mandatory key(s) missing from params array: profile_id');
634 * Check profile apply with no invalid profile Id
636 function testProfileApplyInvalidProfileId() {
639 'profile_id' => 1000,
641 $result = $this->callAPIFailure('profile', 'apply', $params);
647 function testProfileApply() {
648 $pofileFieldValues = $this->_createIndividualContact();
649 current($pofileFieldValues);
650 $contactId = key($pofileFieldValues);
653 'profile_id' => $this->_profileID
,
654 'contact_id' => $contactId,
655 'first_name' => 'abc2',
656 'last_name' => 'xyz2',
657 'email-Primary' => 'abc2.xyz2@gmail.com',
658 'phone-1-1' => '022 321 826',
659 'country-1' => '1013',
660 'state_province-1' => '1000',
663 $result = $this->callAPIAndDocument('profile', 'apply', $params, __FUNCTION__
, __FILE__
);
665 // Expected field values
666 $expected['contact'] = array(
667 'contact_id' => $contactId,
668 'contact_type' => 'Individual',
669 'first_name' => 'abc2',
670 'last_name' => 'xyz2',
672 $expected['email'] = array(
673 'location_type_id' => 1,
675 'email' => 'abc2.xyz2@gmail.com',
678 $expected['phone'] = array(
679 'location_type_id' => 1,
681 'phone_type_id' => 1,
682 'phone' => '022 321 826',
684 $expected['address'] = array(
685 'location_type_id' => 1,
687 'country_id' => 1013,
688 'state_province_id' => 1000,
691 foreach ($expected['contact'] as $field => $value) {
692 $this->assertEquals($value, CRM_Utils_Array
::value($field, $result['values']), "In line " . __LINE__
. " error message: " . "missing/mismatching value for {$field}"
697 'email', 'phone', 'address') as $fieldType) {
698 $typeValues = array_pop($result['values'][$fieldType]);
699 foreach ($expected[$fieldType] as $field => $value) {
700 $this->assertEquals($value, CRM_Utils_Array
::value($field, $typeValues), "In line " . __LINE__
. " error message: " . "missing/mismatching value for {$field} ({$fieldType})"
707 * Helper function to create an Individual with address/email/phone info. Import UF Group and UF Fields
708 * @param array $params
712 function _createIndividualContact($params = array()) {
713 $contactParams = array_merge(array(
714 'first_name' => 'abc1',
715 'last_name' => 'xyz1',
716 'email' => 'abc1.xyz1@yahoo.com',
717 'api.address.create' => array(
718 'location_type_id' => 1,
720 'street_address' => '5 Saint Helier St',
722 'country' => 'United States',
723 'state_province' => 'Michigan',
724 'supplemental_address_1' => 'Hallmark Ct',
725 'supplemental_address_2' => 'Jersey Village',
726 'postal_code' => '90210',
727 'city' => 'Gotham City',
730 'api.phone.create' => array(
731 'location_type_id' => '1',
732 'phone' => '021 512 755',
733 'phone_type_id' => '1',
739 $this->_contactID
= $this->individualCreate($contactParams);
740 $this->_createIndividualProfile();
741 // expected result of above created profile with contact Id $contactId
742 $profileData[$this->_contactID
] = array(
743 'first_name' => 'abc1',
744 'last_name' => 'xyz1',
745 'email-primary' => 'abc1.xyz1@yahoo.com',
746 'phone-1-1' => '021 512 755',
747 'country-1' => '1228',
748 'state_province-1' => '1021',
757 function _createContactWithActivity() {
758 // @TODO: Create profile with custom fields
759 $op = new PHPUnit_Extensions_Database_Operation_Insert();
760 $op->execute($this->_dbconn
,
761 $this->createFlatXMLDataSet(
762 dirname(__FILE__
) . '/dataset/uf_group_contact_activity_26.xml'
765 // hack: xml data set do not accept \ 1 (CRM_Core_DAO::VALUE_SEPARATOR)
766 CRM_Core_DAO
::setFieldValue('CRM_Core_DAO_UFGroup', '26', 'group_type', 'Individual,Contact,Activity' . CRM_Core_DAO
::VALUE_SEPARATOR
. 'ActivityType:1');
768 $sourceContactId = $this->individualCreate();
769 $contactParams = array(
770 'first_name' => 'abc1',
771 'last_name' => 'xyz1',
772 'contact_type' => 'Individual',
773 'email' => 'abc1.xyz1@yahoo.com',
774 'api.address.create' => array(
775 'location_type_id' => 1,
777 'name' => 'Saint Helier St',
779 'country' => 'United States',
780 'state_province' => 'Michigan',
781 'supplemental_address_1' => 'Hallmark Ct',
782 'supplemental_address_2' => 'Jersey Village',
786 $contact = $this->callAPISuccess('contact', 'create', $contactParams);
788 $keys = array_keys($contact['values']);
789 $contactId = array_pop($keys);
791 $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'])
794 $activityParams = array(
795 'source_contact_id' => $sourceContactId,
796 'assignee_contact_id' => $contactId,
797 'activity_type_id' => '1',
798 'subject' => 'Make-it-Happen Meeting',
799 'activity_date_time' => '20110316',
801 'location' => 'Pensulvania',
802 'details' => 'a test activity',
804 'priority_id' => '1',
806 $activity = $this->callAPISuccess('activity', 'create', $activityParams);
808 $activityValues = array_pop($activity['values']);
810 // valid parameters for above profile
811 $profileParams = array(
813 'contact_id' => $contactId,
814 'activity_id' => $activityValues['id'],
817 // expected result of above created profile
819 'first_name' => 'abc1',
820 'last_name' => 'xyz1',
821 'email-Primary' => 'abc1.xyz1@yahoo.com',
822 'activity_subject' => 'Make-it-Happen Meeting',
823 'activity_details' => 'a test activity',
824 'activity_duration' => '120',
825 'activity_date_time_time' => '12:00AM',
826 'activity_date_time' => '03/16/2011',
827 'activity_status_id' => '1',
830 return array($profileParams, $expected);
835 function _createIndividualProfile() {
837 // creating these via the api as we want to utilise & test the flushing of caches when fields created
840 $ufGroupParams = array(
841 'group_type' => 'Individual,Contact',// really we should remove this & test the ufField create sets it
842 'name' => 'test_individual_contact_profile',
843 'title' => 'Flat Coffee',
844 'api.uf_field.create' => array(
846 'field_name' => 'first_name',
848 'visibility' => 'Public Pages and Listings',
849 'field_type' => 'Individual',
850 'label' => 'First Name',
853 'field_name' => 'last_name',
855 'visibility' => 'Public Pages and Listings',
856 'field_type' => 'Individual',
857 'label' => 'Last Name',
860 'field_name' => 'email',
862 'visibility' => 'Public Pages and Listings',
863 'field_type' => 'Contact',
867 'field_name' => 'phone',
869 'visibility' => 'Public Pages and Listings',
870 'field_type' => 'Contact',
871 'location_type_id' => 1,
872 'phone_type_id' => 1,
876 'field_name' => 'country',
878 'visibility' => 'Public Pages and Listings',
879 'field_type' => 'Contact',
880 'location_type_id' => 1,
884 'field_name' => 'state_province',
886 'visibility' => 'Public Pages and Listings',
887 'field_type' => 'Contact',
888 'location_type_id' => 1,
889 'label' => 'State Province'
892 'field_name' => 'postal_code',
894 'field_type' => 'Contact',
895 'location_type_id' => 1,
896 'label' => 'State Province'
900 $profile = $this->callAPISuccess('uf_group', 'create', $ufGroupParams);
901 $this->_profileID
= $profile['id'];
905 * @param int $profileID
907 function _addCustomFieldToProfile($profileID) {
908 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, '');
909 $this->uFFieldCreate(array('uf_group_id' => $profileID, 'field_name' => 'custom_' . $ids['custom_field_id'], 'contact_type' => 'Contact'));