3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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 * Test APIv3 civicrm_profile_* functions
34 class api_v3_ProfileTest
extends CiviUnitTestCase
{
35 protected $_apiversion;
36 protected $_profileID = 0;
37 protected $_membershipTypeID;
38 protected $_contactID;
40 public function setUp() {
41 $this->_apiversion
= 3;
43 $config = CRM_Core_Config
::singleton();
44 $countryLimit = $config->countryLimit
;
45 $countryLimit[1] = 1013;
46 $config->countryLimit
= $countryLimit;
48 $this->createLoggedInUser();
49 $this->_membershipTypeID
= $this->membershipTypeCreate();
52 public function tearDown() {
54 $this->quickCleanup(array(
59 'civicrm_contribution',
62 $this->callAPISuccess('membership_type', 'delete', array('id' => $this->_membershipTypeID
));
63 // ok can't be bothered wring an api to do this & truncating is crazy
64 CRM_Core_DAO
::executeQuery(" DELETE FROM civicrm_uf_group WHERE id IN ($this->_profileID, 26)");
68 * Check Without ProfileId.
70 public function testProfileGetWithoutProfileId() {
71 $this->callAPIFailure('profile', 'get', array('contact_id' => 1),
72 'Mandatory key(s) missing from params array: profile_id'
77 * Check with no invalid profile Id.
79 public function testProfileGetInvalidProfileId() {
80 $this->callAPIFailure('profile', 'get', array('contact_id' => 1, 'profile_id' => 1000));
86 public function testProfileGet() {
87 $profileFieldValues = $this->_createIndividualContact();
88 $expected = reset($profileFieldValues);
89 $contactId = key($profileFieldValues);
91 'profile_id' => $this->_profileID
,
92 'contact_id' => $contactId,
94 $result = $this->callAPISuccess('profile', 'get', $params);
95 foreach ($expected as $profileField => $value) {
96 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $result['values']));
100 public function testProfileGetMultiple() {
101 $profileFieldValues = $this->_createIndividualContact();
102 $expected = reset($profileFieldValues);
103 $contactId = key($profileFieldValues);
105 'profile_id' => array($this->_profileID
, 1, 'Billing'),
106 'contact_id' => $contactId,
109 $result = $this->callAPIAndDocument('profile', 'get', $params, __FUNCTION__
, __FILE__
);
110 foreach ($expected as $profileField => $value) {
111 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $result['values'][$this->_profileID
]), " error message: " . "missing/mismatching value for {$profileField}");
113 $this->assertEquals('abc1', $result['values'][1]['first_name'], " error message: " . "missing/mismatching value for {$profileField}");
114 $this->assertFalse(array_key_exists('email-Primary', $result['values'][1]), 'profile 1 doesn not include email');
115 $this->assertEquals($result['values']['Billing'], array(
116 'billing_first_name' => 'abc1',
117 'billing_middle_name' => 'J.',
118 'billing_last_name' => 'xyz1',
119 'billing_street_address-5' => '5 Saint Helier St',
120 'billing_city-5' => 'Gotham City',
121 'billing_state_province_id-5' => '1021',
122 'billing_country_id-5' => '1228',
123 'billing_postal_code-5' => '90210',
124 'billing-email-5' => 'abc1.xyz1@yahoo.com',
125 'email-5' => 'abc1.xyz1@yahoo.com',
129 public function testProfileGetBillingUseIsBillingLocation() {
130 $individual = $this->_createIndividualContact();
131 $contactId = key($individual);
132 $this->callAPISuccess('address', 'create', array(
134 'street_address' => 'is billing st',
135 'location_type_id' => 2,
136 'contact_id' => $contactId,
140 'profile_id' => array($this->_profileID
, 1, 'Billing'),
141 'contact_id' => $contactId,
144 $result = $this->callAPISuccess('profile', 'get', $params);
145 $this->assertEquals('abc1', $result['values'][1]['first_name']);
146 $this->assertEquals(array(
147 'billing_first_name' => 'abc1',
148 'billing_middle_name' => 'J.',
149 'billing_last_name' => 'xyz1',
150 'billing_street_address-5' => 'is billing st',
151 'billing_city-5' => '',
152 'billing_state_province_id-5' => '',
153 'billing_country_id-5' => '',
154 'billing-email-5' => 'abc1.xyz1@yahoo.com',
155 'email-5' => 'abc1.xyz1@yahoo.com',
156 'billing_postal_code-5' => '',
157 ), $result['values']['Billing']);
160 public function testProfileGetMultipleHasBillingLocation() {
161 $individual = $this->_createIndividualContact();
162 $contactId = key($individual);
163 $this->callAPISuccess('address', 'create', array(
164 'contact_id' => $contactId,
165 'street_address' => '25 Big Street',
166 'city' => 'big city',
167 'location_type_id' => 5,
169 $this->callAPISuccess('email', 'create', array(
170 'contact_id' => $contactId,
171 'email' => 'big@once.com',
172 'location_type_id' => 2,
177 'profile_id' => array($this->_profileID
, 1, 'Billing'),
178 'contact_id' => $contactId,
181 $result = $this->callAPISuccess('profile', 'get', $params);
182 $this->assertEquals('abc1', $result['values'][1]['first_name']);
183 $this->assertEquals($result['values']['Billing'], array(
184 'billing_first_name' => 'abc1',
185 'billing_middle_name' => 'J.',
186 'billing_last_name' => 'xyz1',
187 'billing_street_address-5' => '25 Big Street',
188 'billing_city-5' => 'big city',
189 'billing_state_province_id-5' => '',
190 'billing_country_id-5' => '',
191 'billing-email-5' => 'big@once.com',
192 'email-5' => 'big@once.com',
193 'billing_postal_code-5' => '',
198 * Get Billing empty contact - this will return generic defaults
200 public function testProfileGetBillingEmptyContact() {
201 $this->callAPISuccess('Setting', 'create', ['defaultContactCountry' => 1228]);
203 'profile_id' => array('Billing'),
206 $result = $this->callAPISuccess('profile', 'get', $params);
207 $this->assertEquals(array(
208 'billing_first_name' => '',
209 'billing_middle_name' => '',
210 'billing_last_name' => '',
211 'billing_street_address-5' => '',
212 'billing_city-5' => '',
213 'billing_state_province_id-5' => '',
214 'billing_country_id-5' => '1228',
215 'billing_email-5' => '',
217 'billing_postal_code-5' => '',
218 ), $result['values']['Billing']);
222 * Check contact activity profile without activity id.
224 public function testContactActivityGetWithoutActivityId() {
225 list($params) = $this->_createContactWithActivity();
227 unset($params['activity_id']);
228 $this->callAPIFailure('profile', 'get', $params, 'Mandatory key(s) missing from params array: activity_id');
232 * Check contact activity profile wrong activity id.
234 public function testContactActivityGetWrongActivityId() {
235 list($params) = $this->_createContactWithActivity();
236 $params['activity_id'] = 100001;
237 $this->callAPIFailure('profile', 'get', $params, 'Invalid Activity Id (aid).');
241 * Check contact activity profile with wrong activity type.
243 public function testContactActivityGetWrongActivityType() {
244 //flush cache by calling with reset
245 $activityTypes = CRM_Core_PseudoConstant
::activityType(TRUE, TRUE, TRUE, 'name', TRUE);
247 $sourceContactId = $this->householdCreate();
249 $activityparams = array(
250 'source_contact_id' => $sourceContactId,
251 'activity_type_id' => '2',
252 'subject' => 'Test activity',
253 'activity_date_time' => '20110316',
255 'location' => 'Pensulvania',
256 'details' => 'a test activity',
258 'priority_id' => '1',
261 $activity = $this->callAPISuccess('activity', 'create', $activityparams);
263 $activityValues = array_pop($activity['values']);
265 list($params) = $this->_createContactWithActivity();
267 $params['activity_id'] = $activityValues['id'];
268 $this->callAPIFailure('profile', 'get', $params, 'This activity cannot be edited or viewed via this profile.');
272 * Check contact activity profile with success.
274 public function testContactActivityGetSuccess() {
275 list($params, $expected) = $this->_createContactWithActivity();
277 $result = $this->callAPISuccess('profile', 'get', $params);
279 foreach ($expected as $profileField => $value) {
280 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $result['values']), " error message: " . "missing/mismatching value for {$profileField}"
286 * Check getfields works & gives us our fields
288 public function testGetFields() {
289 $this->_createIndividualProfile();
290 $this->_addCustomFieldToProfile($this->_profileID
);
291 $result = $this->callAPIAndDocument('profile', 'getfields', array(
292 'action' => 'submit',
293 'profile_id' => $this->_profileID
,
294 ), __FUNCTION__
, __FILE__
,
295 'demonstrates retrieving profile fields passing in an id');
296 $this->assertArrayKeyExists('first_name', $result['values']);
297 $this->assertEquals('2', $result['values']['first_name']['type']);
298 $this->assertEquals('Email', $result['values']['email-primary']['title']);
299 $this->assertEquals('civicrm_state_province', $result['values']['state_province-1']['pseudoconstant']['table']);
300 $this->assertEquals('defaultValue', $result['values']['custom_1']['default_value']);
301 $this->assertFalse(array_key_exists('participant_status', $result['values']));
305 * Check getfields works & gives us our fields - partipant profile
307 public function testGetFieldsParticipantProfile() {
308 $result = $this->callAPISuccess('profile', 'getfields', array(
309 'action' => 'submit',
310 'profile_id' => 'participant_status',
311 'get_options' => 'all',
314 $this->assertTrue(array_key_exists('participant_status_id', $result['values']));
315 $this->assertEquals('Attended', $result['values']['participant_status_id']['options'][2]);
316 $this->assertEquals(array('participant_status'), $result['values']['participant_status_id']['api.aliases']);
320 * Check getfields works & gives us our fields - membership_batch_entry
321 * (getting to the end with no e-notices is pretty good evidence it's working)
323 public function testGetFieldsMembershipBatchProfile() {
324 $result = $this->callAPISuccess('profile', 'getfields', array(
325 'action' => 'submit',
326 'profile_id' => 'membership_batch_entry',
327 'get_options' => 'all',
330 $this->assertTrue(array_key_exists('total_amount', $result['values']));
331 $this->assertTrue(array_key_exists('financial_type_id', $result['values']));
332 $this->assertEquals(array(
333 'contribution_type_id',
336 ), $result['values']['financial_type_id']['api.aliases']);
337 $this->assertTrue(!array_key_exists('financial_type', $result['values']));
338 $this->assertEquals(12, $result['values']['receive_date']['type']);
342 * Check getfields works & gives us our fields - do them all
343 * (getting to the end with no e-notices is pretty good evidence it's working)
345 public function testGetFieldsAllProfiles() {
346 $result = $this->callAPISuccess('uf_group', 'get', array('return' => 'id'));
347 $profileIDs = array_keys($result['values']);
348 foreach ($profileIDs as $profileID) {
349 $this->callAPISuccess('profile', 'getfields', array(
350 'action' => 'submit',
351 'profile_id' => $profileID,
352 'get_options' => 'all',
359 * Check Without ProfileId.
361 public function testProfileSubmitWithoutProfileId() {
365 $this->callAPIFailure('profile', 'submit', $params,
366 'Mandatory key(s) missing from params array: profile_id'
371 * Check with no invalid profile Id.
373 public function testProfileSubmitInvalidProfileId() {
376 'profile_id' => 1000,
378 $result = $this->callAPIFailure('profile', 'submit', $params);
382 * Check with missing required field in profile.
384 public function testProfileSubmitCheckProfileRequired() {
385 $profileFieldValues = $this->_createIndividualContact();
386 $contactId = key($profileFieldValues);
387 $updateParams = array(
388 'first_name' => 'abc2',
389 'last_name' => 'xyz2',
390 'phone-1-1' => '022 321 826',
391 'country-1' => '1013',
392 'state_province-1' => '1000',
395 $params = array_merge(array('profile_id' => $this->_profileID
, 'contact_id' => $contactId),
399 $this->callAPIFailure('profile', 'submit', $params,
400 "Mandatory key(s) missing from params array: email-primary"
405 * Check with success.
407 public function testProfileSubmit() {
408 $profileFieldValues = $this->_createIndividualContact();
409 $contactId = key($profileFieldValues);
411 $updateParams = array(
412 'first_name' => 'abc2',
413 'last_name' => 'xyz2',
414 'email-primary' => 'abc2.xyz2@gmail.com',
415 'phone-1-1' => '022 321 826',
416 'country-1' => '1013',
417 'state_province-1' => '1000',
420 $params = array_merge(array(
421 'profile_id' => $this->_profileID
,
422 'contact_id' => $contactId,
425 $this->callAPIAndDocument('profile', 'submit', $params, __FUNCTION__
, __FILE__
);
428 'profile_id' => $this->_profileID
,
429 'contact_id' => $contactId,
431 $profileDetails = $this->callAPISuccess('profile', 'get', $getParams);
433 foreach ($updateParams as $profileField => $value) {
434 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $profileDetails['values']), "missing/mismatching value for {$profileField}"
437 unset($params['email-primary']);
438 $params['email-Primary'] = 'my@mail.com';
439 $this->callAPISuccess('profile', 'submit', $params);
440 $profileDetails = $this->callAPISuccess('profile', 'get', $getParams);
441 $this->assertEquals('my@mail.com', $profileDetails['values']['email-Primary']);
445 * Ensure caches are being cleared so we don't get into a debugging trap because of cached metadata
446 * First we delete & create to increment the version & then check for caching probs
448 public function testProfileSubmitCheckCaching() {
449 $this->callAPISuccess('membership_type', 'delete', array('id' => $this->_membershipTypeID
));
450 $this->_membershipTypeID
= $this->membershipTypeCreate();
452 $membershipTypes = $this->callAPISuccess('membership_type', 'get', array());
453 $profileFields = $this->callAPISuccess('profile', 'getfields', array(
454 'get_options' => 'all',
455 'action' => 'submit',
456 'profile_id' => 'membership_batch_entry',
458 $getoptions = $this->callAPISuccess('membership', 'getoptions', array(
459 'field' => 'membership_type',
460 'context' => 'validate',
462 $this->assertEquals(array_keys($membershipTypes['values']), array_keys($getoptions['values']));
463 $this->assertEquals(array_keys($membershipTypes['values']), array_keys($profileFields['values']['membership_type_id']['options']));
468 * Test that the fields are returned in the right order despite the faffing around that goes on.
470 public function testMembershipGetFieldsOrder() {
471 $result = $this->callAPISuccess('profile', 'getfields', array(
472 'action' => 'submit',
473 'profile_id' => 'membership_batch_entry',
476 foreach ($result['values'] as $fieldName => $field) {
477 if ($fieldName == 'profile_id') {
480 $this->assertEquals($field['weight'], $weight);
486 * Check we can submit membership batch profiles (create mode)
488 public function testProfileSubmitMembershipBatch() {
489 $this->_contactID
= $this->individualCreate();
490 $this->callAPISuccess('profile', 'submit', array(
491 'profile_id' => 'membership_batch_entry',
492 'financial_type_id' => 1,
493 'membership_type' => $this->_membershipTypeID
,
494 'join_date' => 'now',
495 'total_amount' => 10,
496 'contribution_status_id' => 1,
497 'receive_date' => 'now',
498 'contact_id' => $this->_contactID
,
503 * Set is deprecated but we need to ensure it still works.
505 public function testLegacySet() {
506 $profileFieldValues = $this->_createIndividualContact();
507 $contactId = key($profileFieldValues);
509 $updateParams = array(
510 'first_name' => 'abc2',
511 'last_name' => 'xyz2',
512 'email-Primary' => 'abc2.xyz2@gmail.com',
513 'phone-1-1' => '022 321 826',
514 'country-1' => '1013',
515 'state_province-1' => '1000',
518 $params = array_merge(array(
519 'profile_id' => $this->_profileID
,
520 'contact_id' => $contactId,
523 $result = $this->callAPISuccess('profile', 'set', $params);
524 $this->assertArrayKeyExists('values', $result);
526 'profile_id' => $this->_profileID
,
527 'contact_id' => $contactId,
529 $profileDetails = $this->callAPISuccess('profile', 'get', $getParams);
531 foreach ($updateParams as $profileField => $value) {
532 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $profileDetails['values']), "In line " . __LINE__
. " error message: " . "missing/mismatching value for {$profileField}"
538 * Check contact activity profile without activity id.
540 public function testContactActivitySubmitWithoutActivityId() {
541 list($params, $expected) = $this->_createContactWithActivity();
543 $params = array_merge($params, $expected);
544 unset($params['activity_id']);
545 $result = $this->callAPIFailure('profile', 'submit', $params);
546 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: activity_id');
550 * Check contact activity profile wrong activity id.
552 public function testContactActivitySubmitWrongActivityId() {
553 list($params, $expected) = $this->_createContactWithActivity();
554 $params = array_merge($params, $expected);
555 $params['activity_id'] = 100001;
556 $result = $this->callAPIFailure('profile', 'submit', $params);
557 $this->assertEquals($result['error_message'], 'Invalid Activity Id (aid).');
561 * Check contact activity profile with wrong activity type.
563 public function testContactActivitySubmitWrongActivityType() {
564 //flush cache by calling with reset
565 CRM_Core_PseudoConstant
::activityType(TRUE, TRUE, TRUE, 'name', TRUE);
567 $sourceContactId = $this->householdCreate();
569 $activityparams = array(
570 'source_contact_id' => $sourceContactId,
571 'activity_type_id' => '2',
572 'subject' => 'Test activity',
573 'activity_date_time' => '20110316',
575 'location' => 'Pensulvania',
576 'details' => 'a test activity',
578 'priority_id' => '1',
581 $activity = $this->callAPISuccess('activity', 'create', $activityparams);
583 $activityValues = array_pop($activity['values']);
585 list($params, $expected) = $this->_createContactWithActivity();
587 $params = array_merge($params, $expected);
588 $params['activity_id'] = $activityValues['id'];
589 $this->callAPIFailure('profile', 'submit', $params,
590 'This activity cannot be edited or viewed via this profile.');
594 * Check contact activity profile with success.
596 public function testContactActivitySubmitSuccess() {
597 list($params) = $this->_createContactWithActivity();
599 $updateParams = array(
600 'first_name' => 'abc2',
601 'last_name' => 'xyz2',
602 'email-Primary' => 'abc2.xyz2@yahoo.com',
603 'activity_subject' => 'Test Meeting',
604 'activity_details' => 'a test activity details',
605 'activity_duration' => '100',
606 'activity_date_time' => '2010-03-08 00:00:00',
607 'activity_status_id' => '2',
609 $profileParams = array_merge($params, $updateParams);
610 $this->callAPISuccess('profile', 'submit', $profileParams);
611 $result = $this->callAPISuccess('profile', 'get', $params);
613 foreach ($updateParams as $profileField => $value) {
614 $this->assertEquals($value, CRM_Utils_Array
::value($profileField, $result['values']), " error message: " . "missing/mismatching value for {$profileField}"
620 * Check profile apply Without ProfileId.
622 public function testProfileApplyWithoutProfileId() {
626 $this->callAPIFailure('profile', 'apply', $params,
627 'Mandatory key(s) missing from params array: profile_id');
631 * Check profile apply with no invalid profile Id.
633 public function testProfileApplyInvalidProfileId() {
636 'profile_id' => 1000,
638 $this->callAPIFailure('profile', 'apply', $params);
642 * Check with success.
644 public function testProfileApply() {
645 $profileFieldValues = $this->_createIndividualContact();
646 current($profileFieldValues);
647 $contactId = key($profileFieldValues);
650 'profile_id' => $this->_profileID
,
651 'contact_id' => $contactId,
652 'first_name' => 'abc2',
653 'last_name' => 'xyz2',
654 'email-Primary' => 'abc2.xyz2@gmail.com',
655 'phone-1-1' => '022 321 826',
656 'country-1' => '1013',
657 'state_province-1' => '1000',
660 $result = $this->callAPIAndDocument('profile', 'apply', $params, __FUNCTION__
, __FILE__
);
662 // Expected field values
663 $expected['contact'] = array(
664 'contact_id' => $contactId,
665 'contact_type' => 'Individual',
666 'first_name' => 'abc2',
667 'last_name' => 'xyz2',
669 $expected['email'] = array(
670 'location_type_id' => 1,
672 'email' => 'abc2.xyz2@gmail.com',
675 $expected['phone'] = array(
676 'location_type_id' => 1,
678 'phone_type_id' => 1,
679 'phone' => '022 321 826',
681 $expected['address'] = array(
682 'location_type_id' => 1,
684 'country_id' => 1013,
685 'state_province_id' => 1000,
688 foreach ($expected['contact'] as $field => $value) {
689 $this->assertEquals($value, CRM_Utils_Array
::value($field, $result['values']), "In line " . __LINE__
. " error message: " . "missing/mismatching value for {$field}"
698 $typeValues = array_pop($result['values'][$fieldType]);
699 foreach ($expected[$fieldType] as $field => $value) {
700 $this->assertEquals($value, CRM_Utils_Array
::value($field, $typeValues), "In line " . __LINE__
. " error message: " . "missing/mismatching value for {$field} ({$fieldType})"
707 * Check success with tags.
709 public function testSubmitWithTags() {
710 $profileFieldValues = $this->_createIndividualContact();
711 $params = reset($profileFieldValues);
712 $contactId = key($profileFieldValues);
713 $params['profile_id'] = $this->_profileID
;
714 $params['contact_id'] = $contactId;
716 $this->callAPISuccess('ufField', 'create', array(
717 'uf_group_id' => $this->_profileID
,
718 'field_name' => 'tag',
719 'visibility' => 'Public Pages and Listings',
720 'field_type' => 'Contact',
724 $tag_1 = $this->callAPISuccess('tag', 'create', ['name' => 'abc'])['id'];
725 $tag_2 = $this->callAPISuccess('tag', 'create', ['name' => 'def'])['id'];
727 $params['tag'] = "$tag_1,$tag_2";
728 $result = $this->callAPISuccess('profile', 'submit', $params);
730 $tags = $this->callAPISuccess('entityTag', 'get', ['entity_id' => $contactId]);
731 $this->assertEquals(2, $tags['count']);
733 $params['tag'] = [$tag_1];
734 $result = $this->callAPISuccess('profile', 'submit', $params);
736 $tags = $this->callAPISuccess('entityTag', 'get', ['entity_id' => $contactId]);
737 $this->assertEquals(1, $tags['count']);
740 $result = $this->callAPISuccess('profile', 'submit', $params);
742 $tags = $this->callAPISuccess('entityTag', 'get', ['entity_id' => $contactId]);
743 $this->assertEquals(0, $tags['count']);
748 * Check success with a note.
750 public function testSubmitWithNote() {
751 $profileFieldValues = $this->_createIndividualContact();
752 $params = reset($profileFieldValues);
753 $contactId = key($profileFieldValues);
754 $params['profile_id'] = $this->_profileID
;
755 $params['contact_id'] = $contactId;
757 $this->callAPISuccess('ufField', 'create', array(
758 'uf_group_id' => $this->_profileID
,
759 'field_name' => 'note',
760 'visibility' => 'Public Pages and Listings',
761 'field_type' => 'Contact',
765 $params['note'] = "Hello 123";
766 $this->callAPISuccess('profile', 'submit', $params);
768 $note = $this->callAPISuccessGetSingle('note', ['entity_id' => $contactId]);
769 $this->assertEquals("Hello 123", $note['note']);
773 * Check handling a custom greeting.
775 public function testSubmitGreetingFields() {
776 $profileFieldValues = $this->_createIndividualContact();
777 $params = reset($profileFieldValues);
778 $contactId = key($profileFieldValues);
779 $params['profile_id'] = $this->_profileID
;
780 $params['contact_id'] = $contactId;
782 $this->callAPISuccess('ufField', 'create', array(
783 'uf_group_id' => $this->_profileID
,
784 'field_name' => 'email_greeting',
785 'visibility' => 'Public Pages and Listings',
786 'field_type' => 'Contact',
787 'label' => 'Email Greeting',
790 $emailGreetings = array_column(civicrm_api3('OptionValue', 'get', ['option_group_id' => "email_greeting"])['values'], NULL, 'name');
792 $params['email_greeting'] = $emailGreetings['Customized']['value'];
793 // Custom greeting should be required
794 $this->callAPIFailure('profile', 'submit', $params);
796 $params['email_greeting_custom'] = 'Hello fool!';
797 $this->callAPISuccess('profile', 'submit', $params);
799 // Api3 will not return custom greeting field so resorting to this
800 $greeting = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $contactId, 'email_greeting_custom');
802 $this->assertEquals("Hello fool!", $greeting);
806 * Helper function to create an Individual with address/email/phone info. Import UF Group and UF Fields
807 * @param array $params
811 public function _createIndividualContact($params = array()) {
812 $contactParams = array_merge(array(
813 'first_name' => 'abc1',
814 'last_name' => 'xyz1',
815 'email' => 'abc1.xyz1@yahoo.com',
816 'api.address.create' => array(
817 'location_type_id' => 1,
819 'street_address' => '5 Saint Helier St',
821 'country' => 'UNITED STATES',
822 'state_province' => 'Michigan',
823 'supplemental_address_1' => 'Hallmark Ct',
824 'supplemental_address_2' => 'Jersey Village',
825 'supplemental_address_3' => 'My Town',
826 'postal_code' => '90210',
827 'city' => 'Gotham City',
830 'api.phone.create' => array(
831 'location_type_id' => '1',
832 'phone' => '021 512 755',
833 'phone_type_id' => '1',
839 $this->_contactID
= $this->individualCreate($contactParams);
840 $this->_createIndividualProfile();
841 // expected result of above created profile with contact Id $contactId
842 $profileData[$this->_contactID
] = array(
843 'first_name' => 'abc1',
844 'last_name' => 'xyz1',
845 'email-primary' => 'abc1.xyz1@yahoo.com',
846 'phone-1-1' => '021 512 755',
847 'country-1' => '1228',
848 'state_province-1' => '1021',
857 public function _createContactWithActivity() {
858 // @TODO: Create profile with custom fields
859 $op = new PHPUnit_Extensions_Database_Operation_Insert();
860 $op->execute($this->_dbconn
,
861 $this->createFlatXMLDataSet(
862 dirname(__FILE__
) . '/dataset/uf_group_contact_activity_26.xml'
865 // hack: xml data set do not accept \ 1 (CRM_Core_DAO::VALUE_SEPARATOR)
866 CRM_Core_DAO
::setFieldValue('CRM_Core_DAO_UFGroup', '26', 'group_type', 'Individual,Contact,Activity' . CRM_Core_DAO
::VALUE_SEPARATOR
. 'ActivityType:1');
868 $sourceContactId = $this->individualCreate();
869 $contactParams = array(
870 'first_name' => 'abc1',
871 'last_name' => 'xyz1',
872 'contact_type' => 'Individual',
873 'email' => 'abc1.xyz1@yahoo.com',
874 'api.address.create' => array(
875 'location_type_id' => 1,
877 'name' => 'Saint Helier St',
879 'country' => 'UNITED STATES',
880 'state_province' => 'Michigan',
881 'supplemental_address_1' => 'Hallmark Ct',
882 'supplemental_address_2' => 'Jersey Village',
883 'supplemental_address_3' => 'My Town',
887 $contact = $this->callAPISuccess('contact', 'create', $contactParams);
889 $keys = array_keys($contact['values']);
890 $contactId = array_pop($keys);
892 $this->assertEquals(0, $contact['values'][$contactId]['api.address.create']['is_error'], " error message: " . CRM_Utils_Array
::value('error_message', $contact['values'][$contactId]['api.address.create'])
895 $activityParams = array(
896 'source_contact_id' => $sourceContactId,
897 'assignee_contact_id' => $contactId,
898 'activity_type_id' => '1',
899 'subject' => 'Make-it-Happen Meeting',
900 'activity_date_time' => '2011-03-16 00:00:00',
902 'location' => 'Pensulvania',
903 'details' => 'a test activity',
905 'priority_id' => '1',
907 $activity = $this->callAPISuccess('activity', 'create', $activityParams);
909 $activityValues = array_pop($activity['values']);
911 // valid parameters for above profile
912 $profileParams = array(
914 'contact_id' => $contactId,
915 'activity_id' => $activityValues['id'],
918 // expected result of above created profile
920 'first_name' => 'abc1',
921 'last_name' => 'xyz1',
922 'email-Primary' => 'abc1.xyz1@yahoo.com',
923 'activity_subject' => 'Make-it-Happen Meeting',
924 'activity_details' => 'a test activity',
925 'activity_duration' => '120',
926 'activity_date_time' => '2011-03-16 00:00:00',
927 'activity_status_id' => '1',
930 return array($profileParams, $expected);
936 public function _createIndividualProfile() {
937 $ufGroupParams = array(
938 'group_type' => 'Individual,Contact',
939 // really we should remove this & test the ufField create sets it
940 'name' => 'test_individual_contact_profile',
941 'title' => 'Flat Coffee',
942 'api.uf_field.create' => array(
944 'field_name' => 'first_name',
946 'visibility' => 'Public Pages and Listings',
947 'field_type' => 'Individual',
948 'label' => 'First Name',
951 'field_name' => 'last_name',
953 'visibility' => 'Public Pages and Listings',
954 'field_type' => 'Individual',
955 'label' => 'Last Name',
958 'field_name' => 'email',
960 'visibility' => 'Public Pages and Listings',
961 'field_type' => 'Contact',
965 'field_name' => 'phone',
967 'visibility' => 'Public Pages and Listings',
968 'field_type' => 'Contact',
969 'location_type_id' => 1,
970 'phone_type_id' => 1,
974 'field_name' => 'country',
976 'visibility' => 'Public Pages and Listings',
977 'field_type' => 'Contact',
978 'location_type_id' => 1,
979 'label' => 'Country',
982 'field_name' => 'state_province',
984 'visibility' => 'Public Pages and Listings',
985 'field_type' => 'Contact',
986 'location_type_id' => 1,
987 'label' => 'State Province',
990 'field_name' => 'postal_code',
992 'field_type' => 'Contact',
993 'location_type_id' => 1,
994 'label' => 'State Province',
998 $profile = $this->callAPISuccess('uf_group', 'create', $ufGroupParams);
999 $this->_profileID
= $profile['id'];
1003 * @param int $profileID
1005 public function _addCustomFieldToProfile($profileID) {
1006 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, '');
1007 $this->uFFieldCreate(array(
1008 'uf_group_id' => $profileID,
1009 'field_name' => 'custom_' . $ids['custom_field_id'],
1010 'contact_type' => 'Contact',