4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.6 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2014 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
30 * Include class definitions
32 require_once 'tests/phpunit/CiviTest/CiviUnitTestCase.php';
35 * Test APIv3 civicrm_profile_* functions
39 class api_v3_ProfileTest
extends CiviUnitTestCase
{
40 protected $_apiversion;
41 protected $_profileID = 0;
42 protected $_membershipTypeID;
43 protected $_contactID;
45 public function setUp() {
46 $this->_apiversion
= 3;
48 $config = CRM_Core_Config
::singleton();
49 $config->countryLimit
[1] = 1013;
50 $config->stateLimit
[1] = 1013;
51 $this->createLoggedInUser();
52 $this->_membershipTypeID
= $this->membershipTypeCreate();
55 public function tearDown() {
57 $this->quickCleanup(array(
62 '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('contact_id' => $contactId, 'street_address' => '25 Big Street', 'city' => 'big city', 'location_type_id' => 5));
177 $this->callAPISuccess('email', 'create', array('contact_id' => $contactId, 'email' => 'big@once.com', 'location_type_id' => 2, 'is_billing' => 1));
179 $expected = current($individual);
182 'profile_id' => array($this->_profileID
, 1, 'Billing'),
183 'contact_id' => $contactId,
186 $result = $this->callAPISuccess('profile', 'get', $params, __FUNCTION__
, __FILE__
);
187 $this->assertEquals('abc1', $result['values'][1]['first_name']);
188 $this->assertEquals($result['values']['Billing'], array(
189 'billing_first_name' => 'abc1',
190 'billing_middle_name' => 'J.',
191 'billing_last_name' => 'xyz1',
192 'billing_street_address-5' => '25 Big Street',
193 'billing_city-5' => 'big city',
194 'billing_state_province_id-5' => '',
195 'billing_country_id-5' => '',
196 'billing-email-5' => 'big@once.com',
197 'email-5' => 'big@once.com',
198 'billing_postal_code-5' => '',
203 * Get Billing empty contact - this will return generic defaults
205 public function testProfileGetBillingEmptyContact() {
208 'profile_id' => array('Billing'),
211 $result = $this->callAPISuccess('profile', 'get', $params);
212 $this->assertEquals(array(
213 'billing_first_name' => '',
214 'billing_middle_name' => '',
215 'billing_last_name' => '',
216 'billing_street_address-5' => '',
217 'billing_city-5' => '',
218 'billing_state_province_id-5' => '',
219 'billing_country_id-5' => '1228',
220 'billing_email-5' => '',
222 'billing_postal_code-5' => '',
223 ), $result['values']['Billing']);
227 * Check contact activity profile without activity id
229 public function testContactActivityGetWithoutActivityId() {
230 list($params, $expected) = $this->_createContactWithActivity();
232 unset($params['activity_id']);
233 $result = $this->callAPIFailure('profile', 'get', $params,
234 'Mandatory key(s) missing from params array: activity_id');
238 * Check contact activity profile wrong activity id
240 public function testContactActivityGetWrongActivityId() {
241 list($params, $expected) = $this->_createContactWithActivity();
243 $params['activity_id'] = 100001;
244 $result = $this->callAPIFailure('profile', 'get', $params,
245 'Invalid Activity Id (aid).');
249 * Check contact activity profile with wrong activity type
251 public function testContactActivityGetWrongActivityType() {
252 //flush cache by calling with reset
253 $activityTypes = CRM_Core_PseudoConstant
::activityType(TRUE, TRUE, TRUE, 'name', TRUE);
255 $sourceContactId = $this->householdCreate();
257 $activityparams = array(
258 'source_contact_id' => $sourceContactId,
259 'activity_type_id' => '2',
260 'subject' => 'Test activity',
261 'activity_date_time' => '20110316',
263 'location' => 'Pensulvania',
264 'details' => 'a test activity',
266 'priority_id' => '1',
269 $activity = $this->callAPISuccess('activity', 'create', $activityparams);
271 $activityValues = array_pop($activity['values']);
273 list($params, $expected) = $this->_createContactWithActivity();
275 $params['activity_id'] = $activityValues['id'];
276 $result = $this->callAPIFailure('profile', 'get', $params,
277 'This activity cannot be edited or viewed via this profile.'
282 * Check contact activity profile with success
284 public function testContactActivityGetSuccess() {
285 list($params, $expected) = $this->_createContactWithActivity();
287 $result = $this->callAPISuccess('profile', 'get', $params);
289 foreach ($expected as $profileField => $value) {
290 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $result['values']), "In line " . __LINE__
. " error message: " . "missing/mismatching value for {$profileField}"
296 * Check getfields works & gives us our fields
298 public function testGetFields() {
299 $this->_createIndividualProfile();
300 $this->_addCustomFieldToProfile($this->_profileID
);
301 $result = $this->callAPIAndDocument('profile', 'getfields', array('action' => 'submit', 'profile_id' => $this->_profileID
), __FUNCTION__
, __FILE__
,
302 'demonstrates retrieving profile fields passing in an id');
303 $this->assertArrayKeyExists('first_name', $result['values']);
304 $this->assertEquals('2', $result['values']['first_name']['type']);
305 $this->assertEquals('Email', $result['values']['email-primary']['title']);
306 $this->assertEquals('civicrm_state_province', $result['values']['state_province-1']['pseudoconstant']['table']);
307 $this->assertEquals('defaultValue', $result['values']['custom_1']['default_value']);
308 $this->assertFalse(array_key_exists('participant_status', $result['values']));
312 * Check getfields works & gives us our fields - partipant profile
314 public function testGetFieldsParticipantProfile() {
315 $result = $this->callAPISuccess('profile', 'getfields', array(
316 'action' => 'submit',
317 'profile_id' => 'participant_status',
318 'get_options' => 'all')
320 $this->assertTrue(array_key_exists('participant_status_id', $result['values']));
321 $this->assertEquals('Attended', $result['values']['participant_status_id']['options'][2]);
322 $this->assertEquals(array('participant_status'), $result['values']['participant_status_id']['api.aliases']);
326 * Check getfields works & gives us our fields - membership_batch_entry
327 * (getting to the end with no e-notices is pretty good evidence it's working)
329 public function testGetFieldsMembershipBatchProfile() {
330 $result = $this->callAPISuccess('profile', 'getfields', array(
331 'action' => 'submit',
332 'profile_id' => 'membership_batch_entry',
333 'get_options' => 'all')
335 $this->assertTrue(array_key_exists('total_amount', $result['values']));
336 $this->assertTrue(array_key_exists('financial_type_id', $result['values']));
337 $this->assertEquals(array('contribution_type_id', 'contribution_type', 'financial_type'), $result['values']['financial_type_id']['api.aliases']);
338 $this->assertTrue(!array_key_exists('financial_type', $result['values']));
339 $this->assertEquals(12, $result['values']['receive_date']['type']);
343 * Check getfields works & gives us our fields - do them all
344 * (getting to the end with no e-notices is pretty good evidence it's working)
346 public function testGetFieldsAllProfiles() {
347 $result = $this->callAPISuccess('uf_group', 'get', array('return' => 'id'));
348 $profileIDs = array_keys($result['values']);
349 foreach ($profileIDs as $profileID) {
350 $result = $this->callAPISuccess('profile', 'getfields', array(
351 'action' => 'submit',
352 'profile_id' => $profileID,
353 'get_options' => 'all')
357 /////////////// test $this->callAPISuccess3_profile_set //////////////////
360 * Check Without ProfileId
362 public function testProfileSubmitWithoutProfileId() {
366 $result = $this->callAPIFailure('profile', 'submit', $params,
367 'Mandatory key(s) missing from params array: profile_id'
372 * Check with no invalid profile Id
374 public function testProfileSubmitInvalidProfileId() {
377 'profile_id' => 1000,
379 $result = $this->callAPIFailure('profile', 'submit', $params);
383 * Check with missing required field in profile
385 public function testProfileSubmitCheckProfileRequired() {
386 $pofileFieldValues = $this->_createIndividualContact();
387 current($pofileFieldValues);
388 $contactId = key($pofileFieldValues);
389 $updateParams = array(
390 'first_name' => 'abc2',
391 'last_name' => 'xyz2',
392 'phone-1-1' => '022 321 826',
393 'country-1' => '1013',
394 'state_province-1' => '1000',
397 $params = array_merge(array('profile_id' => $this->_profileID
, 'contact_id' => $contactId),
401 $result = $this->callAPIFailure('profile', 'submit', $params,
402 "Missing required parameters for profile id $this->_profileID: email-Primary"
409 public function testProfileSubmit() {
410 $pofileFieldValues = $this->_createIndividualContact();
411 current($pofileFieldValues);
412 $contactId = key($pofileFieldValues);
414 $updateParams = array(
415 'first_name' => 'abc2',
416 'last_name' => 'xyz2',
417 'email-primary' => 'abc2.xyz2@gmail.com',
418 'phone-1-1' => '022 321 826',
419 'country-1' => '1013',
420 'state_province-1' => '1000',
423 $params = array_merge(array(
424 'profile_id' => $this->_profileID
,
425 'contact_id' => $contactId,
428 $result = $this->callAPIAndDocument('profile', 'submit', $params, __FUNCTION__
, __FILE__
);
431 'profile_id' => $this->_profileID
,
432 'contact_id' => $contactId,
434 $profileDetails = $this->callAPISuccess('profile', 'get', $getParams);
436 foreach ($updateParams as $profileField => $value) {
437 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $profileDetails['values']), "missing/mismatching value for {$profileField}"
440 unset($params['email-primary']);
441 $params['email-Primary'] = 'my@mail.com';
442 $this->callAPISuccess('profile', 'submit', $params);
443 $profileDetails = $this->callAPISuccess('profile', 'get', $getParams);
444 $this->assertEquals('my@mail.com', $profileDetails['values']['email-Primary']);
448 * Ensure caches are being cleared so we don't get into a debugging trap because of cached metadata
449 * First we delete & create to increment the version & then check for caching probs
451 public function testProfileSubmitCheckCaching() {
452 $this->callAPISuccess('membership_type', 'delete', array('id' => $this->_membershipTypeID
));
453 $this->_membershipTypeID
= $this->membershipTypeCreate();
455 $membershipTypes = $this->callAPISuccess('membership_type', 'get', array());
456 $profileFields = $this->callAPISuccess('profile', 'getfields', array('get_options' => 'all', 'action' => 'submit', 'profile_id' => 'membership_batch_entry'));
457 $getoptions = $this->callAPISuccess('membership', 'getoptions', array('field' => 'membership_type', 'context' => 'validate'));
458 $this->assertEquals(array_keys($membershipTypes['values']), array_keys($getoptions['values']));
459 $this->assertEquals(array_keys($membershipTypes['values']), array_keys($profileFields['values']['membership_type_id']['options']));
464 * Test that the fields are returned in the right order despite the faffing around that goes on
466 public function testMembershipGetFieldsOrder() {
467 $result = $this->callAPISuccess('profile', 'getfields', array('action' => 'submit', 'profile_id' => 'membership_batch_entry'));
469 foreach($result['values'] as $fieldName => $field) {
470 if($fieldName == 'profile_id') {
473 $this->assertEquals($field['weight'], $weight);
478 * Check we can submit membership batch profiles (create mode)
480 public function testProfileSubmitMembershipBatch() {
481 $this->_contactID
= $this->individualCreate();
482 $this->callAPISuccess('profile', 'submit', array(
483 'profile_id' => 'membership_batch_entry',
484 'financial_type_id' => 1,
485 'membership_type' => $this->_membershipTypeID
,
486 'join_date' => 'now',
487 'total_amount' => 10,
488 'contribution_status_id' => 1,
489 'receive_date' => 'now',
490 'contact_id' => $this->_contactID
,
494 * Set is deprecated but we need to ensure it still works
496 public function testLegacySet() {
497 $pofileFieldValues = $this->_createIndividualContact();
498 current($pofileFieldValues);
499 $contactId = key($pofileFieldValues);
501 $updateParams = array(
502 'first_name' => 'abc2',
503 'last_name' => 'xyz2',
504 'email-Primary' => 'abc2.xyz2@gmail.com',
505 'phone-1-1' => '022 321 826',
506 'country-1' => '1013',
507 'state_province-1' => '1000',
510 $params = array_merge(array(
511 'profile_id' => $this->_profileID
,
512 'contact_id' => $contactId,
515 $result = $this->callAPISuccess('profile', 'set', $params);
516 $this->assertArrayKeyExists('values', $result);
518 'profile_id' => $this->_profileID
,
519 'contact_id' => $contactId,
521 $profileDetails = $this->callAPISuccess('profile', 'get', $getParams);
523 foreach ($updateParams as $profileField => $value) {
524 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $profileDetails['values']), "In line " . __LINE__
. " error message: " . "missing/mismatching value for {$profileField}"
530 * Check contact activity profile without activity id
532 public function testContactActivitySubmitWithoutActivityId() {
533 list($params, $expected) = $this->_createContactWithActivity();
535 $params = array_merge($params, $expected);
536 unset($params['activity_id']);
537 $result = $this->callAPIFailure('profile', 'submit', $params);
538 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: activity_id');
542 * Check contact activity profile wrong activity id
544 public function testContactActivitySubmitWrongActivityId() {
545 list($params, $expected) = $this->_createContactWithActivity();
546 $params = array_merge($params, $expected);
547 $params['activity_id'] = 100001;
548 $result = $this->callAPIFailure('profile', 'submit', $params);
549 $this->assertEquals($result['error_message'], 'Invalid Activity Id (aid).');
553 * Check contact activity profile with wrong activity type
555 public function testContactActivitySubmitWrongActivityType() {
556 //flush cache by calling with reset
557 $activityTypes = CRM_Core_PseudoConstant
::activityType(TRUE, TRUE, TRUE, 'name', TRUE);
559 $sourceContactId = $this->householdCreate();
561 $activityparams = array(
562 'source_contact_id' => $sourceContactId,
563 'activity_type_id' => '2',
564 'subject' => 'Test activity',
565 'activity_date_time' => '20110316',
567 'location' => 'Pensulvania',
568 'details' => 'a test activity',
570 'priority_id' => '1',
573 $activity = $this->callAPISuccess('activity', 'create', $activityparams);
575 $activityValues = array_pop($activity['values']);
577 list($params, $expected) = $this->_createContactWithActivity();
579 $params = array_merge($params, $expected);
580 $params['activity_id'] = $activityValues['id'];
581 $result = $this->callAPIFailure('profile', 'submit', $params,
582 'This activity cannot be edited or viewed via this profile.');
586 * Check contact activity profile with success
588 public function testContactActivitySubmitSuccess() {
589 list($params, $expected) = $this->_createContactWithActivity();
591 $updateParams = array(
592 'first_name' => 'abc2',
593 'last_name' => 'xyz2',
594 'email-Primary' => 'abc2.xyz2@yahoo.com',
595 'activity_subject' => 'Test Meeting',
596 'activity_details' => 'a test activity details',
597 'activity_duration' => '100',
598 'activity_date_time' => '03/08/2010',
599 'activity_status_id' => '2',
601 $profileParams = array_merge($params, $updateParams);
602 $this->callAPISuccess('profile', 'submit', $profileParams);
603 $result = $this->callAPISuccess('profile', 'get', $params);
605 foreach ($updateParams as $profileField => $value) {
606 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $result['values']), "In line " . __LINE__
. " error message: " . "missing/mismatching value for {$profileField}"
612 * Check profile apply Without ProfileId
614 public function testProfileApplyWithoutProfileId() {
618 $result = $this->callAPIFailure('profile', 'apply', $params,
619 'Mandatory key(s) missing from params array: profile_id');
623 * Check profile apply with no invalid profile Id
625 public function testProfileApplyInvalidProfileId() {
628 'profile_id' => 1000,
630 $result = $this->callAPIFailure('profile', 'apply', $params);
636 public function testProfileApply() {
637 $pofileFieldValues = $this->_createIndividualContact();
638 current($pofileFieldValues);
639 $contactId = key($pofileFieldValues);
642 'profile_id' => $this->_profileID
,
643 'contact_id' => $contactId,
644 'first_name' => 'abc2',
645 'last_name' => 'xyz2',
646 'email-Primary' => 'abc2.xyz2@gmail.com',
647 'phone-1-1' => '022 321 826',
648 'country-1' => '1013',
649 'state_province-1' => '1000',
652 $result = $this->callAPIAndDocument('profile', 'apply', $params, __FUNCTION__
, __FILE__
);
654 // Expected field values
655 $expected['contact'] = array(
656 'contact_id' => $contactId,
657 'contact_type' => 'Individual',
658 'first_name' => 'abc2',
659 'last_name' => 'xyz2',
661 $expected['email'] = array(
662 'location_type_id' => 1,
664 'email' => 'abc2.xyz2@gmail.com',
667 $expected['phone'] = array(
668 'location_type_id' => 1,
670 'phone_type_id' => 1,
671 'phone' => '022 321 826',
673 $expected['address'] = array(
674 'location_type_id' => 1,
676 'country_id' => 1013,
677 'state_province_id' => 1000,
680 foreach ($expected['contact'] as $field => $value) {
681 $this->assertEquals($value, CRM_Utils_Array
::value($field, $result['values']), "In line " . __LINE__
. " error message: " . "missing/mismatching value for {$field}"
686 'email', 'phone', 'address') as $fieldType) {
687 $typeValues = array_pop($result['values'][$fieldType]);
688 foreach ($expected[$fieldType] as $field => $value) {
689 $this->assertEquals($value, CRM_Utils_Array
::value($field, $typeValues), "In line " . __LINE__
. " error message: " . "missing/mismatching value for {$field} ({$fieldType})"
696 * Helper function to create an Individual with address/email/phone info. Import UF Group and UF Fields
697 * @param array $params
701 public function _createIndividualContact($params = array()) {
702 $contactParams = array_merge(array(
703 'first_name' => 'abc1',
704 'last_name' => 'xyz1',
705 'email' => 'abc1.xyz1@yahoo.com',
706 'api.address.create' => array(
707 'location_type_id' => 1,
709 'street_address' => '5 Saint Helier St',
711 'country' => 'United States',
712 'state_province' => 'Michigan',
713 'supplemental_address_1' => 'Hallmark Ct',
714 'supplemental_address_2' => 'Jersey Village',
715 'postal_code' => '90210',
716 'city' => 'Gotham City',
719 'api.phone.create' => array(
720 'location_type_id' => '1',
721 'phone' => '021 512 755',
722 'phone_type_id' => '1',
728 $this->_contactID
= $this->individualCreate($contactParams);
729 $this->_createIndividualProfile();
730 // expected result of above created profile with contact Id $contactId
731 $profileData[$this->_contactID
] = array(
732 'first_name' => 'abc1',
733 'last_name' => 'xyz1',
734 'email-primary' => 'abc1.xyz1@yahoo.com',
735 'phone-1-1' => '021 512 755',
736 'country-1' => '1228',
737 'state_province-1' => '1021',
746 public function _createContactWithActivity() {
747 // @TODO: Create profile with custom fields
748 $op = new PHPUnit_Extensions_Database_Operation_Insert();
749 $op->execute($this->_dbconn
,
750 $this->createFlatXMLDataSet(
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 public 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'];
894 * @param int $profileID
896 public function _addCustomFieldToProfile($profileID) {
897 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, '');
898 $this->uFFieldCreate(array('uf_group_id' => $profileID, 'field_name' => 'custom_' . $ids['custom_field_id'], 'contact_type' => 'Contact'));