3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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 $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',
64 $this->callAPISuccess('membership_type', 'delete', array('id' => $this->_membershipTypeID
));
65 // ok can't be bothered wring an api to do this & truncating is crazy
66 CRM_Core_DAO
::executeQuery(" DELETE FROM civicrm_uf_group WHERE id IN ($this->_profileID, 26)");
69 ////////////// test $this->callAPISuccess3_profile_get //////////////////
72 * Check Without ProfileId.
74 public function testProfileGetWithoutProfileId() {
78 $result = $this->callAPIFailure('profile', 'get', $params,
79 'Mandatory key(s) missing from params array: profile_id'
84 * Check with no invalid profile Id.
86 public function testProfileGetInvalidProfileId() {
91 $result = $this->callAPIFailure('profile', 'get', $params);
97 public function testProfileGet() {
98 $pofileFieldValues = $this->_createIndividualContact();
99 $expected = current($pofileFieldValues);
100 $contactId = key($pofileFieldValues);
102 'profile_id' => $this->_profileID
,
103 'contact_id' => $contactId,
105 $result = $this->callAPISuccess('profile', 'get', $params);
106 foreach ($expected as $profileField => $value) {
107 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $result['values']));
111 public function testProfileGetMultiple() {
112 $pofileFieldValues = $this->_createIndividualContact();
113 $expected = current($pofileFieldValues);
114 $contactId = key($pofileFieldValues);
116 'profile_id' => array($this->_profileID
, 1, 'Billing'),
117 'contact_id' => $contactId,
120 $result = $this->callAPIAndDocument('profile', 'get', $params, __FUNCTION__
, __FILE__
);
121 foreach ($expected as $profileField => $value) {
122 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $result['values'][$this->_profileID
]), " error message: " . "missing/mismatching value for {$profileField}");
124 $this->assertEquals('abc1', $result['values'][1]['first_name'], " error message: " . "missing/mismatching value for {$profileField}");
125 $this->assertFalse(array_key_exists('email-Primary', $result['values'][1]), 'profile 1 doesn not include email');
126 $this->assertEquals($result['values']['Billing'], array(
127 'billing_first_name' => 'abc1',
128 'billing_middle_name' => 'J.',
129 'billing_last_name' => 'xyz1',
130 'billing_street_address-5' => '5 Saint Helier St',
131 'billing_city-5' => 'Gotham City',
132 'billing_state_province_id-5' => '1021',
133 'billing_country_id-5' => '1228',
134 'billing_postal_code-5' => '90210',
135 'billing-email-5' => 'abc1.xyz1@yahoo.com',
136 'email-5' => 'abc1.xyz1@yahoo.com',
140 public function testProfileGetBillingUseIsBillingLocation() {
141 $individual = $this->_createIndividualContact();
142 $contactId = key($individual);
143 $this->callAPISuccess('address', 'create', array(
145 'street_address' => 'is billing st',
146 'location_type_id' => 2,
147 'contact_id' => $contactId,
150 $expected = current($individual);
153 'profile_id' => array($this->_profileID
, 1, 'Billing'),
154 'contact_id' => $contactId,
157 $result = $this->callAPISuccess('profile', 'get', $params);
158 $this->assertEquals('abc1', $result['values'][1]['first_name']);
159 $this->assertEquals(array(
160 'billing_first_name' => 'abc1',
161 'billing_middle_name' => 'J.',
162 'billing_last_name' => 'xyz1',
163 'billing_street_address-5' => 'is billing st',
164 'billing_city-5' => '',
165 'billing_state_province_id-5' => '',
166 'billing_country_id-5' => '',
167 'billing-email-5' => 'abc1.xyz1@yahoo.com',
168 'email-5' => 'abc1.xyz1@yahoo.com',
169 'billing_postal_code-5' => '',
170 ), $result['values']['Billing']);
173 public function testProfileGetMultipleHasBillingLocation() {
174 $individual = $this->_createIndividualContact();
175 $contactId = key($individual);
176 $this->callAPISuccess('address', 'create', array(
177 'contact_id' => $contactId,
178 'street_address' => '25 Big Street',
179 'city' => 'big city',
180 'location_type_id' => 5,
182 $this->callAPISuccess('email', 'create', array(
183 'contact_id' => $contactId,
184 'email' => 'big@once.com',
185 'location_type_id' => 2,
189 $expected = current($individual);
192 'profile_id' => array($this->_profileID
, 1, 'Billing'),
193 'contact_id' => $contactId,
196 $result = $this->callAPISuccess('profile', 'get', $params, __FUNCTION__
, __FILE__
);
197 $this->assertEquals('abc1', $result['values'][1]['first_name']);
198 $this->assertEquals($result['values']['Billing'], array(
199 'billing_first_name' => 'abc1',
200 'billing_middle_name' => 'J.',
201 'billing_last_name' => 'xyz1',
202 'billing_street_address-5' => '25 Big Street',
203 'billing_city-5' => 'big city',
204 'billing_state_province_id-5' => '',
205 'billing_country_id-5' => '',
206 'billing-email-5' => 'big@once.com',
207 'email-5' => 'big@once.com',
208 'billing_postal_code-5' => '',
213 * Get Billing empty contact - this will return generic defaults
215 public function testProfileGetBillingEmptyContact() {
218 'profile_id' => array('Billing'),
221 $result = $this->callAPISuccess('profile', 'get', $params);
222 $this->assertEquals(array(
223 'billing_first_name' => '',
224 'billing_middle_name' => '',
225 'billing_last_name' => '',
226 'billing_street_address-5' => '',
227 'billing_city-5' => '',
228 'billing_state_province_id-5' => '',
229 'billing_country_id-5' => '1228',
230 'billing_email-5' => '',
232 'billing_postal_code-5' => '',
233 ), $result['values']['Billing']);
237 * Check contact activity profile without activity id.
239 public function testContactActivityGetWithoutActivityId() {
240 list($params, $expected) = $this->_createContactWithActivity();
242 unset($params['activity_id']);
243 $result = $this->callAPIFailure('profile', 'get', $params,
244 'Mandatory key(s) missing from params array: activity_id');
248 * Check contact activity profile wrong activity id.
250 public function testContactActivityGetWrongActivityId() {
251 list($params, $expected) = $this->_createContactWithActivity();
253 $params['activity_id'] = 100001;
254 $result = $this->callAPIFailure('profile', 'get', $params,
255 'Invalid Activity Id (aid).');
259 * Check contact activity profile with wrong activity type.
261 public function testContactActivityGetWrongActivityType() {
262 //flush cache by calling with reset
263 $activityTypes = CRM_Core_PseudoConstant
::activityType(TRUE, TRUE, TRUE, 'name', TRUE);
265 $sourceContactId = $this->householdCreate();
267 $activityparams = array(
268 'source_contact_id' => $sourceContactId,
269 'activity_type_id' => '2',
270 'subject' => 'Test activity',
271 'activity_date_time' => '20110316',
273 'location' => 'Pensulvania',
274 'details' => 'a test activity',
276 'priority_id' => '1',
279 $activity = $this->callAPISuccess('activity', 'create', $activityparams);
281 $activityValues = array_pop($activity['values']);
283 list($params, $expected) = $this->_createContactWithActivity();
285 $params['activity_id'] = $activityValues['id'];
286 $result = $this->callAPIFailure('profile', 'get', $params,
287 'This activity cannot be edited or viewed via this profile.'
292 * Check contact activity profile with success.
294 public function testContactActivityGetSuccess() {
295 list($params, $expected) = $this->_createContactWithActivity();
297 $result = $this->callAPISuccess('profile', 'get', $params);
299 foreach ($expected as $profileField => $value) {
300 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $result['values']), "In line " . __LINE__
. " error message: " . "missing/mismatching value for {$profileField}"
306 * Check getfields works & gives us our fields
308 public function testGetFields() {
309 $this->_createIndividualProfile();
310 $this->_addCustomFieldToProfile($this->_profileID
);
311 $result = $this->callAPIAndDocument('profile', 'getfields', array(
312 'action' => 'submit',
313 'profile_id' => $this->_profileID
,
314 ), __FUNCTION__
, __FILE__
,
315 'demonstrates retrieving profile fields passing in an id');
316 $this->assertArrayKeyExists('first_name', $result['values']);
317 $this->assertEquals('2', $result['values']['first_name']['type']);
318 $this->assertEquals('Email', $result['values']['email-primary']['title']);
319 $this->assertEquals('civicrm_state_province', $result['values']['state_province-1']['pseudoconstant']['table']);
320 $this->assertEquals('defaultValue', $result['values']['custom_1']['default_value']);
321 $this->assertFalse(array_key_exists('participant_status', $result['values']));
325 * Check getfields works & gives us our fields - partipant profile
327 public function testGetFieldsParticipantProfile() {
328 $result = $this->callAPISuccess('profile', 'getfields', array(
329 'action' => 'submit',
330 'profile_id' => 'participant_status',
331 'get_options' => 'all',
334 $this->assertTrue(array_key_exists('participant_status_id', $result['values']));
335 $this->assertEquals('Attended', $result['values']['participant_status_id']['options'][2]);
336 $this->assertEquals(array('participant_status'), $result['values']['participant_status_id']['api.aliases']);
340 * Check getfields works & gives us our fields - membership_batch_entry
341 * (getting to the end with no e-notices is pretty good evidence it's working)
343 public function testGetFieldsMembershipBatchProfile() {
344 $result = $this->callAPISuccess('profile', 'getfields', array(
345 'action' => 'submit',
346 'profile_id' => 'membership_batch_entry',
347 'get_options' => 'all',
350 $this->assertTrue(array_key_exists('total_amount', $result['values']));
351 $this->assertTrue(array_key_exists('financial_type_id', $result['values']));
352 $this->assertEquals(array(
353 'contribution_type_id',
356 ), $result['values']['financial_type_id']['api.aliases']);
357 $this->assertTrue(!array_key_exists('financial_type', $result['values']));
358 $this->assertEquals(12, $result['values']['receive_date']['type']);
362 * Check getfields works & gives us our fields - do them all
363 * (getting to the end with no e-notices is pretty good evidence it's working)
365 public function testGetFieldsAllProfiles() {
366 $result = $this->callAPISuccess('uf_group', 'get', array('return' => 'id'));
367 $profileIDs = array_keys($result['values']);
368 foreach ($profileIDs as $profileID) {
369 $result = $this->callAPISuccess('profile', 'getfields', array(
370 'action' => 'submit',
371 'profile_id' => $profileID,
372 'get_options' => 'all',
377 /////////////// test $this->callAPISuccess3_profile_set //////////////////
380 * Check Without ProfileId.
382 public function testProfileSubmitWithoutProfileId() {
386 $result = $this->callAPIFailure('profile', 'submit', $params,
387 'Mandatory key(s) missing from params array: profile_id'
392 * Check with no invalid profile Id.
394 public function testProfileSubmitInvalidProfileId() {
397 'profile_id' => 1000,
399 $result = $this->callAPIFailure('profile', 'submit', $params);
403 * Check with missing required field in profile.
405 public function testProfileSubmitCheckProfileRequired() {
406 $pofileFieldValues = $this->_createIndividualContact();
407 current($pofileFieldValues);
408 $contactId = key($pofileFieldValues);
409 $updateParams = array(
410 'first_name' => 'abc2',
411 'last_name' => 'xyz2',
412 'phone-1-1' => '022 321 826',
413 'country-1' => '1013',
414 'state_province-1' => '1000',
417 $params = array_merge(array('profile_id' => $this->_profileID
, 'contact_id' => $contactId),
421 $result = $this->callAPIFailure('profile', 'submit', $params,
422 "Missing required parameters for profile id $this->_profileID: email-Primary"
427 * Check with success.
429 public function testProfileSubmit() {
430 $pofileFieldValues = $this->_createIndividualContact();
431 current($pofileFieldValues);
432 $contactId = key($pofileFieldValues);
434 $updateParams = array(
435 'first_name' => 'abc2',
436 'last_name' => 'xyz2',
437 'email-primary' => 'abc2.xyz2@gmail.com',
438 'phone-1-1' => '022 321 826',
439 'country-1' => '1013',
440 'state_province-1' => '1000',
443 $params = array_merge(array(
444 'profile_id' => $this->_profileID
,
445 'contact_id' => $contactId,
448 $result = $this->callAPIAndDocument('profile', 'submit', $params, __FUNCTION__
, __FILE__
);
451 'profile_id' => $this->_profileID
,
452 'contact_id' => $contactId,
454 $profileDetails = $this->callAPISuccess('profile', 'get', $getParams);
456 foreach ($updateParams as $profileField => $value) {
457 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $profileDetails['values']), "missing/mismatching value for {$profileField}"
460 unset($params['email-primary']);
461 $params['email-Primary'] = 'my@mail.com';
462 $this->callAPISuccess('profile', 'submit', $params);
463 $profileDetails = $this->callAPISuccess('profile', 'get', $getParams);
464 $this->assertEquals('my@mail.com', $profileDetails['values']['email-Primary']);
468 * Ensure caches are being cleared so we don't get into a debugging trap because of cached metadata
469 * First we delete & create to increment the version & then check for caching probs
471 public function testProfileSubmitCheckCaching() {
472 $this->callAPISuccess('membership_type', 'delete', array('id' => $this->_membershipTypeID
));
473 $this->_membershipTypeID
= $this->membershipTypeCreate();
475 $membershipTypes = $this->callAPISuccess('membership_type', 'get', array());
476 $profileFields = $this->callAPISuccess('profile', 'getfields', array(
477 'get_options' => 'all',
478 'action' => 'submit',
479 'profile_id' => 'membership_batch_entry',
481 $getoptions = $this->callAPISuccess('membership', 'getoptions', array(
482 'field' => 'membership_type',
483 'context' => 'validate',
485 $this->assertEquals(array_keys($membershipTypes['values']), array_keys($getoptions['values']));
486 $this->assertEquals(array_keys($membershipTypes['values']), array_keys($profileFields['values']['membership_type_id']['options']));
491 * Test that the fields are returned in the right order despite the faffing around that goes on.
493 public function testMembershipGetFieldsOrder() {
494 $result = $this->callAPISuccess('profile', 'getfields', array(
495 'action' => 'submit',
496 'profile_id' => 'membership_batch_entry',
499 foreach ($result['values'] as $fieldName => $field) {
500 if ($fieldName == 'profile_id') {
503 $this->assertEquals($field['weight'], $weight);
509 * Check we can submit membership batch profiles (create mode)
511 public function testProfileSubmitMembershipBatch() {
512 $this->_contactID
= $this->individualCreate();
513 $this->callAPISuccess('profile', 'submit', array(
514 'profile_id' => 'membership_batch_entry',
515 'financial_type_id' => 1,
516 'membership_type' => $this->_membershipTypeID
,
517 'join_date' => 'now',
518 'total_amount' => 10,
519 'contribution_status_id' => 1,
520 'receive_date' => 'now',
521 'contact_id' => $this->_contactID
,
526 * Set is deprecated but we need to ensure it still works.
528 public function testLegacySet() {
529 $pofileFieldValues = $this->_createIndividualContact();
530 current($pofileFieldValues);
531 $contactId = key($pofileFieldValues);
533 $updateParams = array(
534 'first_name' => 'abc2',
535 'last_name' => 'xyz2',
536 'email-Primary' => 'abc2.xyz2@gmail.com',
537 'phone-1-1' => '022 321 826',
538 'country-1' => '1013',
539 'state_province-1' => '1000',
542 $params = array_merge(array(
543 'profile_id' => $this->_profileID
,
544 'contact_id' => $contactId,
547 $result = $this->callAPISuccess('profile', 'set', $params);
548 $this->assertArrayKeyExists('values', $result);
550 'profile_id' => $this->_profileID
,
551 'contact_id' => $contactId,
553 $profileDetails = $this->callAPISuccess('profile', 'get', $getParams);
555 foreach ($updateParams as $profileField => $value) {
556 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $profileDetails['values']), "In line " . __LINE__
. " error message: " . "missing/mismatching value for {$profileField}"
562 * Check contact activity profile without activity id.
564 public function testContactActivitySubmitWithoutActivityId() {
565 list($params, $expected) = $this->_createContactWithActivity();
567 $params = array_merge($params, $expected);
568 unset($params['activity_id']);
569 $result = $this->callAPIFailure('profile', 'submit', $params);
570 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: activity_id');
574 * Check contact activity profile wrong activity id.
576 public function testContactActivitySubmitWrongActivityId() {
577 list($params, $expected) = $this->_createContactWithActivity();
578 $params = array_merge($params, $expected);
579 $params['activity_id'] = 100001;
580 $result = $this->callAPIFailure('profile', 'submit', $params);
581 $this->assertEquals($result['error_message'], 'Invalid Activity Id (aid).');
585 * Check contact activity profile with wrong activity type.
587 public function testContactActivitySubmitWrongActivityType() {
588 //flush cache by calling with reset
589 $activityTypes = CRM_Core_PseudoConstant
::activityType(TRUE, TRUE, TRUE, 'name', TRUE);
591 $sourceContactId = $this->householdCreate();
593 $activityparams = array(
594 'source_contact_id' => $sourceContactId,
595 'activity_type_id' => '2',
596 'subject' => 'Test activity',
597 'activity_date_time' => '20110316',
599 'location' => 'Pensulvania',
600 'details' => 'a test activity',
602 'priority_id' => '1',
605 $activity = $this->callAPISuccess('activity', 'create', $activityparams);
607 $activityValues = array_pop($activity['values']);
609 list($params, $expected) = $this->_createContactWithActivity();
611 $params = array_merge($params, $expected);
612 $params['activity_id'] = $activityValues['id'];
613 $result = $this->callAPIFailure('profile', 'submit', $params,
614 'This activity cannot be edited or viewed via this profile.');
618 * Check contact activity profile with success.
620 public function testContactActivitySubmitSuccess() {
621 list($params, $expected) = $this->_createContactWithActivity();
623 $updateParams = array(
624 'first_name' => 'abc2',
625 'last_name' => 'xyz2',
626 'email-Primary' => 'abc2.xyz2@yahoo.com',
627 'activity_subject' => 'Test Meeting',
628 'activity_details' => 'a test activity details',
629 'activity_duration' => '100',
630 'activity_date_time' => '03/08/2010',
631 'activity_status_id' => '2',
633 $profileParams = array_merge($params, $updateParams);
634 $this->callAPISuccess('profile', 'submit', $profileParams);
635 $result = $this->callAPISuccess('profile', 'get', $params);
637 foreach ($updateParams as $profileField => $value) {
638 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $result['values']), "In line " . __LINE__
. " error message: " . "missing/mismatching value for {$profileField}"
644 * Check profile apply Without ProfileId.
646 public function testProfileApplyWithoutProfileId() {
650 $result = $this->callAPIFailure('profile', 'apply', $params,
651 'Mandatory key(s) missing from params array: profile_id');
655 * Check profile apply with no invalid profile Id.
657 public function testProfileApplyInvalidProfileId() {
660 'profile_id' => 1000,
662 $result = $this->callAPIFailure('profile', 'apply', $params);
666 * Check with success.
668 public function testProfileApply() {
669 $pofileFieldValues = $this->_createIndividualContact();
670 current($pofileFieldValues);
671 $contactId = key($pofileFieldValues);
674 'profile_id' => $this->_profileID
,
675 'contact_id' => $contactId,
676 'first_name' => 'abc2',
677 'last_name' => 'xyz2',
678 'email-Primary' => 'abc2.xyz2@gmail.com',
679 'phone-1-1' => '022 321 826',
680 'country-1' => '1013',
681 'state_province-1' => '1000',
684 $result = $this->callAPIAndDocument('profile', 'apply', $params, __FUNCTION__
, __FILE__
);
686 // Expected field values
687 $expected['contact'] = array(
688 'contact_id' => $contactId,
689 'contact_type' => 'Individual',
690 'first_name' => 'abc2',
691 'last_name' => 'xyz2',
693 $expected['email'] = array(
694 'location_type_id' => 1,
696 'email' => 'abc2.xyz2@gmail.com',
699 $expected['phone'] = array(
700 'location_type_id' => 1,
702 'phone_type_id' => 1,
703 'phone' => '022 321 826',
705 $expected['address'] = array(
706 'location_type_id' => 1,
708 'country_id' => 1013,
709 'state_province_id' => 1000,
712 foreach ($expected['contact'] as $field => $value) {
713 $this->assertEquals($value, CRM_Utils_Array
::value($field, $result['values']), "In line " . __LINE__
. " error message: " . "missing/mismatching value for {$field}"
722 $typeValues = array_pop($result['values'][$fieldType]);
723 foreach ($expected[$fieldType] as $field => $value) {
724 $this->assertEquals($value, CRM_Utils_Array
::value($field, $typeValues), "In line " . __LINE__
. " error message: " . "missing/mismatching value for {$field} ({$fieldType})"
731 * Helper function to create an Individual with address/email/phone info. Import UF Group and UF Fields
732 * @param array $params
736 public function _createIndividualContact($params = array()) {
737 $contactParams = array_merge(array(
738 'first_name' => 'abc1',
739 'last_name' => 'xyz1',
740 'email' => 'abc1.xyz1@yahoo.com',
741 'api.address.create' => array(
742 'location_type_id' => 1,
744 'street_address' => '5 Saint Helier St',
746 'country' => 'United States',
747 'state_province' => 'Michigan',
748 'supplemental_address_1' => 'Hallmark Ct',
749 'supplemental_address_2' => 'Jersey Village',
750 'postal_code' => '90210',
751 'city' => 'Gotham City',
754 'api.phone.create' => array(
755 'location_type_id' => '1',
756 'phone' => '021 512 755',
757 'phone_type_id' => '1',
763 $this->_contactID
= $this->individualCreate($contactParams);
764 $this->_createIndividualProfile();
765 // expected result of above created profile with contact Id $contactId
766 $profileData[$this->_contactID
] = array(
767 'first_name' => 'abc1',
768 'last_name' => 'xyz1',
769 'email-primary' => 'abc1.xyz1@yahoo.com',
770 'phone-1-1' => '021 512 755',
771 'country-1' => '1228',
772 'state_province-1' => '1021',
781 public function _createContactWithActivity() {
782 // @TODO: Create profile with custom fields
783 $op = new PHPUnit_Extensions_Database_Operation_Insert();
784 $op->execute($this->_dbconn
,
785 $this->createFlatXMLDataSet(
786 dirname(__FILE__
) . '/dataset/uf_group_contact_activity_26.xml'
789 // hack: xml data set do not accept \ 1 (CRM_Core_DAO::VALUE_SEPARATOR)
790 CRM_Core_DAO
::setFieldValue('CRM_Core_DAO_UFGroup', '26', 'group_type', 'Individual,Contact,Activity' . CRM_Core_DAO
::VALUE_SEPARATOR
. 'ActivityType:1');
792 $sourceContactId = $this->individualCreate();
793 $contactParams = array(
794 'first_name' => 'abc1',
795 'last_name' => 'xyz1',
796 'contact_type' => 'Individual',
797 'email' => 'abc1.xyz1@yahoo.com',
798 'api.address.create' => array(
799 'location_type_id' => 1,
801 'name' => 'Saint Helier St',
803 'country' => 'United States',
804 'state_province' => 'Michigan',
805 'supplemental_address_1' => 'Hallmark Ct',
806 'supplemental_address_2' => 'Jersey Village',
810 $contact = $this->callAPISuccess('contact', 'create', $contactParams);
812 $keys = array_keys($contact['values']);
813 $contactId = array_pop($keys);
815 $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'])
818 $activityParams = array(
819 'source_contact_id' => $sourceContactId,
820 'assignee_contact_id' => $contactId,
821 'activity_type_id' => '1',
822 'subject' => 'Make-it-Happen Meeting',
823 'activity_date_time' => '20110316',
825 'location' => 'Pensulvania',
826 'details' => 'a test activity',
828 'priority_id' => '1',
830 $activity = $this->callAPISuccess('activity', 'create', $activityParams);
832 $activityValues = array_pop($activity['values']);
834 // valid parameters for above profile
835 $profileParams = array(
837 'contact_id' => $contactId,
838 'activity_id' => $activityValues['id'],
841 // expected result of above created profile
843 'first_name' => 'abc1',
844 'last_name' => 'xyz1',
845 'email-Primary' => 'abc1.xyz1@yahoo.com',
846 'activity_subject' => 'Make-it-Happen Meeting',
847 'activity_details' => 'a test activity',
848 'activity_duration' => '120',
849 'activity_date_time_time' => '12:00AM',
850 'activity_date_time' => '03/16/2011',
851 'activity_status_id' => '1',
854 return array($profileParams, $expected);
860 public function _createIndividualProfile() {
862 // creating these via the api as we want to utilise & test the flushing of caches when fields created
865 $ufGroupParams = array(
866 'group_type' => 'Individual,Contact', // really we should remove this & test the ufField create sets it
867 'name' => 'test_individual_contact_profile',
868 'title' => 'Flat Coffee',
869 'api.uf_field.create' => array(
871 'field_name' => 'first_name',
873 'visibility' => 'Public Pages and Listings',
874 'field_type' => 'Individual',
875 'label' => 'First Name',
878 'field_name' => 'last_name',
880 'visibility' => 'Public Pages and Listings',
881 'field_type' => 'Individual',
882 'label' => 'Last Name',
885 'field_name' => 'email',
887 'visibility' => 'Public Pages and Listings',
888 'field_type' => 'Contact',
892 'field_name' => 'phone',
894 'visibility' => 'Public Pages and Listings',
895 'field_type' => 'Contact',
896 'location_type_id' => 1,
897 'phone_type_id' => 1,
901 'field_name' => 'country',
903 'visibility' => 'Public Pages and Listings',
904 'field_type' => 'Contact',
905 'location_type_id' => 1,
906 'label' => 'Country',
909 'field_name' => 'state_province',
911 'visibility' => 'Public Pages and Listings',
912 'field_type' => 'Contact',
913 'location_type_id' => 1,
914 'label' => 'State Province',
917 'field_name' => 'postal_code',
919 'field_type' => 'Contact',
920 'location_type_id' => 1,
921 'label' => 'State Province',
925 $profile = $this->callAPISuccess('uf_group', 'create', $ufGroupParams);
926 $this->_profileID
= $profile['id'];
930 * @param int $profileID
932 public function _addCustomFieldToProfile($profileID) {
933 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, '');
934 $this->uFFieldCreate(array(
935 'uf_group_id' => $profileID,
936 'field_name' => 'custom_' . $ids['custom_field_id'],
937 'contact_type' => 'Contact',