4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.4 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
30 * Include class definitions
32 require_once 'tests/phpunit/CiviTest/CiviUnitTestCase.php';
35 * Test APIv3 civicrm_profile_* functions
39 class api_v3_ProfileTest
extends CiviUnitTestCase
{
40 protected $_apiversion;
41 protected $_profileID = 0;
42 protected $_membershipTypeID;
43 protected $_contactID;
46 'name' => 'Profile Test',
47 'description' => 'Test all profile API methods.',
48 'group' => 'CiviCRM API Tests',
53 $this->_apiversion
= 3;
55 $config = CRM_Core_Config
::singleton();
56 $config->countryLimit
[1] = 1013;
57 $config->stateLimit
[1] = 1013;
58 $this->createLoggedInUser();
59 $this->_membershipTypeID
= $this->membershipTypeCreate();
64 $this->quickCleanup(array(
69 'civicrm_contribution',
71 $this->callAPISuccess('membership_type', 'delete', array('id' => $this->_membershipTypeID
));
72 // ok can't be bothered wring an api to do this & truncating is crazy
73 CRM_Core_DAO
::executeQuery(" DELETE FROM civicrm_uf_group WHERE id IN ($this->_profileID, 26)");
76 ////////////// test $this->callAPISuccess3_profile_get //////////////////
79 * check Without ProfileId
81 function testProfileGetWithoutProfileId() {
85 $result = $this->callAPIFailure('profile', 'get', $params,
86 'Mandatory key(s) missing from params array: profile_id'
91 * check with no invalid profile Id
93 function testProfileGetInvalidProfileId() {
98 $result = $this->callAPIFailure('profile', 'get', $params);
104 function testProfileGet() {
105 $pofileFieldValues = $this->_createIndividualContact();
106 $expected = current($pofileFieldValues);
107 $contactId = key($pofileFieldValues);
109 'profile_id' => $this->_profileID
,
110 'contact_id' => $contactId,
112 $result = $this->callAPISuccess('profile', 'get', $params);
113 foreach ($expected as $profileField => $value) {
114 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $result['values']));
118 function testProfileGetMultiple() {
119 $pofileFieldValues = $this->_createIndividualContact();
120 $expected = current($pofileFieldValues);
121 $contactId = key($pofileFieldValues);
123 'profile_id' => array($this->_profileID
, 1, 'Billing'),
124 'contact_id' => $contactId,
127 $result = $this->callAPIAndDocument('profile', 'get', $params, __FUNCTION__
, __FILE__
);
128 foreach ($expected as $profileField => $value) {
129 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $result['values'][$this->_profileID
]), " error message: " . "missing/mismatching value for {$profileField}");
131 $this->assertEquals('abc1', $result['values'][1]['first_name'], " error message: " . "missing/mismatching value for {$profileField}");
132 $this->assertFalse(array_key_exists('email-Primary', $result['values'][1]), 'profile 1 doesn not include email');
133 $this->assertEquals($result['values']['Billing'], array(
134 'billing_first_name' => 'abc1',
135 'billing_middle_name' => 'J.',
136 'billing_last_name' => 'xyz1',
137 'billing_street_address-5' => '5 Saint Helier St',
138 'billing_city-5' => 'Gotham City',
139 'billing_state_province_id-5' => '1021',
140 'billing_country_id-5' => '1228',
141 'billing-email-5' => 'abc1.xyz1@yahoo.com',
142 'billing_postal_code-5' => '90210',
143 'billing-email-5' => 'abc1.xyz1@yahoo.com',
144 'email-5' => 'abc1.xyz1@yahoo.com',
148 function testProfileGetBillingUseIsBillingLocation() {
149 $individual = $this->_createIndividualContact();
150 $contactId = key($individual);
151 $this->callAPISuccess('address', 'create', array(
153 'street_address' => 'is billing st',
154 'location_type_id' => 2,
155 'contact_id' => $contactId,
158 $expected = current($individual);
161 'profile_id' => array($this->_profileID
, 1, 'Billing'),
162 'contact_id' => $contactId,
165 $result = $this->callAPISuccess('profile', 'get', $params);
166 $this->assertEquals('abc1', $result['values'][1]['first_name']);
167 $this->assertEquals(array(
168 'billing_first_name' => 'abc1',
169 'billing_middle_name' => 'J.',
170 'billing_last_name' => 'xyz1',
171 'billing_street_address-5' => 'is billing st',
172 'billing_city-5' => '',
173 'billing_state_province_id-5' => '',
174 'billing_country_id-5' => '',
175 'billing-email-5' => 'abc1.xyz1@yahoo.com',
176 'email-5' => 'abc1.xyz1@yahoo.com',
177 'billing_postal_code-5' => '',
178 ), $result['values']['Billing']);
181 function testProfileGetMultipleHasBillingLocation() {
182 $individual = $this->_createIndividualContact();
183 $contactId = key($individual);
184 $this->callAPISuccess('address', 'create', array('contact_id' => $contactId , 'street_address' => '25 Big Street', 'city' => 'big city', 'location_type_id' => 5));
185 $this->callAPISuccess('email', 'create', array('contact_id' => $contactId , 'email' => 'big@once.com', 'location_type_id' => 2, 'is_billing' => 1));
187 $expected = current($individual);
190 'profile_id' => array($this->_profileID
, 1, 'Billing'),
191 'contact_id' => $contactId,
194 $result = $this->callAPISuccess('profile', 'get', $params, __FUNCTION__
, __FILE__
);
195 $this->assertEquals('abc1', $result['values'][1]['first_name']);
196 $this->assertEquals($result['values']['Billing'], array(
197 'billing_first_name' => 'abc1',
198 'billing_middle_name' => 'J.',
199 'billing_last_name' => 'xyz1',
200 'billing_street_address-5' => '25 Big Street',
201 'billing_city-5' => 'big city',
202 'billing_state_province_id-5' => '',
203 'billing_country_id-5' => '',
204 'billing-email-5' => 'big@once.com',
205 'email-5' => 'big@once.com',
206 'billing_postal_code-5' => '',
211 * get Billing empty contact - this will return generic defaults
213 function testProfileGetBillingEmptyContact() {
216 'profile_id' => array('Billing'),
219 $result = $this->callAPISuccess('profile', 'get', $params);
220 $this->assertEquals(array(
221 'billing_first_name' => '',
222 'billing_middle_name' => '',
223 'billing_last_name' => '',
224 'billing_street_address-5' => '',
225 'billing_city-5' => '',
226 'billing_state_province_id-5' => '',
227 'billing_country_id-5' => '1228',
228 'billing_email-5' => '',
230 'billing_postal_code-5' => '',
231 ), $result['values']['Billing']);
235 * check contact activity profile without activity id
237 function testContactActivityGetWithoutActivityId() {
238 list($params, $expected) = $this->_createContactWithActivity();
240 unset($params['activity_id']);
241 $result = $this->callAPIFailure('profile', 'get', $params,
242 'Mandatory key(s) missing from params array: activity_id');
246 * check contact activity profile wrong activity id
248 function testContactActivityGetWrongActivityId() {
249 list($params, $expected) = $this->_createContactWithActivity();
251 $params['activity_id'] = 100001;
252 $result = $this->callAPIFailure('profile', 'get', $params,
253 'Invalid Activity Id (aid).');
257 * check contact activity profile with wrong activity type
259 function testContactActivityGetWrongActivityType() {
260 //flush cache by calling with reset
261 $activityTypes = CRM_Core_PseudoConstant
::activityType(TRUE, TRUE, TRUE, 'name', TRUE);
263 $sourceContactId = $this->householdCreate();
265 $activityparams = array(
266 'source_contact_id' => $sourceContactId,
267 'activity_type_id' => '2',
268 'subject' => 'Test activity',
269 'activity_date_time' => '20110316',
271 'location' => 'Pensulvania',
272 'details' => 'a test activity',
274 'priority_id' => '1',
277 $activity = $this->callAPISuccess('activity', 'create', $activityparams);
279 $activityValues = array_pop($activity['values']);
281 list($params, $expected) = $this->_createContactWithActivity();
283 $params['activity_id'] = $activityValues['id'];
284 $result = $this->callAPIFailure('profile', 'get', $params,
285 'This activity cannot be edited or viewed via this profile.'
290 * check contact activity profile with success
292 function testContactActivityGetSuccess() {
293 list($params, $expected) = $this->_createContactWithActivity();
295 $result = $this->callAPISuccess('profile', 'get', $params);
297 foreach ($expected as $profileField => $value) {
298 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $result['values']), "In line " . __LINE__
. " error message: " . "missing/mismatching value for {$profileField}"
304 * Check getfields works & gives us our fields
306 function testGetFields() {
307 $this->_createIndividualProfile();
308 $this->_addCustomFieldToProfile($this->_profileID
);
309 $result = $this->callAPIAndDocument('profile', 'getfields', array('action' => 'submit', 'profile_id' => $this->_profileID
), __FUNCTION__
, __FILE__
,
310 'demonstrates retrieving profile fields passing in an id');
311 $this->assertArrayKeyExists('first_name', $result['values']);
312 $this->assertEquals('2', $result['values']['first_name']['type']);
313 $this->assertEquals('Email', $result['values']['email-primary']['title']);
314 $this->assertEquals('civicrm_state_province', $result['values']['state_province-1']['pseudoconstant']['table']);
315 $this->assertEquals('defaultValue', $result['values']['custom_1']['default_value']);
316 $this->assertFalse(array_key_exists('participant_status', $result['values']));
319 * Check getfields works & gives us our fields - partipant profile
321 function testGetFieldsParticipantProfile() {
322 $result = $this->callAPISuccess('profile', 'getfields', array(
323 'action' => 'submit',
324 'profile_id' => 'participant_status',
325 'get_options' => 'all')
327 $this->assertTrue(array_key_exists('participant_status_id', $result['values']));
328 $this->assertEquals('Attended', $result['values']['participant_status_id']['options'][2]);
329 $this->assertEquals(array('participant_status'), $result['values']['participant_status_id']['api.aliases']);
333 * Check getfields works & gives us our fields - membership_batch_entry
334 * (getting to the end with no e-notices is pretty good evidence it's working)
336 function testGetFieldsMembershipBatchProfile() {
337 $result = $this->callAPISuccess('profile', 'getfields', array(
338 'action' => 'submit',
339 'profile_id' => 'membership_batch_entry',
340 'get_options' => 'all')
342 $this->assertTrue(array_key_exists('total_amount', $result['values']));
343 $this->assertTrue(array_key_exists('financial_type_id', $result['values']));
344 $this->assertEquals(array('contribution_type_id', 'contribution_type', 'financial_type'), $result['values']['financial_type_id']['api.aliases']);
345 $this->assertTrue(!array_key_exists('financial_type', $result['values']));
346 $this->assertEquals(12, $result['values']['receive_date']['type']);
350 * Check getfields works & gives us our fields - do them all
351 * (getting to the end with no e-notices is pretty good evidence it's working)
353 function testGetFieldsAllProfiles() {
354 $result = $this->callAPISuccess('uf_group', 'get', array('return' => 'id'));
355 $profileIDs = array_keys($result['values']);
356 foreach ($profileIDs as $profileID) {
357 $result = $this->callAPISuccess('profile', 'getfields', array(
358 'action' => 'submit',
359 'profile_id' => $profileID,
360 'get_options' => 'all')
364 /////////////// test $this->callAPISuccess3_profile_set //////////////////
367 * check Without ProfileId
369 function testProfileSubmitWithoutProfileId() {
373 $result = $this->callAPIFailure('profile', 'submit', $params,
374 'Mandatory key(s) missing from params array: profile_id'
379 * check with no invalid profile Id
381 function testProfileSubmitInvalidProfileId() {
384 'profile_id' => 1000,
386 $result = $this->callAPIFailure('profile', 'submit', $params);
390 * check with missing required field in profile
392 function testProfileSubmitCheckProfileRequired() {
393 $pofileFieldValues = $this->_createIndividualContact();
394 current($pofileFieldValues);
395 $contactId = key($pofileFieldValues);
396 $updateParams = array(
397 'first_name' => 'abc2',
398 'last_name' => 'xyz2',
399 'phone-1-1' => '022 321 826',
400 'country-1' => '1013',
401 'state_province-1' => '1000',
404 $params = array_merge(array('profile_id' => $this->_profileID
, 'contact_id' => $contactId),
408 $result = $this->callAPIFailure('profile', 'submit', $params,
409 "Missing required parameters for profile id $this->_profileID: email-Primary"
416 function testProfileSubmit() {
417 $pofileFieldValues = $this->_createIndividualContact();
418 current($pofileFieldValues);
419 $contactId = key($pofileFieldValues);
421 $updateParams = array(
422 'first_name' => 'abc2',
423 'last_name' => 'xyz2',
424 'email-primary' => 'abc2.xyz2@gmail.com',
425 'phone-1-1' => '022 321 826',
426 'country-1' => '1013',
427 'state_province-1' => '1000',
430 $params = array_merge(array(
431 'profile_id' => $this->_profileID
,
432 'contact_id' => $contactId,
435 $result = $this->callAPIAndDocument('profile', 'submit', $params, __FUNCTION__
, __FILE__
);
438 'profile_id' => $this->_profileID
,
439 'contact_id' => $contactId,
441 $profileDetails = $this->callAPISuccess('profile', 'get', $getParams);
443 foreach ($updateParams as $profileField => $value) {
444 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $profileDetails['values']), "missing/mismatching value for {$profileField}"
447 unset($params['email-primary']);
448 $params['email-Primary'] = 'my@mail.com';
449 $this->callAPISuccess('profile', 'submit', $params);
450 $profileDetails = $this->callAPISuccess('profile', 'get', $getParams);
451 $this->assertEquals('my@mail.com', $profileDetails['values']['email-Primary']);
455 * Ensure caches are being cleared so we don't get into a debugging trap because of cached metadata
456 * First we delete & create to increment the version & then check for caching probs
458 function testProfileSubmitCheckCaching() {
459 $this->callAPISuccess('membership_type', 'delete', array('id' => $this->_membershipTypeID
));
460 $this->_membershipTypeID
= $this->membershipTypeCreate();
462 $membershipTypes = $this->callAPISuccess('membership_type', 'get', array());
463 $profileFields = $this->callAPISuccess('profile', 'getfields', array('get_options' => 'all', 'action' => 'submit', 'profile_id' => 'membership_batch_entry'));
464 $getoptions = $this->callAPISuccess('membership', 'getoptions', array('field' => 'membership_type', 'context' => 'validate'));
465 $this->assertEquals(array_keys($membershipTypes['values']), array_keys($getoptions['values']));
466 $this->assertEquals(array_keys($membershipTypes['values']), array_keys($profileFields['values']['membership_type']['options']));
470 * Check we can submit membership batch profiles (create mode)
472 function testProfileSubmitMembershipBatch() {
473 $this->_contactID
= $this->individualCreate();
474 $this->callAPISuccess('profile', 'submit', array(
475 'profile_id' => 'membership_batch_entry',
476 'financial_type_id' => 1,
477 'membership_type' => $this->_membershipTypeID
,
478 'join_date' => 'now',
479 'total_amount' => 10,
480 'contribution_status_id' => 1,
481 'receive_date' => 'now',
482 'contact_id' => $this->_contactID
,
486 * set is deprecated but we need to ensure it still works
488 function testLegacySet() {
489 $pofileFieldValues = $this->_createIndividualContact();
490 current($pofileFieldValues);
491 $contactId = key($pofileFieldValues);
493 $updateParams = array(
494 'first_name' => 'abc2',
495 'last_name' => 'xyz2',
496 'email-Primary' => 'abc2.xyz2@gmail.com',
497 'phone-1-1' => '022 321 826',
498 'country-1' => '1013',
499 'state_province-1' => '1000',
502 $params = array_merge(array(
503 'profile_id' => $this->_profileID
,
504 'contact_id' => $contactId,
507 $result = $this->callAPISuccess('profile', 'set', $params);
508 $this->assertArrayKeyExists('values', $result);
510 'profile_id' => $this->_profileID
,
511 'contact_id' => $contactId,
513 $profileDetails = $this->callAPISuccess('profile', 'get', $getParams);
515 foreach ($updateParams as $profileField => $value) {
516 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $profileDetails['values']), "In line " . __LINE__
. " error message: " . "missing/mismatching value for {$profileField}"
521 * check contact activity profile without activity id
523 function testContactActivitySubmitWithoutActivityId() {
524 list($params, $expected) = $this->_createContactWithActivity();
526 $params = array_merge($params, $expected);
527 unset($params['activity_id']);
528 $result = $this->callAPIFailure('profile', 'submit', $params);
529 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: activity_id');
533 * check contact activity profile wrong activity id
535 function testContactActivitySubmitWrongActivityId() {
536 list($params, $expected) = $this->_createContactWithActivity();
537 $params = array_merge($params, $expected);
538 $params['activity_id'] = 100001;
539 $result = $this->callAPIFailure('profile', 'submit', $params);
540 $this->assertEquals($result['error_message'], 'Invalid Activity Id (aid).');
544 * check contact activity profile with wrong activity type
546 function testContactActivitySubmitWrongActivityType() {
547 //flush cache by calling with reset
548 $activityTypes = CRM_Core_PseudoConstant
::activityType(TRUE, TRUE, TRUE, 'name', TRUE);
550 $sourceContactId = $this->householdCreate();
552 $activityparams = array(
553 'source_contact_id' => $sourceContactId,
554 'activity_type_id' => '2',
555 'subject' => 'Test activity',
556 'activity_date_time' => '20110316',
558 'location' => 'Pensulvania',
559 'details' => 'a test activity',
561 'priority_id' => '1',
564 $activity = $this->callAPISuccess('activity', 'create', $activityparams);
566 $activityValues = array_pop($activity['values']);
568 list($params, $expected) = $this->_createContactWithActivity();
570 $params = array_merge($params, $expected);
571 $params['activity_id'] = $activityValues['id'];
572 $result = $this->callAPIFailure('profile', 'submit', $params,
573 'This activity cannot be edited or viewed via this profile.');
577 * check contact activity profile with success
579 function testContactActivitySubmitSuccess() {
580 list($params, $expected) = $this->_createContactWithActivity();
582 $updateParams = array(
583 'first_name' => 'abc2',
584 'last_name' => 'xyz2',
585 'email-Primary' => 'abc2.xyz2@yahoo.com',
586 'activity_subject' => 'Test Meeting',
587 'activity_details' => 'a test activity details',
588 'activity_duration' => '100',
589 'activity_date_time' => '03/08/2010',
590 'activity_status_id' => '2',
592 $profileParams = array_merge($params, $updateParams);
593 $this->callAPISuccess('profile', 'submit', $profileParams);
594 $result = $this->callAPISuccess('profile', 'get', $params);
596 foreach ($updateParams as $profileField => $value) {
597 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $result['values']), "In line " . __LINE__
. " error message: " . "missing/mismatching value for {$profileField}"
603 * check profile apply Without ProfileId
605 function testProfileApplyWithoutProfileId() {
609 $result = $this->callAPIFailure('profile', 'apply', $params,
610 'Mandatory key(s) missing from params array: profile_id');
614 * check profile apply with no invalid profile Id
616 function testProfileApplyInvalidProfileId() {
619 'profile_id' => 1000,
621 $result = $this->callAPIFailure('profile', 'apply', $params);
627 function testProfileApply() {
628 $pofileFieldValues = $this->_createIndividualContact();
629 current($pofileFieldValues);
630 $contactId = key($pofileFieldValues);
633 'profile_id' => $this->_profileID
,
634 'contact_id' => $contactId,
635 'first_name' => 'abc2',
636 'last_name' => 'xyz2',
637 'email-Primary' => 'abc2.xyz2@gmail.com',
638 'phone-1-1' => '022 321 826',
639 'country-1' => '1013',
640 'state_province-1' => '1000',
643 $result = $this->callAPIAndDocument('profile', 'apply', $params, __FUNCTION__
, __FILE__
);
645 // Expected field values
646 $expected['contact'] = array(
647 'contact_id' => $contactId,
648 'contact_type' => 'Individual',
649 'first_name' => 'abc2',
650 'last_name' => 'xyz2',
652 $expected['email'] = array(
653 'location_type_id' => 1,
655 'email' => 'abc2.xyz2@gmail.com',
658 $expected['phone'] = array(
659 'location_type_id' => 1,
661 'phone_type_id' => 1,
662 'phone' => '022 321 826',
664 $expected['address'] = array(
665 'location_type_id' => 1,
667 'country_id' => 1013,
668 'state_province_id' => 1000,
671 foreach ($expected['contact'] as $field => $value) {
672 $this->assertEquals($value, CRM_Utils_Array
::value($field, $result['values']), "In line " . __LINE__
. " error message: " . "missing/mismatching value for {$field}"
677 'email', 'phone', 'address') as $fieldType) {
678 $typeValues = array_pop($result['values'][$fieldType]);
679 foreach ($expected[$fieldType] as $field => $value) {
680 $this->assertEquals($value, CRM_Utils_Array
::value($field, $typeValues), "In line " . __LINE__
. " error message: " . "missing/mismatching value for {$field} ({$fieldType})"
687 * Helper function to create an Individual with address/email/phone info. Import UF Group and UF Fields
689 function _createIndividualContact($params = array()) {
690 $contactParams = array_merge(array(
691 'first_name' => 'abc1',
692 'last_name' => 'xyz1',
693 'email' => 'abc1.xyz1@yahoo.com',
694 'api.address.create' => array(
695 'location_type_id' => 1,
697 'street_address' => '5 Saint Helier St',
699 'country' => 'United States',
700 'state_province' => 'Michigan',
701 'supplemental_address_1' => 'Hallmark Ct',
702 'supplemental_address_2' => 'Jersey Village',
703 'postal_code' => '90210',
704 'city' => 'Gotham City',
707 'api.phone.create' => array(
708 'location_type_id' => '1',
709 'phone' => '021 512 755',
710 'phone_type_id' => '1',
716 $this->_contactID
= $this->individualCreate($contactParams);
717 $this->_createIndividualProfile();
718 // expected result of above created profile with contact Id $contactId
719 $profileData[$this->_contactID
] = array(
720 'first_name' => 'abc1',
721 'last_name' => 'xyz1',
722 'email-primary' => 'abc1.xyz1@yahoo.com',
723 'phone-1-1' => '021 512 755',
724 'country-1' => '1228',
725 'state_province-1' => '1021',
731 function _createContactWithActivity() {
732 // @TODO: Create profile with custom fields
733 $op = new PHPUnit_Extensions_Database_Operation_Insert();
734 $op->execute($this->_dbconn
,
735 new PHPUnit_Extensions_Database_DataSet_FlatXMLDataSet(
736 dirname(__FILE__
) . '/dataset/uf_group_contact_activity_26.xml'
739 // hack: xml data set do not accept \ 1 (CRM_Core_DAO::VALUE_SEPARATOR)
740 CRM_Core_DAO
::setFieldValue('CRM_Core_DAO_UFGroup', '26', 'group_type', 'Individual,Contact,Activity' . CRM_Core_DAO
::VALUE_SEPARATOR
. 'ActivityType:1');
742 $sourceContactId = $this->individualCreate();
743 $contactParams = array(
744 'first_name' => 'abc1',
745 'last_name' => 'xyz1',
746 'contact_type' => 'Individual',
747 'email' => 'abc1.xyz1@yahoo.com',
748 'api.address.create' => array(
749 'location_type_id' => 1,
751 'name' => 'Saint Helier St',
753 'country' => 'United States',
754 'state_province' => 'Michigan',
755 'supplemental_address_1' => 'Hallmark Ct',
756 'supplemental_address_2' => 'Jersey Village',
760 $contact = $this->callAPISuccess('contact', 'create', $contactParams);
762 $keys = array_keys($contact['values']);
763 $contactId = array_pop($keys);
765 $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'])
768 $activityParams = array(
769 'source_contact_id' => $sourceContactId,
770 'assignee_contact_id' => $contactId,
771 'activity_type_id' => '1',
772 'subject' => 'Make-it-Happen Meeting',
773 'activity_date_time' => '20110316',
775 'location' => 'Pensulvania',
776 'details' => 'a test activity',
778 'priority_id' => '1',
780 $activity = $this->callAPISuccess('activity', 'create', $activityParams);
782 $activityValues = array_pop($activity['values']);
784 // valid parameters for above profile
785 $profileParams = array(
787 'contact_id' => $contactId,
788 'activity_id' => $activityValues['id'],
791 // expected result of above created profile
793 'first_name' => 'abc1',
794 'last_name' => 'xyz1',
795 'email-Primary' => 'abc1.xyz1@yahoo.com',
796 'activity_subject' => 'Make-it-Happen Meeting',
797 'activity_details' => 'a test activity',
798 'activity_duration' => '120',
799 'activity_date_time_time' => '12:00AM',
800 'activity_date_time' => '03/16/2011',
801 'activity_status_id' => '1',
804 return array($profileParams, $expected);
809 function _createIndividualProfile() {
811 // creating these via the api as we want to utilise & test the flushing of caches when fields created
814 $ufGroupParams = array(
815 'group_type' => 'Individual,Contact',// really we should remove this & test the ufField create sets it
816 'name' => 'test_individual_contact_profile',
817 'title' => 'Flat Coffee',
818 'api.uf_field.create' => array(
820 'field_name' => 'first_name',
822 'visibility' => 'Public Pages and Listings',
823 'field_type' => 'Individual',
824 'label' => 'First Name',
827 'field_name' => 'last_name',
829 'visibility' => 'Public Pages and Listings',
830 'field_type' => 'Individual',
831 'label' => 'Last Name',
834 'field_name' => 'email',
836 'visibility' => 'Public Pages and Listings',
837 'field_type' => 'Contact',
841 'field_name' => 'phone',
843 'visibility' => 'Public Pages and Listings',
844 'field_type' => 'Contact',
845 'location_type_id' => 1,
846 'phone_type_id' => 1,
850 'field_name' => 'country',
852 'visibility' => 'Public Pages and Listings',
853 'field_type' => 'Contact',
854 'location_type_id' => 1,
858 'field_name' => 'state_province',
860 'visibility' => 'Public Pages and Listings',
861 'field_type' => 'Contact',
862 'location_type_id' => 1,
863 'label' => 'State Province'
866 'field_name' => 'postal_code',
868 'field_type' => 'Contact',
869 'location_type_id' => 1,
870 'label' => 'State Province'
874 $profile = $this->callAPISuccess('uf_group', 'create', $ufGroupParams);
875 $this->_profileID
= $profile['id'];
878 function _addCustomFieldToProfile($profileID) {
879 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, '');
880 $this->uFFieldCreate(array('uf_group_id' => $profileID, 'field_name' => 'custom_' . $ids['custom_field_id'], 'contact_type' => 'Contact'));