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 * Include class definitions
31 require_once 'tests/phpunit/CiviTest/CiviUnitTestCase.php';
34 * Test APIv3 civicrm_profile_* functions
38 class api_v3_ProfileTest
extends CiviUnitTestCase
{
39 protected $_apiversion;
40 protected $_profileID = 0;
41 protected $_membershipTypeID;
42 protected $_contactID;
44 public function setUp() {
45 $this->_apiversion
= 3;
47 $config = CRM_Core_Config
::singleton();
48 $countryLimit = $config->countryLimit
;
49 $countryLimit[1] = 1013;
50 $config->countryLimit
= $countryLimit;
52 $this->createLoggedInUser();
53 $this->_membershipTypeID
= $this->membershipTypeCreate();
56 public function tearDown() {
58 $this->quickCleanup(array(
63 'civicrm_contribution',
66 $this->callAPISuccess('membership_type', 'delete', array('id' => $this->_membershipTypeID
));
67 // ok can't be bothered wring an api to do this & truncating is crazy
68 CRM_Core_DAO
::executeQuery(" DELETE FROM civicrm_uf_group WHERE id IN ($this->_profileID, 26)");
71 ////////////// test $this->callAPISuccess3_profile_get //////////////////
74 * Check Without ProfileId.
76 public function testProfileGetWithoutProfileId() {
80 $result = $this->callAPIFailure('profile', 'get', $params,
81 'Mandatory key(s) missing from params array: profile_id'
86 * Check with no invalid profile Id.
88 public function testProfileGetInvalidProfileId() {
93 $result = $this->callAPIFailure('profile', 'get', $params);
99 public function testProfileGet() {
100 $pofileFieldValues = $this->_createIndividualContact();
101 $expected = current($pofileFieldValues);
102 $contactId = key($pofileFieldValues);
104 'profile_id' => $this->_profileID
,
105 'contact_id' => $contactId,
107 $result = $this->callAPISuccess('profile', 'get', $params);
108 foreach ($expected as $profileField => $value) {
109 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $result['values']));
113 public function testProfileGetMultiple() {
114 $pofileFieldValues = $this->_createIndividualContact();
115 $expected = current($pofileFieldValues);
116 $contactId = key($pofileFieldValues);
118 'profile_id' => array($this->_profileID
, 1, 'Billing'),
119 'contact_id' => $contactId,
122 $result = $this->callAPIAndDocument('profile', 'get', $params, __FUNCTION__
, __FILE__
);
123 foreach ($expected as $profileField => $value) {
124 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $result['values'][$this->_profileID
]), " error message: " . "missing/mismatching value for {$profileField}");
126 $this->assertEquals('abc1', $result['values'][1]['first_name'], " error message: " . "missing/mismatching value for {$profileField}");
127 $this->assertFalse(array_key_exists('email-Primary', $result['values'][1]), 'profile 1 doesn not include email');
128 $this->assertEquals($result['values']['Billing'], array(
129 'billing_first_name' => 'abc1',
130 'billing_middle_name' => 'J.',
131 'billing_last_name' => 'xyz1',
132 'billing_street_address-5' => '5 Saint Helier St',
133 'billing_city-5' => 'Gotham City',
134 'billing_state_province_id-5' => '1021',
135 'billing_country_id-5' => '1228',
136 'billing_postal_code-5' => '90210',
137 'billing-email-5' => 'abc1.xyz1@yahoo.com',
138 'email-5' => 'abc1.xyz1@yahoo.com',
142 public function testProfileGetBillingUseIsBillingLocation() {
143 $individual = $this->_createIndividualContact();
144 $contactId = key($individual);
145 $this->callAPISuccess('address', 'create', array(
147 'street_address' => 'is billing st',
148 'location_type_id' => 2,
149 'contact_id' => $contactId,
152 $expected = current($individual);
155 'profile_id' => array($this->_profileID
, 1, 'Billing'),
156 'contact_id' => $contactId,
159 $result = $this->callAPISuccess('profile', 'get', $params);
160 $this->assertEquals('abc1', $result['values'][1]['first_name']);
161 $this->assertEquals(array(
162 'billing_first_name' => 'abc1',
163 'billing_middle_name' => 'J.',
164 'billing_last_name' => 'xyz1',
165 'billing_street_address-5' => 'is billing st',
166 'billing_city-5' => '',
167 'billing_state_province_id-5' => '',
168 'billing_country_id-5' => '',
169 'billing-email-5' => 'abc1.xyz1@yahoo.com',
170 'email-5' => 'abc1.xyz1@yahoo.com',
171 'billing_postal_code-5' => '',
172 ), $result['values']['Billing']);
175 public function testProfileGetMultipleHasBillingLocation() {
176 $individual = $this->_createIndividualContact();
177 $contactId = key($individual);
178 $this->callAPISuccess('address', 'create', array(
179 'contact_id' => $contactId,
180 'street_address' => '25 Big Street',
181 'city' => 'big city',
182 'location_type_id' => 5,
184 $this->callAPISuccess('email', 'create', array(
185 'contact_id' => $contactId,
186 'email' => 'big@once.com',
187 'location_type_id' => 2,
191 $expected = current($individual);
194 'profile_id' => array($this->_profileID
, 1, 'Billing'),
195 'contact_id' => $contactId,
198 $result = $this->callAPISuccess('profile', 'get', $params, __FUNCTION__
, __FILE__
);
199 $this->assertEquals('abc1', $result['values'][1]['first_name']);
200 $this->assertEquals($result['values']['Billing'], array(
201 'billing_first_name' => 'abc1',
202 'billing_middle_name' => 'J.',
203 'billing_last_name' => 'xyz1',
204 'billing_street_address-5' => '25 Big Street',
205 'billing_city-5' => 'big city',
206 'billing_state_province_id-5' => '',
207 'billing_country_id-5' => '',
208 'billing-email-5' => 'big@once.com',
209 'email-5' => 'big@once.com',
210 'billing_postal_code-5' => '',
215 * Get Billing empty contact - this will return generic defaults
217 public function testProfileGetBillingEmptyContact() {
220 'profile_id' => array('Billing'),
223 $result = $this->callAPISuccess('profile', 'get', $params);
224 $this->assertEquals(array(
225 'billing_first_name' => '',
226 'billing_middle_name' => '',
227 'billing_last_name' => '',
228 'billing_street_address-5' => '',
229 'billing_city-5' => '',
230 'billing_state_province_id-5' => '',
231 'billing_country_id-5' => '1228',
232 'billing_email-5' => '',
234 'billing_postal_code-5' => '',
235 ), $result['values']['Billing']);
239 * Check contact activity profile without activity id.
241 public function testContactActivityGetWithoutActivityId() {
242 list($params, $expected) = $this->_createContactWithActivity();
244 unset($params['activity_id']);
245 $result = $this->callAPIFailure('profile', 'get', $params,
246 'Mandatory key(s) missing from params array: activity_id');
250 * Check contact activity profile wrong activity id.
252 public function testContactActivityGetWrongActivityId() {
253 list($params, $expected) = $this->_createContactWithActivity();
255 $params['activity_id'] = 100001;
256 $result = $this->callAPIFailure('profile', 'get', $params,
257 'Invalid Activity Id (aid).');
261 * Check contact activity profile with wrong activity type.
263 public function testContactActivityGetWrongActivityType() {
264 //flush cache by calling with reset
265 $activityTypes = CRM_Core_PseudoConstant
::activityType(TRUE, TRUE, TRUE, 'name', TRUE);
267 $sourceContactId = $this->householdCreate();
269 $activityparams = array(
270 'source_contact_id' => $sourceContactId,
271 'activity_type_id' => '2',
272 'subject' => 'Test activity',
273 'activity_date_time' => '20110316',
275 'location' => 'Pensulvania',
276 'details' => 'a test activity',
278 'priority_id' => '1',
281 $activity = $this->callAPISuccess('activity', 'create', $activityparams);
283 $activityValues = array_pop($activity['values']);
285 list($params, $expected) = $this->_createContactWithActivity();
287 $params['activity_id'] = $activityValues['id'];
288 $result = $this->callAPIFailure('profile', 'get', $params,
289 'This activity cannot be edited or viewed via this profile.'
294 * Check contact activity profile with success.
296 public function testContactActivityGetSuccess() {
297 list($params, $expected) = $this->_createContactWithActivity();
299 $result = $this->callAPISuccess('profile', 'get', $params);
301 foreach ($expected as $profileField => $value) {
302 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $result['values']), "In line " . __LINE__
. " error message: " . "missing/mismatching value for {$profileField}"
308 * Check getfields works & gives us our fields
310 public function testGetFields() {
311 $this->_createIndividualProfile();
312 $this->_addCustomFieldToProfile($this->_profileID
);
313 $result = $this->callAPIAndDocument('profile', 'getfields', array(
314 'action' => 'submit',
315 'profile_id' => $this->_profileID
,
316 ), __FUNCTION__
, __FILE__
,
317 'demonstrates retrieving profile fields passing in an id');
318 $this->assertArrayKeyExists('first_name', $result['values']);
319 $this->assertEquals('2', $result['values']['first_name']['type']);
320 $this->assertEquals('Email', $result['values']['email-primary']['title']);
321 $this->assertEquals('civicrm_state_province', $result['values']['state_province-1']['pseudoconstant']['table']);
322 $this->assertEquals('defaultValue', $result['values']['custom_1']['default_value']);
323 $this->assertFalse(array_key_exists('participant_status', $result['values']));
327 * Check getfields works & gives us our fields - partipant profile
329 public function testGetFieldsParticipantProfile() {
330 $result = $this->callAPISuccess('profile', 'getfields', array(
331 'action' => 'submit',
332 'profile_id' => 'participant_status',
333 'get_options' => 'all',
336 $this->assertTrue(array_key_exists('participant_status_id', $result['values']));
337 $this->assertEquals('Attended', $result['values']['participant_status_id']['options'][2]);
338 $this->assertEquals(array('participant_status'), $result['values']['participant_status_id']['api.aliases']);
342 * Check getfields works & gives us our fields - membership_batch_entry
343 * (getting to the end with no e-notices is pretty good evidence it's working)
345 public function testGetFieldsMembershipBatchProfile() {
346 $result = $this->callAPISuccess('profile', 'getfields', array(
347 'action' => 'submit',
348 'profile_id' => 'membership_batch_entry',
349 'get_options' => 'all',
352 $this->assertTrue(array_key_exists('total_amount', $result['values']));
353 $this->assertTrue(array_key_exists('financial_type_id', $result['values']));
354 $this->assertEquals(array(
355 'contribution_type_id',
358 ), $result['values']['financial_type_id']['api.aliases']);
359 $this->assertTrue(!array_key_exists('financial_type', $result['values']));
360 $this->assertEquals(12, $result['values']['receive_date']['type']);
364 * Check getfields works & gives us our fields - do them all
365 * (getting to the end with no e-notices is pretty good evidence it's working)
367 public function testGetFieldsAllProfiles() {
368 $result = $this->callAPISuccess('uf_group', 'get', array('return' => 'id'));
369 $profileIDs = array_keys($result['values']);
370 foreach ($profileIDs as $profileID) {
371 $result = $this->callAPISuccess('profile', 'getfields', array(
372 'action' => 'submit',
373 'profile_id' => $profileID,
374 'get_options' => 'all',
379 /////////////// test $this->callAPISuccess3_profile_set //////////////////
382 * Check Without ProfileId.
384 public function testProfileSubmitWithoutProfileId() {
388 $result = $this->callAPIFailure('profile', 'submit', $params,
389 'Mandatory key(s) missing from params array: profile_id'
394 * Check with no invalid profile Id.
396 public function testProfileSubmitInvalidProfileId() {
399 'profile_id' => 1000,
401 $result = $this->callAPIFailure('profile', 'submit', $params);
405 * Check with missing required field in profile.
407 public function testProfileSubmitCheckProfileRequired() {
408 $pofileFieldValues = $this->_createIndividualContact();
409 current($pofileFieldValues);
410 $contactId = key($pofileFieldValues);
411 $updateParams = array(
412 'first_name' => 'abc2',
413 'last_name' => 'xyz2',
414 'phone-1-1' => '022 321 826',
415 'country-1' => '1013',
416 'state_province-1' => '1000',
419 $params = array_merge(array('profile_id' => $this->_profileID
, 'contact_id' => $contactId),
423 $result = $this->callAPIFailure('profile', 'submit', $params,
424 "Missing required parameters for profile id $this->_profileID: email-Primary"
429 * Check with success.
431 public function testProfileSubmit() {
432 $pofileFieldValues = $this->_createIndividualContact();
433 current($pofileFieldValues);
434 $contactId = key($pofileFieldValues);
436 $updateParams = array(
437 'first_name' => 'abc2',
438 'last_name' => 'xyz2',
439 'email-primary' => 'abc2.xyz2@gmail.com',
440 'phone-1-1' => '022 321 826',
441 'country-1' => '1013',
442 'state_province-1' => '1000',
445 $params = array_merge(array(
446 'profile_id' => $this->_profileID
,
447 'contact_id' => $contactId,
450 $result = $this->callAPIAndDocument('profile', 'submit', $params, __FUNCTION__
, __FILE__
);
453 'profile_id' => $this->_profileID
,
454 'contact_id' => $contactId,
456 $profileDetails = $this->callAPISuccess('profile', 'get', $getParams);
458 foreach ($updateParams as $profileField => $value) {
459 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $profileDetails['values']), "missing/mismatching value for {$profileField}"
462 unset($params['email-primary']);
463 $params['email-Primary'] = 'my@mail.com';
464 $this->callAPISuccess('profile', 'submit', $params);
465 $profileDetails = $this->callAPISuccess('profile', 'get', $getParams);
466 $this->assertEquals('my@mail.com', $profileDetails['values']['email-Primary']);
470 * Ensure caches are being cleared so we don't get into a debugging trap because of cached metadata
471 * First we delete & create to increment the version & then check for caching probs
473 public function testProfileSubmitCheckCaching() {
474 $this->callAPISuccess('membership_type', 'delete', array('id' => $this->_membershipTypeID
));
475 $this->_membershipTypeID
= $this->membershipTypeCreate();
477 $membershipTypes = $this->callAPISuccess('membership_type', 'get', array());
478 $profileFields = $this->callAPISuccess('profile', 'getfields', array(
479 'get_options' => 'all',
480 'action' => 'submit',
481 'profile_id' => 'membership_batch_entry',
483 $getoptions = $this->callAPISuccess('membership', 'getoptions', array(
484 'field' => 'membership_type',
485 'context' => 'validate',
487 $this->assertEquals(array_keys($membershipTypes['values']), array_keys($getoptions['values']));
488 $this->assertEquals(array_keys($membershipTypes['values']), array_keys($profileFields['values']['membership_type_id']['options']));
493 * Test that the fields are returned in the right order despite the faffing around that goes on.
495 public function testMembershipGetFieldsOrder() {
496 $result = $this->callAPISuccess('profile', 'getfields', array(
497 'action' => 'submit',
498 'profile_id' => 'membership_batch_entry',
501 foreach ($result['values'] as $fieldName => $field) {
502 if ($fieldName == 'profile_id') {
505 $this->assertEquals($field['weight'], $weight);
511 * Check we can submit membership batch profiles (create mode)
513 public function testProfileSubmitMembershipBatch() {
514 $this->_contactID
= $this->individualCreate();
515 $this->callAPISuccess('profile', 'submit', array(
516 'profile_id' => 'membership_batch_entry',
517 'financial_type_id' => 1,
518 'membership_type' => $this->_membershipTypeID
,
519 'join_date' => 'now',
520 'total_amount' => 10,
521 'contribution_status_id' => 1,
522 'receive_date' => 'now',
523 'contact_id' => $this->_contactID
,
528 * Set is deprecated but we need to ensure it still works.
530 public function testLegacySet() {
531 $pofileFieldValues = $this->_createIndividualContact();
532 current($pofileFieldValues);
533 $contactId = key($pofileFieldValues);
535 $updateParams = array(
536 'first_name' => 'abc2',
537 'last_name' => 'xyz2',
538 'email-Primary' => 'abc2.xyz2@gmail.com',
539 'phone-1-1' => '022 321 826',
540 'country-1' => '1013',
541 'state_province-1' => '1000',
544 $params = array_merge(array(
545 'profile_id' => $this->_profileID
,
546 'contact_id' => $contactId,
549 $result = $this->callAPISuccess('profile', 'set', $params);
550 $this->assertArrayKeyExists('values', $result);
552 'profile_id' => $this->_profileID
,
553 'contact_id' => $contactId,
555 $profileDetails = $this->callAPISuccess('profile', 'get', $getParams);
557 foreach ($updateParams as $profileField => $value) {
558 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $profileDetails['values']), "In line " . __LINE__
. " error message: " . "missing/mismatching value for {$profileField}"
564 * Check contact activity profile without activity id.
566 public function testContactActivitySubmitWithoutActivityId() {
567 list($params, $expected) = $this->_createContactWithActivity();
569 $params = array_merge($params, $expected);
570 unset($params['activity_id']);
571 $result = $this->callAPIFailure('profile', 'submit', $params);
572 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: activity_id');
576 * Check contact activity profile wrong activity id.
578 public function testContactActivitySubmitWrongActivityId() {
579 list($params, $expected) = $this->_createContactWithActivity();
580 $params = array_merge($params, $expected);
581 $params['activity_id'] = 100001;
582 $result = $this->callAPIFailure('profile', 'submit', $params);
583 $this->assertEquals($result['error_message'], 'Invalid Activity Id (aid).');
587 * Check contact activity profile with wrong activity type.
589 public function testContactActivitySubmitWrongActivityType() {
590 //flush cache by calling with reset
591 $activityTypes = CRM_Core_PseudoConstant
::activityType(TRUE, TRUE, TRUE, 'name', TRUE);
593 $sourceContactId = $this->householdCreate();
595 $activityparams = array(
596 'source_contact_id' => $sourceContactId,
597 'activity_type_id' => '2',
598 'subject' => 'Test activity',
599 'activity_date_time' => '20110316',
601 'location' => 'Pensulvania',
602 'details' => 'a test activity',
604 'priority_id' => '1',
607 $activity = $this->callAPISuccess('activity', 'create', $activityparams);
609 $activityValues = array_pop($activity['values']);
611 list($params, $expected) = $this->_createContactWithActivity();
613 $params = array_merge($params, $expected);
614 $params['activity_id'] = $activityValues['id'];
615 $result = $this->callAPIFailure('profile', 'submit', $params,
616 'This activity cannot be edited or viewed via this profile.');
620 * Check contact activity profile with success.
622 public function testContactActivitySubmitSuccess() {
623 list($params, $expected) = $this->_createContactWithActivity();
625 $updateParams = array(
626 'first_name' => 'abc2',
627 'last_name' => 'xyz2',
628 'email-Primary' => 'abc2.xyz2@yahoo.com',
629 'activity_subject' => 'Test Meeting',
630 'activity_details' => 'a test activity details',
631 'activity_duration' => '100',
632 'activity_date_time' => '03/08/2010',
633 'activity_status_id' => '2',
635 $profileParams = array_merge($params, $updateParams);
636 $this->callAPISuccess('profile', 'submit', $profileParams);
637 $result = $this->callAPISuccess('profile', 'get', $params);
639 foreach ($updateParams as $profileField => $value) {
640 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $result['values']), "In line " . __LINE__
. " error message: " . "missing/mismatching value for {$profileField}"
646 * Check profile apply Without ProfileId.
648 public function testProfileApplyWithoutProfileId() {
652 $result = $this->callAPIFailure('profile', 'apply', $params,
653 'Mandatory key(s) missing from params array: profile_id');
657 * Check profile apply with no invalid profile Id.
659 public function testProfileApplyInvalidProfileId() {
662 'profile_id' => 1000,
664 $result = $this->callAPIFailure('profile', 'apply', $params);
668 * Check with success.
670 public function testProfileApply() {
671 $pofileFieldValues = $this->_createIndividualContact();
672 current($pofileFieldValues);
673 $contactId = key($pofileFieldValues);
676 'profile_id' => $this->_profileID
,
677 'contact_id' => $contactId,
678 'first_name' => 'abc2',
679 'last_name' => 'xyz2',
680 'email-Primary' => 'abc2.xyz2@gmail.com',
681 'phone-1-1' => '022 321 826',
682 'country-1' => '1013',
683 'state_province-1' => '1000',
686 $result = $this->callAPIAndDocument('profile', 'apply', $params, __FUNCTION__
, __FILE__
);
688 // Expected field values
689 $expected['contact'] = array(
690 'contact_id' => $contactId,
691 'contact_type' => 'Individual',
692 'first_name' => 'abc2',
693 'last_name' => 'xyz2',
695 $expected['email'] = array(
696 'location_type_id' => 1,
698 'email' => 'abc2.xyz2@gmail.com',
701 $expected['phone'] = array(
702 'location_type_id' => 1,
704 'phone_type_id' => 1,
705 'phone' => '022 321 826',
707 $expected['address'] = array(
708 'location_type_id' => 1,
710 'country_id' => 1013,
711 'state_province_id' => 1000,
714 foreach ($expected['contact'] as $field => $value) {
715 $this->assertEquals($value, CRM_Utils_Array
::value($field, $result['values']), "In line " . __LINE__
. " error message: " . "missing/mismatching value for {$field}"
724 $typeValues = array_pop($result['values'][$fieldType]);
725 foreach ($expected[$fieldType] as $field => $value) {
726 $this->assertEquals($value, CRM_Utils_Array
::value($field, $typeValues), "In line " . __LINE__
. " error message: " . "missing/mismatching value for {$field} ({$fieldType})"
733 * Helper function to create an Individual with address/email/phone info. Import UF Group and UF Fields
734 * @param array $params
738 public function _createIndividualContact($params = array()) {
739 $contactParams = array_merge(array(
740 'first_name' => 'abc1',
741 'last_name' => 'xyz1',
742 'email' => 'abc1.xyz1@yahoo.com',
743 'api.address.create' => array(
744 'location_type_id' => 1,
746 'street_address' => '5 Saint Helier St',
748 'country' => 'UNITED STATES',
749 'state_province' => 'Michigan',
750 'supplemental_address_1' => 'Hallmark Ct',
751 'supplemental_address_2' => 'Jersey Village',
752 'postal_code' => '90210',
753 'city' => 'Gotham City',
756 'api.phone.create' => array(
757 'location_type_id' => '1',
758 'phone' => '021 512 755',
759 'phone_type_id' => '1',
765 $this->_contactID
= $this->individualCreate($contactParams);
766 $this->_createIndividualProfile();
767 // expected result of above created profile with contact Id $contactId
768 $profileData[$this->_contactID
] = array(
769 'first_name' => 'abc1',
770 'last_name' => 'xyz1',
771 'email-primary' => 'abc1.xyz1@yahoo.com',
772 'phone-1-1' => '021 512 755',
773 'country-1' => '1228',
774 'state_province-1' => '1021',
783 public function _createContactWithActivity() {
784 // @TODO: Create profile with custom fields
785 $op = new PHPUnit_Extensions_Database_Operation_Insert();
786 $op->execute($this->_dbconn
,
787 $this->createFlatXMLDataSet(
788 dirname(__FILE__
) . '/dataset/uf_group_contact_activity_26.xml'
791 // hack: xml data set do not accept \ 1 (CRM_Core_DAO::VALUE_SEPARATOR)
792 CRM_Core_DAO
::setFieldValue('CRM_Core_DAO_UFGroup', '26', 'group_type', 'Individual,Contact,Activity' . CRM_Core_DAO
::VALUE_SEPARATOR
. 'ActivityType:1');
794 $sourceContactId = $this->individualCreate();
795 $contactParams = array(
796 'first_name' => 'abc1',
797 'last_name' => 'xyz1',
798 'contact_type' => 'Individual',
799 'email' => 'abc1.xyz1@yahoo.com',
800 'api.address.create' => array(
801 'location_type_id' => 1,
803 'name' => 'Saint Helier St',
805 'country' => 'UNITED STATES',
806 'state_province' => 'Michigan',
807 'supplemental_address_1' => 'Hallmark Ct',
808 'supplemental_address_2' => 'Jersey Village',
812 $contact = $this->callAPISuccess('contact', 'create', $contactParams);
814 $keys = array_keys($contact['values']);
815 $contactId = array_pop($keys);
817 $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'])
820 $activityParams = array(
821 'source_contact_id' => $sourceContactId,
822 'assignee_contact_id' => $contactId,
823 'activity_type_id' => '1',
824 'subject' => 'Make-it-Happen Meeting',
825 'activity_date_time' => '20110316',
827 'location' => 'Pensulvania',
828 'details' => 'a test activity',
830 'priority_id' => '1',
832 $activity = $this->callAPISuccess('activity', 'create', $activityParams);
834 $activityValues = array_pop($activity['values']);
836 // valid parameters for above profile
837 $profileParams = array(
839 'contact_id' => $contactId,
840 'activity_id' => $activityValues['id'],
843 // expected result of above created profile
845 'first_name' => 'abc1',
846 'last_name' => 'xyz1',
847 'email-Primary' => 'abc1.xyz1@yahoo.com',
848 'activity_subject' => 'Make-it-Happen Meeting',
849 'activity_details' => 'a test activity',
850 'activity_duration' => '120',
851 'activity_date_time_time' => '12:00AM',
852 'activity_date_time' => '03/16/2011',
853 'activity_status_id' => '1',
856 return array($profileParams, $expected);
862 public function _createIndividualProfile() {
864 // creating these via the api as we want to utilise & test the flushing of caches when fields created
867 $ufGroupParams = array(
868 'group_type' => 'Individual,Contact', // really we should remove this & test the ufField create sets it
869 'name' => 'test_individual_contact_profile',
870 'title' => 'Flat Coffee',
871 'api.uf_field.create' => array(
873 'field_name' => 'first_name',
875 'visibility' => 'Public Pages and Listings',
876 'field_type' => 'Individual',
877 'label' => 'First Name',
880 'field_name' => 'last_name',
882 'visibility' => 'Public Pages and Listings',
883 'field_type' => 'Individual',
884 'label' => 'Last Name',
887 'field_name' => 'email',
889 'visibility' => 'Public Pages and Listings',
890 'field_type' => 'Contact',
894 'field_name' => 'phone',
896 'visibility' => 'Public Pages and Listings',
897 'field_type' => 'Contact',
898 'location_type_id' => 1,
899 'phone_type_id' => 1,
903 'field_name' => 'country',
905 'visibility' => 'Public Pages and Listings',
906 'field_type' => 'Contact',
907 'location_type_id' => 1,
908 'label' => 'Country',
911 'field_name' => 'state_province',
913 'visibility' => 'Public Pages and Listings',
914 'field_type' => 'Contact',
915 'location_type_id' => 1,
916 'label' => 'State Province',
919 'field_name' => 'postal_code',
921 'field_type' => 'Contact',
922 'location_type_id' => 1,
923 'label' => 'State Province',
927 $profile = $this->callAPISuccess('uf_group', 'create', $ufGroupParams);
928 $this->_profileID
= $profile['id'];
932 * @param int $profileID
934 public function _addCustomFieldToProfile($profileID) {
935 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, '');
936 $this->uFFieldCreate(array(
937 'uf_group_id' => $profileID,
938 'field_name' => 'custom_' . $ids['custom_field_id'],
939 'contact_type' => 'Contact',