4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.4 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
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;
46 'name' => 'Profile Test',
47 'description' => 'Test all profile API methods.',
48 'group' => 'CiviCRM API Tests',
53 $this->_apiversion
= 3;
55 $config = CRM_Core_Config
::singleton();
56 $config->countryLimit
[1] = 1013;
57 $config->stateLimit
[1] = 1013;
58 $this->createLoggedInUser();
59 $this->_membershipTypeID
= $this->membershipTypeCreate();
64 $this->quickCleanup(array(
69 'civicrm_contribution',
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)");
76 ////////////// test $this->callAPISuccess3_profile_get //////////////////
79 * check Without ProfileId
81 function testProfileGetWithoutProfileId() {
85 $result = $this->callAPIFailure('profile', 'get', $params,
86 'Mandatory key(s) missing from params array: profile_id'
91 * check with no invalid profile Id
93 function testProfileGetInvalidProfileId() {
98 $result = $this->callAPIFailure('profile', 'get', $params);
104 function testProfileGet() {
105 $pofileFieldValues = $this->_createIndividualContact();
106 $expected = current($pofileFieldValues);
107 $contactId = key($pofileFieldValues);
109 'profile_id' => $this->_profileID
,
110 'contact_id' => $contactId,
112 $result = $this->callAPISuccess('profile', 'get', $params);
113 foreach ($expected as $profileField => $value) {
114 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $result['values']));
118 function testProfileGetMultiple() {
119 $pofileFieldValues = $this->_createIndividualContact();
120 $expected = current($pofileFieldValues);
121 $contactId = key($pofileFieldValues);
123 'profile_id' => array($this->_profileID
, 1, 'Billing'),
124 'contact_id' => $contactId,
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}");
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',
148 function testProfileGetBillingUseIsBillingLocation() {
149 $individual = $this->_createIndividualContact();
150 $contactId = key($individual);
151 $this->callAPISuccess('address', 'create', array(
153 'street_address' => 'is billing st',
154 'location_type_id' => 2,
155 'contact_id' => $contactId,
158 $expected = current($individual);
161 'profile_id' => array($this->_profileID
, 1, 'Billing'),
162 'contact_id' => $contactId,
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']);
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));
187 $expected = current($individual);
190 'profile_id' => array($this->_profileID
, 1, 'Billing'),
191 'contact_id' => $contactId,
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' => '',
211 * get Billing empty contact - this will return generic defaults
213 function testProfileGetBillingEmptyContact() {
216 'profile_id' => array('Billing'),
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' => '',
230 'billing_postal_code-5' => '',
231 ), $result['values']['Billing']);
235 * check contact activity profile without activity id
237 function testContactActivityGetWithoutActivityId() {
238 list($params, $expected) = $this->_createContactWithActivity();
240 unset($params['activity_id']);
241 $result = $this->callAPIFailure('profile', 'get', $params,
242 'Mandatory key(s) missing from params array: activity_id');
246 * check contact activity profile wrong activity id
248 function testContactActivityGetWrongActivityId() {
249 list($params, $expected) = $this->_createContactWithActivity();
251 $params['activity_id'] = 100001;
252 $result = $this->callAPIFailure('profile', 'get', $params,
253 'Invalid Activity Id (aid).');
257 * check contact activity profile with wrong activity type
259 function testContactActivityGetWrongActivityType() {
260 //flush cache by calling with reset
261 $activityTypes = CRM_Core_PseudoConstant
::activityType(TRUE, TRUE, TRUE, 'name', TRUE);
263 $sourceContactId = $this->householdCreate();
265 $activityparams = array(
266 'source_contact_id' => $sourceContactId,
267 'activity_type_id' => '2',
268 'subject' => 'Test activity',
269 'activity_date_time' => '20110316',
271 'location' => 'Pensulvania',
272 'details' => 'a test activity',
274 'priority_id' => '1',
277 $activity = $this->callAPISuccess('activity', 'create', $activityparams);
279 $activityValues = array_pop($activity['values']);
281 list($params, $expected) = $this->_createContactWithActivity();
283 $params['activity_id'] = $activityValues['id'];
284 $result = $this->callAPIFailure('profile', 'get', $params,
285 'This activity cannot be edited or viewed via this profile.'
290 * check contact activity profile with success
292 function testContactActivityGetSuccess() {
293 list($params, $expected) = $this->_createContactWithActivity();
295 $result = $this->callAPISuccess('profile', 'get', $params);
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}"
304 * Check getfields works & gives us our fields
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']));
319 * Check getfields works & gives us our fields - partipant profile
321 function testGetFieldsParticipantProfile() {
322 $result = $this->callAPISuccess('profile', 'getfields', array(
323 'action' => 'submit',
324 'profile_id' => 'participant_status',
325 'get_options' => 'all')
327 $this->assertTrue(array_key_exists('participant_status_id', $result['values']));
328 $this->assertEquals('Attended', $result['values']['participant_status_id']['options'][2]);
329 $this->assertEquals(array('participant_status'), $result['values']['participant_status_id']['api.aliases']);
333 * Check getfields works & gives us our fields - membership_batch_entry
334 * (getting to the end with no e-notices is pretty good evidence it's working)
336 function testGetFieldsMembershipBatchProfile() {
337 $result = $this->callAPISuccess('profile', 'getfields', array(
338 'action' => 'submit',
339 'profile_id' => 'membership_batch_entry',
340 'get_options' => 'all')
342 $this->assertTrue(array_key_exists('total_amount', $result['values']));
343 $this->assertTrue(array_key_exists('financial_type_id', $result['values']));
344 $this->assertEquals(array('contribution_type_id', 'contribution_type', 'financial_type'), $result['values']['financial_type_id']['api.aliases']);
345 $this->assertTrue(!array_key_exists('financial_type', $result['values']));
346 $this->assertEquals(12, $result['values']['receive_date']['type']);
350 * Check getfields works & gives us our fields - do them all
351 * (getting to the end with no e-notices is pretty good evidence it's working)
353 function testGetFieldsAllProfiles() {
354 $result = $this->callAPISuccess('uf_group', 'get', array('return' => 'id'));
355 $profileIDs = array_keys($result['values']);
356 foreach ($profileIDs as $profileID) {
357 $result = $this->callAPISuccess('profile', 'getfields', array(
358 'action' => 'submit',
359 'profile_id' => $profileID,
360 'get_options' => 'all')
364 /////////////// test $this->callAPISuccess3_profile_set //////////////////
367 * check Without ProfileId
369 function testProfileSubmitWithoutProfileId() {
373 $result = $this->callAPIFailure('profile', 'submit', $params,
374 'Mandatory key(s) missing from params array: profile_id'
379 * check with no invalid profile Id
381 function testProfileSubmitInvalidProfileId() {
384 'profile_id' => 1000,
386 $result = $this->callAPIFailure('profile', 'submit', $params);
390 * check with missing required field in profile
392 function testProfileSubmitCheckProfileRequired() {
393 $pofileFieldValues = $this->_createIndividualContact();
394 current($pofileFieldValues);
395 $contactId = key($pofileFieldValues);
396 $updateParams = array(
397 'first_name' => 'abc2',
398 'last_name' => 'xyz2',
399 'phone-1-1' => '022 321 826',
400 'country-1' => '1013',
401 'state_province-1' => '1000',
404 $params = array_merge(array('profile_id' => $this->_profileID
, 'contact_id' => $contactId),
408 $result = $this->callAPIFailure('profile', 'submit', $params,
409 "Missing required parameters for profile id $this->_profileID: email-Primary"
416 function testProfileSubmit() {
417 $pofileFieldValues = $this->_createIndividualContact();
418 current($pofileFieldValues);
419 $contactId = key($pofileFieldValues);
421 $updateParams = array(
422 'first_name' => 'abc2',
423 'last_name' => 'xyz2',
424 'email-primary' => 'abc2.xyz2@gmail.com',
425 'phone-1-1' => '022 321 826',
426 'country-1' => '1013',
427 'state_province-1' => '1000',
430 $params = array_merge(array(
431 'profile_id' => $this->_profileID
,
432 'contact_id' => $contactId,
435 $result = $this->callAPIAndDocument('profile', 'submit', $params, __FUNCTION__
, __FILE__
);
438 'profile_id' => $this->_profileID
,
439 'contact_id' => $contactId,
441 $profileDetails = $this->callAPISuccess('profile', 'get', $getParams);
443 foreach ($updateParams as $profileField => $value) {
444 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $profileDetails['values']), "missing/mismatching value for {$profileField}"
447 unset($params['email-primary']);
448 $params['email-Primary'] = 'my@mail.com';
449 $this->callAPISuccess('profile', 'submit', $params);
450 $profileDetails = $this->callAPISuccess('profile', 'get', $getParams);
451 $this->assertEquals('my@mail.com', $profileDetails['values']['email-Primary']);
455 * Ensure caches are being cleared so we don't get into a debugging trap because of cached metadata
456 * First we delete & create to increment the version & then check for caching probs
458 function testProfileSubmitCheckCaching() {
459 $this->callAPISuccess('membership_type', 'delete', array('id' => $this->_membershipTypeID
));
460 $this->_membershipTypeID
= $this->membershipTypeCreate();
462 $membershipTypes = $this->callAPISuccess('membership_type', 'get', array());
463 $profileFields = $this->callAPISuccess('profile', 'getfields', array('get_options' => 'all', 'action' => 'submit', 'profile_id' => 'membership_batch_entry'));
464 $getoptions = $this->callAPISuccess('membership', 'getoptions', array('field' => 'membership_type', 'context' => 'validate'));
465 $this->assertEquals(array_keys($membershipTypes['values']), array_keys($getoptions['values']));
466 $this->assertEquals(array_keys($membershipTypes['values']), array_keys($profileFields['values']['membership_type_id']['options']));
471 * Test that the fields are returned in the right order despite the faffing around that goes on
473 function testMembershipGetFieldsOrder() {
474 $result = $this->callAPISuccess('profile', 'getfields', array('action' => 'submit', 'profile_id' => 'membership_batch_entry'));
476 foreach($result['values'] as $fieldName => $field) {
477 if($fieldName == 'profile_id') {
480 $this->assertEquals($field['weight'], $weight);
485 * Check we can submit membership batch profiles (create mode)
487 function testProfileSubmitMembershipBatch() {
488 $this->_contactID
= $this->individualCreate();
489 $this->callAPISuccess('profile', 'submit', array(
490 'profile_id' => 'membership_batch_entry',
491 'financial_type_id' => 1,
492 'membership_type' => $this->_membershipTypeID
,
493 'join_date' => 'now',
494 'total_amount' => 10,
495 'contribution_status_id' => 1,
496 'receive_date' => 'now',
497 'contact_id' => $this->_contactID
,
501 * set is deprecated but we need to ensure it still works
503 function testLegacySet() {
504 $pofileFieldValues = $this->_createIndividualContact();
505 current($pofileFieldValues);
506 $contactId = key($pofileFieldValues);
508 $updateParams = array(
509 'first_name' => 'abc2',
510 'last_name' => 'xyz2',
511 'email-Primary' => 'abc2.xyz2@gmail.com',
512 'phone-1-1' => '022 321 826',
513 'country-1' => '1013',
514 'state_province-1' => '1000',
517 $params = array_merge(array(
518 'profile_id' => $this->_profileID
,
519 'contact_id' => $contactId,
522 $result = $this->callAPISuccess('profile', 'set', $params);
523 $this->assertArrayKeyExists('values', $result);
525 'profile_id' => $this->_profileID
,
526 'contact_id' => $contactId,
528 $profileDetails = $this->callAPISuccess('profile', 'get', $getParams);
530 foreach ($updateParams as $profileField => $value) {
531 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $profileDetails['values']), "In line " . __LINE__
. " error message: " . "missing/mismatching value for {$profileField}"
536 * check contact activity profile without activity id
538 function testContactActivitySubmitWithoutActivityId() {
539 list($params, $expected) = $this->_createContactWithActivity();
541 $params = array_merge($params, $expected);
542 unset($params['activity_id']);
543 $result = $this->callAPIFailure('profile', 'submit', $params);
544 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: activity_id');
548 * check contact activity profile wrong activity id
550 function testContactActivitySubmitWrongActivityId() {
551 list($params, $expected) = $this->_createContactWithActivity();
552 $params = array_merge($params, $expected);
553 $params['activity_id'] = 100001;
554 $result = $this->callAPIFailure('profile', 'submit', $params);
555 $this->assertEquals($result['error_message'], 'Invalid Activity Id (aid).');
559 * check contact activity profile with wrong activity type
561 function testContactActivitySubmitWrongActivityType() {
562 //flush cache by calling with reset
563 $activityTypes = CRM_Core_PseudoConstant
::activityType(TRUE, TRUE, TRUE, 'name', TRUE);
565 $sourceContactId = $this->householdCreate();
567 $activityparams = array(
568 'source_contact_id' => $sourceContactId,
569 'activity_type_id' => '2',
570 'subject' => 'Test activity',
571 'activity_date_time' => '20110316',
573 'location' => 'Pensulvania',
574 'details' => 'a test activity',
576 'priority_id' => '1',
579 $activity = $this->callAPISuccess('activity', 'create', $activityparams);
581 $activityValues = array_pop($activity['values']);
583 list($params, $expected) = $this->_createContactWithActivity();
585 $params = array_merge($params, $expected);
586 $params['activity_id'] = $activityValues['id'];
587 $result = $this->callAPIFailure('profile', 'submit', $params,
588 'This activity cannot be edited or viewed via this profile.');
592 * check contact activity profile with success
594 function testContactActivitySubmitSuccess() {
595 list($params, $expected) = $this->_createContactWithActivity();
597 $updateParams = array(
598 'first_name' => 'abc2',
599 'last_name' => 'xyz2',
600 'email-Primary' => 'abc2.xyz2@yahoo.com',
601 'activity_subject' => 'Test Meeting',
602 'activity_details' => 'a test activity details',
603 'activity_duration' => '100',
604 'activity_date_time' => '03/08/2010',
605 'activity_status_id' => '2',
607 $profileParams = array_merge($params, $updateParams);
608 $this->callAPISuccess('profile', 'submit', $profileParams);
609 $result = $this->callAPISuccess('profile', 'get', $params);
611 foreach ($updateParams as $profileField => $value) {
612 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $result['values']), "In line " . __LINE__
. " error message: " . "missing/mismatching value for {$profileField}"
618 * check profile apply Without ProfileId
620 function testProfileApplyWithoutProfileId() {
624 $result = $this->callAPIFailure('profile', 'apply', $params,
625 'Mandatory key(s) missing from params array: profile_id');
629 * check profile apply with no invalid profile Id
631 function testProfileApplyInvalidProfileId() {
634 'profile_id' => 1000,
636 $result = $this->callAPIFailure('profile', 'apply', $params);
642 function testProfileApply() {
643 $pofileFieldValues = $this->_createIndividualContact();
644 current($pofileFieldValues);
645 $contactId = key($pofileFieldValues);
648 'profile_id' => $this->_profileID
,
649 'contact_id' => $contactId,
650 'first_name' => 'abc2',
651 'last_name' => 'xyz2',
652 'email-Primary' => 'abc2.xyz2@gmail.com',
653 'phone-1-1' => '022 321 826',
654 'country-1' => '1013',
655 'state_province-1' => '1000',
658 $result = $this->callAPIAndDocument('profile', 'apply', $params, __FUNCTION__
, __FILE__
);
660 // Expected field values
661 $expected['contact'] = array(
662 'contact_id' => $contactId,
663 'contact_type' => 'Individual',
664 'first_name' => 'abc2',
665 'last_name' => 'xyz2',
667 $expected['email'] = array(
668 'location_type_id' => 1,
670 'email' => 'abc2.xyz2@gmail.com',
673 $expected['phone'] = array(
674 'location_type_id' => 1,
676 'phone_type_id' => 1,
677 'phone' => '022 321 826',
679 $expected['address'] = array(
680 'location_type_id' => 1,
682 'country_id' => 1013,
683 'state_province_id' => 1000,
686 foreach ($expected['contact'] as $field => $value) {
687 $this->assertEquals($value, CRM_Utils_Array
::value($field, $result['values']), "In line " . __LINE__
. " error message: " . "missing/mismatching value for {$field}"
692 'email', 'phone', 'address') as $fieldType) {
693 $typeValues = array_pop($result['values'][$fieldType]);
694 foreach ($expected[$fieldType] as $field => $value) {
695 $this->assertEquals($value, CRM_Utils_Array
::value($field, $typeValues), "In line " . __LINE__
. " error message: " . "missing/mismatching value for {$field} ({$fieldType})"
702 * Helper function to create an Individual with address/email/phone info. Import UF Group and UF Fields
704 function _createIndividualContact($params = array()) {
705 $contactParams = array_merge(array(
706 'first_name' => 'abc1',
707 'last_name' => 'xyz1',
708 'email' => 'abc1.xyz1@yahoo.com',
709 'api.address.create' => array(
710 'location_type_id' => 1,
712 'street_address' => '5 Saint Helier St',
714 'country' => 'United States',
715 'state_province' => 'Michigan',
716 'supplemental_address_1' => 'Hallmark Ct',
717 'supplemental_address_2' => 'Jersey Village',
718 'postal_code' => '90210',
719 'city' => 'Gotham City',
722 'api.phone.create' => array(
723 'location_type_id' => '1',
724 'phone' => '021 512 755',
725 'phone_type_id' => '1',
731 $this->_contactID
= $this->individualCreate($contactParams);
732 $this->_createIndividualProfile();
733 // expected result of above created profile with contact Id $contactId
734 $profileData[$this->_contactID
] = array(
735 'first_name' => 'abc1',
736 'last_name' => 'xyz1',
737 'email-primary' => 'abc1.xyz1@yahoo.com',
738 'phone-1-1' => '021 512 755',
739 'country-1' => '1228',
740 'state_province-1' => '1021',
746 function _createContactWithActivity() {
747 // @TODO: Create profile with custom fields
748 $op = new PHPUnit_Extensions_Database_Operation_Insert();
749 $op->execute($this->_dbconn
,
750 new PHPUnit_Extensions_Database_DataSet_FlatXMLDataSet(
751 dirname(__FILE__
) . '/dataset/uf_group_contact_activity_26.xml'
754 // hack: xml data set do not accept \ 1 (CRM_Core_DAO::VALUE_SEPARATOR)
755 CRM_Core_DAO
::setFieldValue('CRM_Core_DAO_UFGroup', '26', 'group_type', 'Individual,Contact,Activity' . CRM_Core_DAO
::VALUE_SEPARATOR
. 'ActivityType:1');
757 $sourceContactId = $this->individualCreate();
758 $contactParams = array(
759 'first_name' => 'abc1',
760 'last_name' => 'xyz1',
761 'contact_type' => 'Individual',
762 'email' => 'abc1.xyz1@yahoo.com',
763 'api.address.create' => array(
764 'location_type_id' => 1,
766 'name' => 'Saint Helier St',
768 'country' => 'United States',
769 'state_province' => 'Michigan',
770 'supplemental_address_1' => 'Hallmark Ct',
771 'supplemental_address_2' => 'Jersey Village',
775 $contact = $this->callAPISuccess('contact', 'create', $contactParams);
777 $keys = array_keys($contact['values']);
778 $contactId = array_pop($keys);
780 $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'])
783 $activityParams = array(
784 'source_contact_id' => $sourceContactId,
785 'assignee_contact_id' => $contactId,
786 'activity_type_id' => '1',
787 'subject' => 'Make-it-Happen Meeting',
788 'activity_date_time' => '20110316',
790 'location' => 'Pensulvania',
791 'details' => 'a test activity',
793 'priority_id' => '1',
795 $activity = $this->callAPISuccess('activity', 'create', $activityParams);
797 $activityValues = array_pop($activity['values']);
799 // valid parameters for above profile
800 $profileParams = array(
802 'contact_id' => $contactId,
803 'activity_id' => $activityValues['id'],
806 // expected result of above created profile
808 'first_name' => 'abc1',
809 'last_name' => 'xyz1',
810 'email-Primary' => 'abc1.xyz1@yahoo.com',
811 'activity_subject' => 'Make-it-Happen Meeting',
812 'activity_details' => 'a test activity',
813 'activity_duration' => '120',
814 'activity_date_time_time' => '12:00AM',
815 'activity_date_time' => '03/16/2011',
816 'activity_status_id' => '1',
819 return array($profileParams, $expected);
824 function _createIndividualProfile() {
826 // creating these via the api as we want to utilise & test the flushing of caches when fields created
829 $ufGroupParams = array(
830 'group_type' => 'Individual,Contact',// really we should remove this & test the ufField create sets it
831 'name' => 'test_individual_contact_profile',
832 'title' => 'Flat Coffee',
833 'api.uf_field.create' => array(
835 'field_name' => 'first_name',
837 'visibility' => 'Public Pages and Listings',
838 'field_type' => 'Individual',
839 'label' => 'First Name',
842 'field_name' => 'last_name',
844 'visibility' => 'Public Pages and Listings',
845 'field_type' => 'Individual',
846 'label' => 'Last Name',
849 'field_name' => 'email',
851 'visibility' => 'Public Pages and Listings',
852 'field_type' => 'Contact',
856 'field_name' => 'phone',
858 'visibility' => 'Public Pages and Listings',
859 'field_type' => 'Contact',
860 'location_type_id' => 1,
861 'phone_type_id' => 1,
865 'field_name' => 'country',
867 'visibility' => 'Public Pages and Listings',
868 'field_type' => 'Contact',
869 'location_type_id' => 1,
873 'field_name' => 'state_province',
875 'visibility' => 'Public Pages and Listings',
876 'field_type' => 'Contact',
877 'location_type_id' => 1,
878 'label' => 'State Province'
881 'field_name' => 'postal_code',
883 'field_type' => 'Contact',
884 'location_type_id' => 1,
885 'label' => 'State Province'
889 $profile = $this->callAPISuccess('uf_group', 'create', $ufGroupParams);
890 $this->_profileID
= $profile['id'];
893 function _addCustomFieldToProfile($profileID) {
894 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, '');
895 $this->uFFieldCreate(array('uf_group_id' => $profileID, 'field_name' => 'custom_' . $ids['custom_field_id'], 'contact_type' => 'Contact'));