3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 $config->countryLimit
[1] = 1013;
49 $config->stateLimit
[1] = 1013;
50 $this->createLoggedInUser();
51 $this->_membershipTypeID
= $this->membershipTypeCreate();
54 public function tearDown() {
56 $this->quickCleanup(array(
61 'civicrm_contribution',
63 $this->callAPISuccess('membership_type', 'delete', array('id' => $this->_membershipTypeID
));
64 // ok can't be bothered wring an api to do this & truncating is crazy
65 CRM_Core_DAO
::executeQuery(" DELETE FROM civicrm_uf_group WHERE id IN ($this->_profileID, 26)");
68 ////////////// test $this->callAPISuccess3_profile_get //////////////////
71 * Check Without ProfileId
73 public function testProfileGetWithoutProfileId() {
77 $result = $this->callAPIFailure('profile', 'get', $params,
78 'Mandatory key(s) missing from params array: profile_id'
83 * Check with no invalid profile Id
85 public function testProfileGetInvalidProfileId() {
90 $result = $this->callAPIFailure('profile', 'get', $params);
96 public function testProfileGet() {
97 $pofileFieldValues = $this->_createIndividualContact();
98 $expected = current($pofileFieldValues);
99 $contactId = key($pofileFieldValues);
101 'profile_id' => $this->_profileID
,
102 'contact_id' => $contactId,
104 $result = $this->callAPISuccess('profile', 'get', $params);
105 foreach ($expected as $profileField => $value) {
106 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $result['values']));
110 public function testProfileGetMultiple() {
111 $pofileFieldValues = $this->_createIndividualContact();
112 $expected = current($pofileFieldValues);
113 $contactId = key($pofileFieldValues);
115 'profile_id' => array($this->_profileID
, 1, 'Billing'),
116 'contact_id' => $contactId,
119 $result = $this->callAPIAndDocument('profile', 'get', $params, __FUNCTION__
, __FILE__
);
120 foreach ($expected as $profileField => $value) {
121 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $result['values'][$this->_profileID
]), " error message: " . "missing/mismatching value for {$profileField}");
123 $this->assertEquals('abc1', $result['values'][1]['first_name'], " error message: " . "missing/mismatching value for {$profileField}");
124 $this->assertFalse(array_key_exists('email-Primary', $result['values'][1]), 'profile 1 doesn not include email');
125 $this->assertEquals($result['values']['Billing'], array(
126 'billing_first_name' => 'abc1',
127 'billing_middle_name' => 'J.',
128 'billing_last_name' => 'xyz1',
129 'billing_street_address-5' => '5 Saint Helier St',
130 'billing_city-5' => 'Gotham City',
131 'billing_state_province_id-5' => '1021',
132 'billing_country_id-5' => '1228',
133 'billing_postal_code-5' => '90210',
134 'billing-email-5' => 'abc1.xyz1@yahoo.com',
135 'email-5' => 'abc1.xyz1@yahoo.com',
139 public function testProfileGetBillingUseIsBillingLocation() {
140 $individual = $this->_createIndividualContact();
141 $contactId = key($individual);
142 $this->callAPISuccess('address', 'create', array(
144 'street_address' => 'is billing st',
145 'location_type_id' => 2,
146 'contact_id' => $contactId,
149 $expected = current($individual);
152 'profile_id' => array($this->_profileID
, 1, 'Billing'),
153 'contact_id' => $contactId,
156 $result = $this->callAPISuccess('profile', 'get', $params);
157 $this->assertEquals('abc1', $result['values'][1]['first_name']);
158 $this->assertEquals(array(
159 'billing_first_name' => 'abc1',
160 'billing_middle_name' => 'J.',
161 'billing_last_name' => 'xyz1',
162 'billing_street_address-5' => 'is billing st',
163 'billing_city-5' => '',
164 'billing_state_province_id-5' => '',
165 'billing_country_id-5' => '',
166 'billing-email-5' => 'abc1.xyz1@yahoo.com',
167 'email-5' => 'abc1.xyz1@yahoo.com',
168 'billing_postal_code-5' => '',
169 ), $result['values']['Billing']);
172 public function testProfileGetMultipleHasBillingLocation() {
173 $individual = $this->_createIndividualContact();
174 $contactId = key($individual);
175 $this->callAPISuccess('address', 'create', array(
176 'contact_id' => $contactId,
177 'street_address' => '25 Big Street',
178 'city' => 'big city',
179 'location_type_id' => 5,
181 $this->callAPISuccess('email', 'create', array(
182 'contact_id' => $contactId,
183 'email' => 'big@once.com',
184 'location_type_id' => 2,
188 $expected = current($individual);
191 'profile_id' => array($this->_profileID
, 1, 'Billing'),
192 'contact_id' => $contactId,
195 $result = $this->callAPISuccess('profile', 'get', $params, __FUNCTION__
, __FILE__
);
196 $this->assertEquals('abc1', $result['values'][1]['first_name']);
197 $this->assertEquals($result['values']['Billing'], array(
198 'billing_first_name' => 'abc1',
199 'billing_middle_name' => 'J.',
200 'billing_last_name' => 'xyz1',
201 'billing_street_address-5' => '25 Big Street',
202 'billing_city-5' => 'big city',
203 'billing_state_province_id-5' => '',
204 'billing_country_id-5' => '',
205 'billing-email-5' => 'big@once.com',
206 'email-5' => 'big@once.com',
207 'billing_postal_code-5' => '',
212 * Get Billing empty contact - this will return generic defaults
214 public function testProfileGetBillingEmptyContact() {
217 'profile_id' => array('Billing'),
220 $result = $this->callAPISuccess('profile', 'get', $params);
221 $this->assertEquals(array(
222 'billing_first_name' => '',
223 'billing_middle_name' => '',
224 'billing_last_name' => '',
225 'billing_street_address-5' => '',
226 'billing_city-5' => '',
227 'billing_state_province_id-5' => '',
228 'billing_country_id-5' => '1228',
229 'billing_email-5' => '',
231 'billing_postal_code-5' => '',
232 ), $result['values']['Billing']);
236 * Check contact activity profile without activity id
238 public function testContactActivityGetWithoutActivityId() {
239 list($params, $expected) = $this->_createContactWithActivity();
241 unset($params['activity_id']);
242 $result = $this->callAPIFailure('profile', 'get', $params,
243 'Mandatory key(s) missing from params array: activity_id');
247 * Check contact activity profile wrong activity id
249 public function testContactActivityGetWrongActivityId() {
250 list($params, $expected) = $this->_createContactWithActivity();
252 $params['activity_id'] = 100001;
253 $result = $this->callAPIFailure('profile', 'get', $params,
254 'Invalid Activity Id (aid).');
258 * Check contact activity profile with wrong activity type
260 public function testContactActivityGetWrongActivityType() {
261 //flush cache by calling with reset
262 $activityTypes = CRM_Core_PseudoConstant
::activityType(TRUE, TRUE, TRUE, 'name', TRUE);
264 $sourceContactId = $this->householdCreate();
266 $activityparams = array(
267 'source_contact_id' => $sourceContactId,
268 'activity_type_id' => '2',
269 'subject' => 'Test activity',
270 'activity_date_time' => '20110316',
272 'location' => 'Pensulvania',
273 'details' => 'a test activity',
275 'priority_id' => '1',
278 $activity = $this->callAPISuccess('activity', 'create', $activityparams);
280 $activityValues = array_pop($activity['values']);
282 list($params, $expected) = $this->_createContactWithActivity();
284 $params['activity_id'] = $activityValues['id'];
285 $result = $this->callAPIFailure('profile', 'get', $params,
286 'This activity cannot be edited or viewed via this profile.'
291 * Check contact activity profile with success
293 public function testContactActivityGetSuccess() {
294 list($params, $expected) = $this->_createContactWithActivity();
296 $result = $this->callAPISuccess('profile', 'get', $params);
298 foreach ($expected as $profileField => $value) {
299 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $result['values']), "In line " . __LINE__
. " error message: " . "missing/mismatching value for {$profileField}"
305 * Check getfields works & gives us our fields
307 public function testGetFields() {
308 $this->_createIndividualProfile();
309 $this->_addCustomFieldToProfile($this->_profileID
);
310 $result = $this->callAPIAndDocument('profile', 'getfields', array(
311 'action' => 'submit',
312 'profile_id' => $this->_profileID
,
313 ), __FUNCTION__
, __FILE__
,
314 'demonstrates retrieving profile fields passing in an id');
315 $this->assertArrayKeyExists('first_name', $result['values']);
316 $this->assertEquals('2', $result['values']['first_name']['type']);
317 $this->assertEquals('Email', $result['values']['email-primary']['title']);
318 $this->assertEquals('civicrm_state_province', $result['values']['state_province-1']['pseudoconstant']['table']);
319 $this->assertEquals('defaultValue', $result['values']['custom_1']['default_value']);
320 $this->assertFalse(array_key_exists('participant_status', $result['values']));
324 * Check getfields works & gives us our fields - partipant profile
326 public function testGetFieldsParticipantProfile() {
327 $result = $this->callAPISuccess('profile', 'getfields', array(
328 'action' => 'submit',
329 'profile_id' => 'participant_status',
330 'get_options' => 'all',
333 $this->assertTrue(array_key_exists('participant_status_id', $result['values']));
334 $this->assertEquals('Attended', $result['values']['participant_status_id']['options'][2]);
335 $this->assertEquals(array('participant_status'), $result['values']['participant_status_id']['api.aliases']);
339 * Check getfields works & gives us our fields - membership_batch_entry
340 * (getting to the end with no e-notices is pretty good evidence it's working)
342 public function testGetFieldsMembershipBatchProfile() {
343 $result = $this->callAPISuccess('profile', 'getfields', array(
344 'action' => 'submit',
345 'profile_id' => 'membership_batch_entry',
346 'get_options' => 'all',
349 $this->assertTrue(array_key_exists('total_amount', $result['values']));
350 $this->assertTrue(array_key_exists('financial_type_id', $result['values']));
351 $this->assertEquals(array(
352 'contribution_type_id',
355 ), $result['values']['financial_type_id']['api.aliases']);
356 $this->assertTrue(!array_key_exists('financial_type', $result['values']));
357 $this->assertEquals(12, $result['values']['receive_date']['type']);
361 * Check getfields works & gives us our fields - do them all
362 * (getting to the end with no e-notices is pretty good evidence it's working)
364 public function testGetFieldsAllProfiles() {
365 $result = $this->callAPISuccess('uf_group', 'get', array('return' => 'id'));
366 $profileIDs = array_keys($result['values']);
367 foreach ($profileIDs as $profileID) {
368 $result = $this->callAPISuccess('profile', 'getfields', array(
369 'action' => 'submit',
370 'profile_id' => $profileID,
371 'get_options' => 'all',
376 /////////////// test $this->callAPISuccess3_profile_set //////////////////
379 * Check Without ProfileId
381 public function testProfileSubmitWithoutProfileId() {
385 $result = $this->callAPIFailure('profile', 'submit', $params,
386 'Mandatory key(s) missing from params array: profile_id'
391 * Check with no invalid profile Id
393 public function testProfileSubmitInvalidProfileId() {
396 'profile_id' => 1000,
398 $result = $this->callAPIFailure('profile', 'submit', $params);
402 * Check with missing required field in profile
404 public function testProfileSubmitCheckProfileRequired() {
405 $pofileFieldValues = $this->_createIndividualContact();
406 current($pofileFieldValues);
407 $contactId = key($pofileFieldValues);
408 $updateParams = array(
409 'first_name' => 'abc2',
410 'last_name' => 'xyz2',
411 'phone-1-1' => '022 321 826',
412 'country-1' => '1013',
413 'state_province-1' => '1000',
416 $params = array_merge(array('profile_id' => $this->_profileID
, 'contact_id' => $contactId),
420 $result = $this->callAPIFailure('profile', 'submit', $params,
421 "Missing required parameters for profile id $this->_profileID: email-Primary"
428 public function testProfileSubmit() {
429 $pofileFieldValues = $this->_createIndividualContact();
430 current($pofileFieldValues);
431 $contactId = key($pofileFieldValues);
433 $updateParams = array(
434 'first_name' => 'abc2',
435 'last_name' => 'xyz2',
436 'email-primary' => 'abc2.xyz2@gmail.com',
437 'phone-1-1' => '022 321 826',
438 'country-1' => '1013',
439 'state_province-1' => '1000',
442 $params = array_merge(array(
443 'profile_id' => $this->_profileID
,
444 'contact_id' => $contactId,
447 $result = $this->callAPIAndDocument('profile', 'submit', $params, __FUNCTION__
, __FILE__
);
450 'profile_id' => $this->_profileID
,
451 'contact_id' => $contactId,
453 $profileDetails = $this->callAPISuccess('profile', 'get', $getParams);
455 foreach ($updateParams as $profileField => $value) {
456 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $profileDetails['values']), "missing/mismatching value for {$profileField}"
459 unset($params['email-primary']);
460 $params['email-Primary'] = 'my@mail.com';
461 $this->callAPISuccess('profile', 'submit', $params);
462 $profileDetails = $this->callAPISuccess('profile', 'get', $getParams);
463 $this->assertEquals('my@mail.com', $profileDetails['values']['email-Primary']);
467 * Ensure caches are being cleared so we don't get into a debugging trap because of cached metadata
468 * First we delete & create to increment the version & then check for caching probs
470 public function testProfileSubmitCheckCaching() {
471 $this->callAPISuccess('membership_type', 'delete', array('id' => $this->_membershipTypeID
));
472 $this->_membershipTypeID
= $this->membershipTypeCreate();
474 $membershipTypes = $this->callAPISuccess('membership_type', 'get', array());
475 $profileFields = $this->callAPISuccess('profile', 'getfields', array(
476 'get_options' => 'all',
477 'action' => 'submit',
478 'profile_id' => 'membership_batch_entry',
480 $getoptions = $this->callAPISuccess('membership', 'getoptions', array(
481 'field' => 'membership_type',
482 'context' => 'validate',
484 $this->assertEquals(array_keys($membershipTypes['values']), array_keys($getoptions['values']));
485 $this->assertEquals(array_keys($membershipTypes['values']), array_keys($profileFields['values']['membership_type_id']['options']));
490 * Test that the fields are returned in the right order despite the faffing around that goes on
492 public function testMembershipGetFieldsOrder() {
493 $result = $this->callAPISuccess('profile', 'getfields', array(
494 'action' => 'submit',
495 'profile_id' => 'membership_batch_entry',
498 foreach ($result['values'] as $fieldName => $field) {
499 if ($fieldName == 'profile_id') {
502 $this->assertEquals($field['weight'], $weight);
508 * Check we can submit membership batch profiles (create mode)
510 public function testProfileSubmitMembershipBatch() {
511 $this->_contactID
= $this->individualCreate();
512 $this->callAPISuccess('profile', 'submit', array(
513 'profile_id' => 'membership_batch_entry',
514 'financial_type_id' => 1,
515 'membership_type' => $this->_membershipTypeID
,
516 'join_date' => 'now',
517 'total_amount' => 10,
518 'contribution_status_id' => 1,
519 'receive_date' => 'now',
520 'contact_id' => $this->_contactID
,
525 * Set is deprecated but we need to ensure it still works
527 public function testLegacySet() {
528 $pofileFieldValues = $this->_createIndividualContact();
529 current($pofileFieldValues);
530 $contactId = key($pofileFieldValues);
532 $updateParams = array(
533 'first_name' => 'abc2',
534 'last_name' => 'xyz2',
535 'email-Primary' => 'abc2.xyz2@gmail.com',
536 'phone-1-1' => '022 321 826',
537 'country-1' => '1013',
538 'state_province-1' => '1000',
541 $params = array_merge(array(
542 'profile_id' => $this->_profileID
,
543 'contact_id' => $contactId,
546 $result = $this->callAPISuccess('profile', 'set', $params);
547 $this->assertArrayKeyExists('values', $result);
549 'profile_id' => $this->_profileID
,
550 'contact_id' => $contactId,
552 $profileDetails = $this->callAPISuccess('profile', 'get', $getParams);
554 foreach ($updateParams as $profileField => $value) {
555 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $profileDetails['values']), "In line " . __LINE__
. " error message: " . "missing/mismatching value for {$profileField}"
561 * Check contact activity profile without activity id
563 public function testContactActivitySubmitWithoutActivityId() {
564 list($params, $expected) = $this->_createContactWithActivity();
566 $params = array_merge($params, $expected);
567 unset($params['activity_id']);
568 $result = $this->callAPIFailure('profile', 'submit', $params);
569 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: activity_id');
573 * Check contact activity profile wrong activity id
575 public function testContactActivitySubmitWrongActivityId() {
576 list($params, $expected) = $this->_createContactWithActivity();
577 $params = array_merge($params, $expected);
578 $params['activity_id'] = 100001;
579 $result = $this->callAPIFailure('profile', 'submit', $params);
580 $this->assertEquals($result['error_message'], 'Invalid Activity Id (aid).');
584 * Check contact activity profile with wrong activity type
586 public function testContactActivitySubmitWrongActivityType() {
587 //flush cache by calling with reset
588 $activityTypes = CRM_Core_PseudoConstant
::activityType(TRUE, TRUE, TRUE, 'name', TRUE);
590 $sourceContactId = $this->householdCreate();
592 $activityparams = array(
593 'source_contact_id' => $sourceContactId,
594 'activity_type_id' => '2',
595 'subject' => 'Test activity',
596 'activity_date_time' => '20110316',
598 'location' => 'Pensulvania',
599 'details' => 'a test activity',
601 'priority_id' => '1',
604 $activity = $this->callAPISuccess('activity', 'create', $activityparams);
606 $activityValues = array_pop($activity['values']);
608 list($params, $expected) = $this->_createContactWithActivity();
610 $params = array_merge($params, $expected);
611 $params['activity_id'] = $activityValues['id'];
612 $result = $this->callAPIFailure('profile', 'submit', $params,
613 'This activity cannot be edited or viewed via this profile.');
617 * Check contact activity profile with success
619 public function testContactActivitySubmitSuccess() {
620 list($params, $expected) = $this->_createContactWithActivity();
622 $updateParams = array(
623 'first_name' => 'abc2',
624 'last_name' => 'xyz2',
625 'email-Primary' => 'abc2.xyz2@yahoo.com',
626 'activity_subject' => 'Test Meeting',
627 'activity_details' => 'a test activity details',
628 'activity_duration' => '100',
629 'activity_date_time' => '03/08/2010',
630 'activity_status_id' => '2',
632 $profileParams = array_merge($params, $updateParams);
633 $this->callAPISuccess('profile', 'submit', $profileParams);
634 $result = $this->callAPISuccess('profile', 'get', $params);
636 foreach ($updateParams as $profileField => $value) {
637 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $result['values']), "In line " . __LINE__
. " error message: " . "missing/mismatching value for {$profileField}"
643 * Check profile apply Without ProfileId
645 public function testProfileApplyWithoutProfileId() {
649 $result = $this->callAPIFailure('profile', 'apply', $params,
650 'Mandatory key(s) missing from params array: profile_id');
654 * Check profile apply with no invalid profile Id
656 public function testProfileApplyInvalidProfileId() {
659 'profile_id' => 1000,
661 $result = $this->callAPIFailure('profile', 'apply', $params);
667 public function testProfileApply() {
668 $pofileFieldValues = $this->_createIndividualContact();
669 current($pofileFieldValues);
670 $contactId = key($pofileFieldValues);
673 'profile_id' => $this->_profileID
,
674 'contact_id' => $contactId,
675 'first_name' => 'abc2',
676 'last_name' => 'xyz2',
677 'email-Primary' => 'abc2.xyz2@gmail.com',
678 'phone-1-1' => '022 321 826',
679 'country-1' => '1013',
680 'state_province-1' => '1000',
683 $result = $this->callAPIAndDocument('profile', 'apply', $params, __FUNCTION__
, __FILE__
);
685 // Expected field values
686 $expected['contact'] = array(
687 'contact_id' => $contactId,
688 'contact_type' => 'Individual',
689 'first_name' => 'abc2',
690 'last_name' => 'xyz2',
692 $expected['email'] = array(
693 'location_type_id' => 1,
695 'email' => 'abc2.xyz2@gmail.com',
698 $expected['phone'] = array(
699 'location_type_id' => 1,
701 'phone_type_id' => 1,
702 'phone' => '022 321 826',
704 $expected['address'] = array(
705 'location_type_id' => 1,
707 'country_id' => 1013,
708 'state_province_id' => 1000,
711 foreach ($expected['contact'] as $field => $value) {
712 $this->assertEquals($value, CRM_Utils_Array
::value($field, $result['values']), "In line " . __LINE__
. " error message: " . "missing/mismatching value for {$field}"
721 $typeValues = array_pop($result['values'][$fieldType]);
722 foreach ($expected[$fieldType] as $field => $value) {
723 $this->assertEquals($value, CRM_Utils_Array
::value($field, $typeValues), "In line " . __LINE__
. " error message: " . "missing/mismatching value for {$field} ({$fieldType})"
730 * Helper function to create an Individual with address/email/phone info. Import UF Group and UF Fields
731 * @param array $params
735 public function _createIndividualContact($params = array()) {
736 $contactParams = array_merge(array(
737 'first_name' => 'abc1',
738 'last_name' => 'xyz1',
739 'email' => 'abc1.xyz1@yahoo.com',
740 'api.address.create' => array(
741 'location_type_id' => 1,
743 'street_address' => '5 Saint Helier St',
745 'country' => 'United States',
746 'state_province' => 'Michigan',
747 'supplemental_address_1' => 'Hallmark Ct',
748 'supplemental_address_2' => 'Jersey Village',
749 'postal_code' => '90210',
750 'city' => 'Gotham City',
753 'api.phone.create' => array(
754 'location_type_id' => '1',
755 'phone' => '021 512 755',
756 'phone_type_id' => '1',
762 $this->_contactID
= $this->individualCreate($contactParams);
763 $this->_createIndividualProfile();
764 // expected result of above created profile with contact Id $contactId
765 $profileData[$this->_contactID
] = array(
766 'first_name' => 'abc1',
767 'last_name' => 'xyz1',
768 'email-primary' => 'abc1.xyz1@yahoo.com',
769 'phone-1-1' => '021 512 755',
770 'country-1' => '1228',
771 'state_province-1' => '1021',
780 public function _createContactWithActivity() {
781 // @TODO: Create profile with custom fields
782 $op = new PHPUnit_Extensions_Database_Operation_Insert();
783 $op->execute($this->_dbconn
,
784 $this->createFlatXMLDataSet(
785 dirname(__FILE__
) . '/dataset/uf_group_contact_activity_26.xml'
788 // hack: xml data set do not accept \ 1 (CRM_Core_DAO::VALUE_SEPARATOR)
789 CRM_Core_DAO
::setFieldValue('CRM_Core_DAO_UFGroup', '26', 'group_type', 'Individual,Contact,Activity' . CRM_Core_DAO
::VALUE_SEPARATOR
. 'ActivityType:1');
791 $sourceContactId = $this->individualCreate();
792 $contactParams = array(
793 'first_name' => 'abc1',
794 'last_name' => 'xyz1',
795 'contact_type' => 'Individual',
796 'email' => 'abc1.xyz1@yahoo.com',
797 'api.address.create' => array(
798 'location_type_id' => 1,
800 'name' => 'Saint Helier St',
802 'country' => 'United States',
803 'state_province' => 'Michigan',
804 'supplemental_address_1' => 'Hallmark Ct',
805 'supplemental_address_2' => 'Jersey Village',
809 $contact = $this->callAPISuccess('contact', 'create', $contactParams);
811 $keys = array_keys($contact['values']);
812 $contactId = array_pop($keys);
814 $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'])
817 $activityParams = array(
818 'source_contact_id' => $sourceContactId,
819 'assignee_contact_id' => $contactId,
820 'activity_type_id' => '1',
821 'subject' => 'Make-it-Happen Meeting',
822 'activity_date_time' => '20110316',
824 'location' => 'Pensulvania',
825 'details' => 'a test activity',
827 'priority_id' => '1',
829 $activity = $this->callAPISuccess('activity', 'create', $activityParams);
831 $activityValues = array_pop($activity['values']);
833 // valid parameters for above profile
834 $profileParams = array(
836 'contact_id' => $contactId,
837 'activity_id' => $activityValues['id'],
840 // expected result of above created profile
842 'first_name' => 'abc1',
843 'last_name' => 'xyz1',
844 'email-Primary' => 'abc1.xyz1@yahoo.com',
845 'activity_subject' => 'Make-it-Happen Meeting',
846 'activity_details' => 'a test activity',
847 'activity_duration' => '120',
848 'activity_date_time_time' => '12:00AM',
849 'activity_date_time' => '03/16/2011',
850 'activity_status_id' => '1',
853 return array($profileParams, $expected);
859 public function _createIndividualProfile() {
861 // creating these via the api as we want to utilise & test the flushing of caches when fields created
864 $ufGroupParams = array(
865 'group_type' => 'Individual,Contact', // really we should remove this & test the ufField create sets it
866 'name' => 'test_individual_contact_profile',
867 'title' => 'Flat Coffee',
868 'api.uf_field.create' => array(
870 'field_name' => 'first_name',
872 'visibility' => 'Public Pages and Listings',
873 'field_type' => 'Individual',
874 'label' => 'First Name',
877 'field_name' => 'last_name',
879 'visibility' => 'Public Pages and Listings',
880 'field_type' => 'Individual',
881 'label' => 'Last Name',
884 'field_name' => 'email',
886 'visibility' => 'Public Pages and Listings',
887 'field_type' => 'Contact',
891 'field_name' => 'phone',
893 'visibility' => 'Public Pages and Listings',
894 'field_type' => 'Contact',
895 'location_type_id' => 1,
896 'phone_type_id' => 1,
900 'field_name' => 'country',
902 'visibility' => 'Public Pages and Listings',
903 'field_type' => 'Contact',
904 'location_type_id' => 1,
905 'label' => 'Country',
908 'field_name' => 'state_province',
910 'visibility' => 'Public Pages and Listings',
911 'field_type' => 'Contact',
912 'location_type_id' => 1,
913 'label' => 'State Province',
916 'field_name' => 'postal_code',
918 'field_type' => 'Contact',
919 'location_type_id' => 1,
920 'label' => 'State Province',
924 $profile = $this->callAPISuccess('uf_group', 'create', $ufGroupParams);
925 $this->_profileID
= $profile['id'];
929 * @param int $profileID
931 public function _addCustomFieldToProfile($profileID) {
932 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, '');
933 $this->uFFieldCreate(array(
934 'uf_group_id' => $profileID,
935 'field_name' => 'custom_' . $ids['custom_field_id'],
936 'contact_type' => 'Contact',