Merge pull request #16519 from civicrm/5.23
[civicrm-core.git] / tests / phpunit / CRM / Activity / BAO / ActivityTest.php
CommitLineData
6a488035 1<?php
0eea664b 2
aba1cd8b
EM
3/**
4 * Class CRM_Activity_BAO_ActivityTest
acb109b7 5 * @group headless
aba1cd8b 6 */
6a488035 7class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase {
39b959db 8
5123cb11
SL
9 private $allowedContactsACL = [];
10
00be9182 11 public function setUp() {
6a488035 12 parent::setUp();
cbcedb39 13 $this->prepareForACLs();
9099cab3 14 CRM_Core_Config::singleton()->userPermissionClass->permissions = ['view all contacts', 'access CiviCRM'];
1a7f0799 15 $this->setupForSmsTests();
6a488035
TO
16 }
17
cbcedb39 18 /**
19 * Clean up after tests.
20 */
00be9182 21 public function tearDown() {
9099cab3 22 $tablesToTruncate = [
824989b9
AS
23 'civicrm_activity',
24 'civicrm_activity_contact',
25 'civicrm_uf_match',
26 'civicrm_campaign',
27 'civicrm_email',
9099cab3 28 ];
6a488035 29 $this->quickCleanup($tablesToTruncate);
cbcedb39 30 $this->cleanUpAfterACLs();
1a7f0799 31 $this->setupForSmsTests(TRUE);
cbcedb39 32 parent::tearDown();
6a488035
TO
33 }
34
35 /**
fe482240 36 * Test case for create() method.
6a488035 37 */
00be9182 38 public function testCreate() {
f7969dcf 39 $contactId = $this->individualCreate();
6a488035 40
9099cab3 41 $params = [
6a488035
TO
42 'source_contact_id' => $contactId,
43 'subject' => 'Scheduling Meeting',
44 'activity_type_id' => 2,
9099cab3 45 ];
6a488035
TO
46
47 CRM_Activity_BAO_Activity::create($params);
48
49 $activityId = $this->assertDBNotNull('CRM_Activity_DAO_Activity', 'Scheduling Meeting', 'id',
50 'subject', 'Database check for created activity.'
51 );
52
cbcedb39 53 // Now call create() to modify an existing Activity.
9099cab3 54 $params = [
6a488035
TO
55 'id' => $activityId,
56 'source_contact_id' => $contactId,
57 'subject' => 'Scheduling Interview',
58 'activity_type_id' => 3,
9099cab3 59 ];
6a488035
TO
60
61 CRM_Activity_BAO_Activity::create($params);
62
63 $activityTypeId = $this->assertDBNotNull('CRM_Activity_DAO_Activity', 'Scheduling Interview',
64 'activity_type_id',
65 'subject', 'Database check on updated activity record.'
66 );
67 $this->assertEquals($activityTypeId, 3, 'Verify activity type id is 3.');
68
93ac19cd 69 $this->contactDelete($contactId);
6a488035
TO
70 }
71
72 /**
fe482240
EM
73 * Test case for getContactActivity() method.
74 *
75 * getContactActivity() method get activities detail for given target contact id.
6a488035 76 */
00be9182 77 public function testGetContactActivity() {
f7969dcf 78 $contactId = $this->individualCreate();
9099cab3 79 $params = [
6a488035
TO
80 'first_name' => 'liz',
81 'last_name' => 'hurleey',
9099cab3 82 ];
f7969dcf 83 $targetContactId = $this->individualCreate($params);
6a488035 84
9099cab3 85 $params = [
6a488035
TO
86 'source_contact_id' => $contactId,
87 'subject' => 'Scheduling Meeting',
88 'activity_type_id' => 2,
9099cab3 89 'target_contact_id' => [$targetContactId],
6a488035 90 'activity_date_time' => date('Ymd'),
9099cab3 91 ];
6a488035 92
f7969dcf 93 $this->callAPISuccess('Activity', 'create', $params);
6a488035
TO
94
95 $activityId = $this->assertDBNotNull('CRM_Activity_DAO_Activity', 'Scheduling Meeting',
96 'id',
97 'subject', 'Database check for created activity.'
98 );
99
a59cecb1 100 // @todo - remove this deprecated functions
6a488035
TO
101 $activities = CRM_Activity_BAO_Activity::getContactActivity($targetContactId);
102
103 $this->assertEquals($activities[$activityId]['subject'], 'Scheduling Meeting', 'Verify activity subject is correct.');
104
93ac19cd 105 $this->contactDelete($contactId);
106 $this->contactDelete($targetContactId);
6a488035
TO
107 }
108
109 /**
fe482240
EM
110 * Test case for retrieve() method.
111 *
112 * Retrieve($params, $defaults) method return activity detail for given params
6a488035
TO
113 * and set defaults.
114 */
00be9182 115 public function testRetrieve() {
f7969dcf 116 $contactId = $this->individualCreate();
9099cab3 117 $params = [
6a488035
TO
118 'first_name' => 'liz',
119 'last_name' => 'hurleey',
9099cab3 120 ];
f7969dcf 121 $targetContactId = $this->individualCreate($params);
6a488035 122
9099cab3 123 $params = [
6a488035
TO
124 'source_contact_id' => $contactId,
125 'subject' => 'Scheduling Meeting',
126 'activity_type_id' => 2,
9099cab3 127 'target_contact_id' => [$targetContactId],
6a488035 128 'activity_date_time' => date('Ymd'),
9099cab3 129 ];
6a488035
TO
130
131 CRM_Activity_BAO_Activity::create($params);
132
cbcedb39 133 $this->assertDBNotNull('CRM_Activity_DAO_Activity', 'Scheduling Meeting', 'id',
6a488035
TO
134 'subject', 'Database check for created activity.'
135 );
136
cbcedb39 137 $this->assertDBNotNull('CRM_Activity_DAO_ActivityContact', $targetContactId,
f1c7b1f0 138 'id', 'contact_id',
6a488035
TO
139 'Database check for created activity target.'
140 );
141
9099cab3 142 $defaults = [];
6a488035
TO
143 $activity = CRM_Activity_BAO_Activity::retrieve($params, $defaults);
144
145 $this->assertEquals($activity->subject, 'Scheduling Meeting', 'Verify activity subject is correct.');
6a488035 146 $this->assertEquals($activity->activity_type_id, 2, 'Verify activity type id is correct.');
b2e56051 147 $this->assertEquals($defaults['source_contact_id'], $contactId, 'Verify source contact id is correct.');
6a488035
TO
148
149 $this->assertEquals($defaults['subject'], 'Scheduling Meeting', 'Verify activity subject is correct.');
6a488035
TO
150 $this->assertEquals($defaults['activity_type_id'], 2, 'Verify activity type id is correct.');
151
152 $this->assertEquals($defaults['target_contact'][0], $targetContactId, 'Verify target contact id is correct.');
153
93ac19cd 154 $this->contactDelete($contactId);
155 $this->contactDelete($targetContactId);
6a488035
TO
156 }
157
5123cb11
SL
158 /**
159 * Test Assigning a target contact but then the logged in user cannot see the contact
160 */
161 public function testTargetContactNotavaliable() {
162 $contactId = $this->individualCreate();
9099cab3 163 $params = [
5123cb11
SL
164 'first_name' => 'liz',
165 'last_name' => 'hurleey',
9099cab3 166 ];
5123cb11
SL
167 $targetContactId = $this->individualCreate($params);
168
9099cab3 169 $params = [
5123cb11
SL
170 'source_contact_id' => $contactId,
171 'subject' => 'Scheduling Meeting',
172 'activity_type_id' => 2,
9099cab3 173 'target_contact_id' => [$targetContactId],
5123cb11 174 'activity_date_time' => date('Ymd'),
9099cab3 175 ];
5123cb11
SL
176
177 CRM_Activity_BAO_Activity::create($params);
178
179 // set custom hook
9099cab3 180 $this->hookClass->setHook('civicrm_aclWhereClause', [$this, 'hook_civicrm_aclWhereClause']);
5123cb11 181
9099cab3 182 CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM'];
5123cb11 183
9099cab3 184 $this->allowedContactsACL = [$contactId];
5123cb11
SL
185
186 // get logged in user
187 $user_id = $this->createLoggedInUser();
188 $activityGetParams = CRM_Core_Page_AJAX::defaultSortAndPagerParams();
189 $activityGetParams += ['contact_id' => $contactId];
190 $activities = CRM_Activity_BAO_Activity::getContactActivitySelector($activityGetParams);
995f30cc
SL
191 // Aseert that we have sensible data to display in the contact tab
192 $this->assertEquals('Anderson, Anthony', $activities['data'][0]['source_contact_name']);
193 // Note that becasue there is a target contact but it is not accessable the output is an empty string not n/a
194 $this->assertEquals('', $activities['data'][0]['target_contact_name']);
195 // verify that doing the underlying query shows we get a target contact_id
196 $this->assertEquals(1, CRM_Activity_BAO_Activity::getActivities(['contact_id' => $contactId])[1]['target_contact_count']);
05704444 197 $this->cleanUpAfterACLs();
5123cb11
SL
198 }
199
6a488035 200 /**
fe482240
EM
201 * Test case for deleteActivity() method.
202 *
6a488035
TO
203 * deleteActivity($params) method deletes activity for given params.
204 */
00be9182 205 public function testDeleteActivity() {
f7969dcf 206 $contactId = $this->individualCreate();
9099cab3 207 $params = [
6a488035
TO
208 'first_name' => 'liz',
209 'last_name' => 'hurleey',
9099cab3 210 ];
f7969dcf 211 $targetContactId = $this->individualCreate($params);
6a488035 212
9099cab3 213 $params = [
6a488035
TO
214 'source_contact_id' => $contactId,
215 'source_record_id' => $contactId,
216 'subject' => 'Scheduling Meeting',
217 'activity_type_id' => 2,
9099cab3 218 'target_contact_id' => [$targetContactId],
6a488035 219 'activity_date_time' => date('Ymd'),
9099cab3 220 ];
6a488035
TO
221
222 CRM_Activity_BAO_Activity::create($params);
223
cbcedb39 224 $this->assertDBNotNull('CRM_Activity_DAO_Activity', 'Scheduling Meeting', 'id',
6a488035
TO
225 'subject', 'Database check for created activity.'
226 );
227
cbcedb39 228 $this->assertDBNotNull('CRM_Activity_DAO_ActivityContact', $targetContactId,
f1c7b1f0 229 'id', 'contact_id',
6a488035
TO
230 'Database check for created activity target.'
231 );
9099cab3 232 $params = [
6a488035
TO
233 'source_contact_id' => $contactId,
234 'source_record_id' => $contactId,
235 'subject' => 'Scheduling Meeting',
236 'activity_type_id' => 2,
9099cab3 237 ];
6a488035 238
93ac19cd 239 CRM_Activity_BAO_Activity::deleteActivity($params);
6a488035 240
93ac19cd 241 $this->assertDBNull('CRM_Activity_DAO_Activity', 'Scheduling Meeting', 'id',
6a488035
TO
242 'subject', 'Database check for deleted activity.'
243 );
93ac19cd 244 $this->contactDelete($contactId);
245 $this->contactDelete($targetContactId);
6a488035
TO
246 }
247
248 /**
fe482240
EM
249 * Test case for deleteActivityTarget() method.
250 *
6a488035
TO
251 * deleteActivityTarget($activityId) method deletes activity target for given activity id.
252 */
00be9182 253 public function testDeleteActivityTarget() {
f7969dcf 254 $contactId = $this->individualCreate();
9099cab3 255 $params = [
6a488035
TO
256 'first_name' => 'liz',
257 'last_name' => 'hurleey',
9099cab3 258 ];
f7969dcf 259 $targetContactId = $this->individualCreate($params);
6a488035 260
9099cab3 261 $params = [
6a488035
TO
262 'source_contact_id' => $contactId,
263 'subject' => 'Scheduling Meeting',
264 'activity_type_id' => 2,
9099cab3 265 'target_contact_id' => [$targetContactId],
6a488035 266 'activity_date_time' => date('Ymd'),
9099cab3 267 ];
6a488035
TO
268
269 CRM_Activity_BAO_Activity::create($params);
270
271 $activityId = $this->assertDBNotNull('CRM_Activity_DAO_Activity', 'Scheduling Meeting', 'id',
272 'subject', 'Database check for created activity.'
273 );
274
cbcedb39 275 $this->assertDBNotNull('CRM_Activity_DAO_ActivityContact', $targetContactId,
f1c7b1f0 276 'id', 'contact_id',
6a488035
TO
277 'Database check for created activity target.'
278 );
279
2517d079 280 CRM_Activity_BAO_Activity::deleteActivityContact($activityId, 3);
6a488035 281
f1c7b1f0
DL
282 $this->assertDBNull('CRM_Activity_DAO_ActivityContact', $targetContactId, 'id',
283 'contact_id', 'Database check for deleted activity target.'
6a488035
TO
284 );
285
93ac19cd 286 $this->contactDelete($contactId);
287 $this->contactDelete($targetContactId);
6a488035
TO
288 }
289
290 /**
fe482240
EM
291 * Test case for deleteActivityAssignment() method.
292 *
6a488035
TO
293 * deleteActivityAssignment($activityId) method deletes activity assignment for given activity id.
294 */
00be9182 295 public function testDeleteActivityAssignment() {
f7969dcf 296 $contactId = $this->individualCreate();
9099cab3 297 $params = [
6a488035
TO
298 'first_name' => 'liz',
299 'last_name' => 'hurleey',
9099cab3 300 ];
f7969dcf 301 $assigneeContactId = $this->individualCreate($params);
6a488035 302
9099cab3 303 $params = [
6a488035
TO
304 'source_contact_id' => $contactId,
305 'subject' => 'Scheduling Meeting',
306 'activity_type_id' => 2,
9099cab3 307 'assignee_contact_id' => [$assigneeContactId],
6a488035 308 'activity_date_time' => date('Ymd'),
9099cab3 309 ];
6a488035
TO
310
311 CRM_Activity_BAO_Activity::create($params);
312
313 $activityId = $this->assertDBNotNull('CRM_Activity_DAO_Activity', 'Scheduling Meeting', 'id',
314 'subject', 'Database check for created activity.'
315 );
316
cbcedb39 317 $this->assertDBNotNull('CRM_Activity_DAO_ActivityContact',
f1c7b1f0 318 $assigneeContactId, 'id', 'contact_id',
6a488035
TO
319 'Database check for created activity assignment.'
320 );
321
2517d079 322 CRM_Activity_BAO_Activity::deleteActivityContact($activityId, 1);
6a488035 323
f1c7b1f0
DL
324 $this->assertDBNull('CRM_Activity_DAO_ActivityContact', $assigneeContactId, 'id',
325 'contact_id', 'Database check for deleted activity assignment.'
6a488035
TO
326 );
327
93ac19cd 328 $this->contactDelete($contactId);
329 $this->contactDelete($assigneeContactId);
6a488035
TO
330 }
331
332 /**
5161bb0c 333 * Test getActivities BAO method for getting count.
3e120a63 334 *
6a488035 335 */
cbcedb39 336 public function testGetActivitiesCountForAdminDashboard() {
3e120a63
RLAR
337 // Reset to default
338 $this->setShowCaseActivitiesInCore(FALSE);
75d842f8 339 $this->setUpForActivityDashboardTests();
3e120a63
RLAR
340 $this->addCaseWithActivity();
341 CRM_Core_Config::singleton()->userPermissionClass->permissions[] = 'access all cases and activities';
342
6ab43e1b 343 $activityCount = CRM_Activity_BAO_Activity::getActivitiesCount($this->_params);
75d842f8 344 $this->assertEquals(8, $activityCount);
3e120a63
RLAR
345
346 // If we're showing case activities, we exepct to see one more (the scheduled meeting)...
347 $this->setShowCaseActivitiesInCore(TRUE);
348 $activityCount = CRM_Activity_BAO_Activity::getActivitiesCount($this->_params);
349 $this->assertEquals(9, $activityCount);
350 // Reset to default
351 $this->setShowCaseActivitiesInCore(FALSE);
6a488035
TO
352 }
353
354 /**
5161bb0c 355 * Test getActivities BAO method for getting count
3e120a63 356 *
6a488035 357 */
00be9182 358 public function testGetActivitiesCountforNonAdminDashboard() {
3e120a63
RLAR
359 // Reset to default
360 $this->setShowCaseActivitiesInCore(FALSE);
a6c2ebdc 361 $this->createTestActivities();
3e120a63
RLAR
362 $this->addCaseWithActivity();
363 CRM_Core_Config::singleton()->userPermissionClass->permissions[] = 'access all cases and activities';
6a488035 364
9099cab3 365 $params = [
6a488035
TO
366 'contact_id' => 9,
367 'admin' => FALSE,
368 'caseId' => NULL,
369 'context' => 'home',
370 'activity_type_id' => NULL,
39b959db
SL
371 // for dashlet the Scheduled status is set by default
372 'activity_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'status_id', 'Scheduled'),
6a488035
TO
373 'offset' => 0,
374 'rowCount' => 0,
375 'sort' => NULL,
9099cab3 376 ];
6a488035 377
6a488035 378 //since we are loading activities from dataset, we know total number of activities for this contact
3e120a63
RLAR
379 // 5 activities ( 2 scheduled, 3 Completed, 1 Scheduled Case activity ),
380 // note that dashboard shows only scheduled activities
6ab43e1b 381 $this->assertEquals(2, CRM_Activity_BAO_Activity::getActivitiesCount($params));
3e120a63
RLAR
382
383 // If we're showing case activities, we exepct to see one more (the scheduled meeting)...
384 $this->setShowCaseActivitiesInCore(TRUE);
385 $this->assertEquals(3, CRM_Activity_BAO_Activity::getActivitiesCount($params));
386 // Reset to default
387 $this->setShowCaseActivitiesInCore(FALSE);
6a488035
TO
388 }
389
390 /**
5161bb0c 391 * Test getActivities BAO method for getting count
3e120a63 392 *
6a488035 393 */
00be9182 394 public function testGetActivitiesCountforContactSummary() {
3e120a63
RLAR
395 // Reset to default
396 $this->setShowCaseActivitiesInCore(FALSE);
a6c2ebdc 397 $this->createTestActivities();
3e120a63
RLAR
398 $this->addCaseWithActivity();
399 CRM_Core_Config::singleton()->userPermissionClass->permissions[] = 'access all cases and activities';
6a488035 400
9099cab3 401 $params = [
6a488035
TO
402 'contact_id' => 9,
403 'admin' => FALSE,
404 'caseId' => NULL,
405 'context' => 'activity',
406 'activity_type_id' => NULL,
407 'offset' => 0,
408 'rowCount' => 0,
409 'sort' => NULL,
9099cab3 410 ];
6a488035
TO
411
412 //since we are loading activities from dataset, we know total number of activities for this contact
3e120a63 413 // 5 activities
6ab43e1b 414 $this->assertEquals(5, CRM_Activity_BAO_Activity::getActivitiesCount($params));
3e120a63
RLAR
415
416 // If we're showing case activities, we exepct to see one more (the scheduled meeting)...
417 $this->setShowCaseActivitiesInCore(TRUE);
418 $this->assertEquals(6, CRM_Activity_BAO_Activity::getActivitiesCount($params));
419 // Reset to default
420 $this->setShowCaseActivitiesInCore(FALSE);
6a488035
TO
421 }
422
23289ddd 423 /**
424 * CRM-18706 - Test Include/Exclude Activity Filters
425 */
426 public function testActivityFilters() {
a6c2ebdc 427 $this->createTestActivities();
c3a9ccbb
JP
428 Civi::settings()->set('preserve_activity_tab_filter', 1);
429 $this->createLoggedInUser();
23289ddd 430
431 global $_GET;
9099cab3 432 $_GET = [
23289ddd 433 'cid' => 9,
434 'context' => 'activity',
435 'activity_type_id' => 1,
436 'is_unit_test' => 1,
9099cab3
CW
437 ];
438 $expectedFilters = [
c3a9ccbb 439 'activity_type_filter_id' => 1,
9099cab3 440 ];
23289ddd 441
c3a9ccbb
JP
442 list($activities, $activityFilter) = CRM_Activity_Page_AJAX::getContactActivity();
443 //Assert whether filters are correctly set.
444 $this->checkArrayEquals($expectedFilters, $activityFilter);
23289ddd 445 // This should include activities of type Meeting only.
cbcedb39 446 foreach ($activities['data'] as $value) {
8c99c0bb 447 $this->assertContains('Meeting', $value['activity_type']);
23289ddd 448 }
449 unset($_GET['activity_type_id']);
450
c3a9ccbb
JP
451 $_GET['activity_type_exclude_id'] = $expectedFilters['activity_type_exclude_filter_id'] = 1;
452 list($activities, $activityFilter) = CRM_Activity_Page_AJAX::getContactActivity();
c1d3e301 453 $this->assertEquals(['activity_type_exclude_filter_id' => 1], $activityFilter);
23289ddd 454 // None of the activities should be of type Meeting.
cbcedb39 455 foreach ($activities['data'] as $value) {
c3a9ccbb 456 $this->assertNotContains('Meeting', $value['activity_type']);
23289ddd 457 }
458 }
459
6a488035 460 /**
5161bb0c 461 * Test getActivities BAO method for getting count
6a488035 462 */
00be9182 463 public function testGetActivitiesCountforContactSummaryWithNoActivities() {
a6c2ebdc 464 $this->createTestActivities();
6a488035 465
9099cab3 466 $params = [
6a488035
TO
467 'contact_id' => 17,
468 'admin' => FALSE,
469 'caseId' => NULL,
470 'context' => 'home',
471 'activity_type_id' => NULL,
472 'offset' => 0,
473 'rowCount' => 0,
474 'sort' => NULL,
9099cab3 475 ];
6a488035
TO
476
477 //since we are loading activities from dataset, we know total number of activities for this contact
478 // this contact does not have any activity
6ab43e1b 479 $this->assertEquals(0, CRM_Activity_BAO_Activity::getActivitiesCount($params));
6a488035
TO
480 }
481
482 /**
eceb18cc 483 * Test getActivities BAO method.
6a488035 484 */
cbcedb39 485 public function testGetActivitiesForAdminDashboard() {
3e120a63 486 $this->setShowCaseActivitiesInCore(FALSE);
75d842f8 487 $this->setUpForActivityDashboardTests();
3e120a63
RLAR
488 $this->addCaseWithActivity();
489 CRM_Core_Config::singleton()->userPermissionClass->permissions[] = 'access all cases and activities';
490
6ab43e1b 491 $activitiesNew = CRM_Activity_BAO_Activity::getActivities($this->_params);
492 // $this->assertEquals($activities, $activitiesDeprecatedFn);
6a488035
TO
493
494 //since we are loading activities from dataset, we know total number of activities
5161bb0c 495 // with no contact ID and there should be 8 schedule activities shown on dashboard
6a488035 496 $count = 8;
9099cab3 497 foreach ([$activitiesNew] as $activities) {
6ab43e1b 498 $this->assertEquals($count, count($activities));
6a488035 499
6ab43e1b 500 foreach ($activities as $key => $value) {
501 $this->assertEquals($value['subject'], "subject {$key}", 'Verify activity subject is correct.');
502 $this->assertEquals($value['activity_type_id'], 2, 'Verify activity type is correct.');
503 $this->assertEquals($value['status_id'], 1, 'Verify all activities are scheduled.');
504 }
6a488035 505 }
3e120a63
RLAR
506
507 // Now check that we get the scheduled meeting, if civicaseShowCaseActivities is set.
508 $this->setShowCaseActivitiesInCore(TRUE);
509 $activitiesNew = CRM_Activity_BAO_Activity::getActivities($this->_params);
510 $this->assertEquals(9, count($activitiesNew));
511 // Scan through to find the meeting.
512 $this->assertTrue(in_array('test meeting activity', array_column($activitiesNew, 'subject')),
513 "failed to find scheduled case Meeting activity");
514 // Reset to default
515 $this->setShowCaseActivitiesInCore(FALSE);
6a488035
TO
516 }
517
75d842f8 518 /**
519 * Test getActivities BAO method.
520 */
521 public function testGetActivitiesForAdminDashboardNoViewContacts() {
9099cab3 522 CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM'];
75d842f8 523 $this->setUpForActivityDashboardTests();
9099cab3 524 foreach ([CRM_Activity_BAO_Activity::getActivities($this->_params)] as $activities) {
6ab43e1b 525 // Skipped until we get back to the upgraded version properly.
6e793248 526 $this->assertEquals(0, count($activities));
6ab43e1b 527 }
26583d3e 528 }
529
530 /**
531 * Test getActivities BAO method.
532 */
533 public function testGetActivitiesForAdminDashboardAclLimitedViewContacts() {
9099cab3
CW
534 CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM'];
535 $this->allowedContacts = [1, 3, 4, 5];
536 $this->hookClass->setHook('civicrm_aclWhereClause', [$this, 'aclWhereMultipleContacts']);
26583d3e 537 $this->setUpForActivityDashboardTests();
6e793248 538 $this->assertEquals(7, count(CRM_Activity_BAO_Activity::getActivities($this->_params)));
75d842f8 539 }
540
6a488035 541 /**
eceb18cc 542 * Test getActivities BAO method.
6a488035 543 */
00be9182 544 public function testGetActivitiesforNonAdminDashboard() {
3e120a63 545 $this->setShowCaseActivitiesInCore(FALSE);
a6c2ebdc 546 $this->createTestActivities();
3e120a63
RLAR
547 $this->addCaseWithActivity();
548 CRM_Core_Config::singleton()->userPermissionClass->permissions[] = 'access all cases and activities';
6a488035
TO
549
550 $contactID = 9;
9099cab3 551 $params = [
6a488035
TO
552 'contact_id' => $contactID,
553 'admin' => FALSE,
554 'caseId' => NULL,
555 'context' => 'home',
556 'activity_type_id' => NULL,
39b959db
SL
557 // for dashlet the Scheduled status is set by default
558 'activity_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'status_id', 'Scheduled'),
6a488035
TO
559 'offset' => 0,
560 'rowCount' => 0,
561 'sort' => NULL,
9099cab3 562 ];
6a488035 563
9099cab3 564 foreach ([CRM_Activity_BAO_Activity::getActivities($params)] as $activities) {
6ab43e1b 565 //since we are loading activities from dataset, we know total number of activities for this contact
566 // 5 activities ( 2 scheduled, 3 Completed ), note that dashboard shows only scheduled activities
567 $count = 2;
568 $this->assertEquals($count, count($activities));
6a488035 569
6ab43e1b 570 foreach ($activities as $key => $value) {
571 $this->assertEquals($value['subject'], "subject {$key}", 'Verify activity subject is correct.');
572 $this->assertEquals($value['activity_type_id'], 2, 'Verify activity type is correct.');
573 $this->assertEquals($value['status_id'], 1, 'Verify all activities are scheduled.');
6a488035 574
6ab43e1b 575 if ($key == 3) {
576 $this->assertArrayHasKey($contactID, $value['target_contact_name']);
577 }
578 elseif ($key == 4) {
579 $this->assertArrayHasKey($contactID, $value['assignee_contact_name']);
580 }
6a488035
TO
581 }
582 }
3e120a63
RLAR
583
584 // Now check that we get the scheduled meeting, if civicaseShowCaseActivities is set.
585 $this->setShowCaseActivitiesInCore(TRUE);
586 $activities = CRM_Activity_BAO_Activity::getActivities($params);
587 $this->assertEquals(3, count($activities));
588 // Scan through to find the meeting.
589 $this->assertTrue(in_array('test meeting activity', array_column($activities, 'subject')),
590 "failed to find scheduled case Meeting activity");
591
592 // Reset to default
593 $this->setShowCaseActivitiesInCore(FALSE);
6a488035
TO
594 }
595
36d2f4d5 596 /**
597 * Test target contact count.
598 */
599 public function testTargetCountforContactSummary() {
600 $targetCount = 5;
601 $contactId = $this->individualCreate();
9099cab3 602 $targetContactIDs = [];
36d2f4d5 603 for ($i = 0; $i < $targetCount; $i++) {
9099cab3 604 $targetContactIDs[] = $this->individualCreate([], $i);
36d2f4d5 605 }
cbcedb39 606 // Create activities with 5 target contacts.
9099cab3 607 $activityParams = [
36d2f4d5 608 'source_contact_id' => $contactId,
609 'target_contact_id' => $targetContactIDs,
9099cab3 610 ];
36d2f4d5 611 $this->activityCreate($activityParams);
612
9099cab3 613 $params = [
36d2f4d5 614 'contact_id' => $contactId,
615 'context' => 'activity',
9099cab3 616 ];
c2ce41b6 617 $activities = CRM_Activity_BAO_Activity::getActivities($params);
618 //verify target count
619 $this->assertEquals($targetCount, $activities[1]['target_contact_count']);
620 $this->assertEquals([$targetContactIDs[0] => 'Anderson, Anthony'], $activities[1]['target_contact_name']);
621 $this->assertEquals('Anderson, Anthony', $activities[1]['source_contact_name']);
622 $this->assertEquals('Anderson, Anthony', $activities[1]['assignee_contact_name'][4]);
36d2f4d5 623 }
624
a6c2ebdc 625 /**
626 * Test getActivities BAO method.
627 */
628 public function testGetActivitiesforContactSummaryWithSortOptions() {
629 $this->createTestActivities();
630 $params = [
631 'contact_id' => 9,
632 'admin' => FALSE,
633 'caseId' => NULL,
634 'context' => 'activity',
635 'activity_type_id' => NULL,
636 'offset' => 0,
637 'rowCount' => 0,
638 'sort' => 'source_contact_name desc',
639 ];
640
641 $activities = CRM_Activity_BAO_Activity::getActivities($params);
642 $alphaOrder = ['Test Contact 11', 'Test Contact 12', 'Test Contact 3', 'Test Contact 4', 'Test Contact 9'];
643 foreach ($activities as $activity) {
644 $this->assertEquals(array_pop($alphaOrder), $activity['source_contact_name']);
645 }
646
647 }
648
6a488035 649 /**
eceb18cc 650 * Test getActivities BAO method.
6a488035 651 */
c2ce41b6 652 public function testGetActivitiesForContactSummary() {
3e120a63
RLAR
653 // Reset to default
654 $this->setShowCaseActivitiesInCore(FALSE);
a6c2ebdc 655 $this->createTestActivities();
3e120a63
RLAR
656 $this->addCaseWithActivity();
657 CRM_Core_Config::singleton()->userPermissionClass->permissions[] = 'access all cases and activities';
6a488035
TO
658
659 $contactID = 9;
9099cab3 660 $params = [
6a488035
TO
661 'contact_id' => $contactID,
662 'admin' => FALSE,
663 'caseId' => NULL,
664 'context' => 'activity',
665 'activity_type_id' => NULL,
666 'offset' => 0,
667 'rowCount' => 0,
9099cab3 668 ];
6a488035
TO
669
670 //since we are loading activities from dataset, we know total number of activities for this contact
671 // 5 activities, Contact Summary should show all activities
672 $count = 5;
c2ce41b6 673 $activities = CRM_Activity_BAO_Activity::getActivities($params);
674 $this->assertEquals($count, count($activities));
675 foreach ($activities as $key => $value) {
676 $this->assertEquals($value['subject'], "subject {$key}", 'Verify activity subject is correct.');
6a488035 677
c2ce41b6 678 if ($key > 8) {
679 $this->assertEquals($value['status_id'], 2, 'Verify all activities are scheduled.');
680 }
681 else {
682 $this->assertEquals($value['status_id'], 1, 'Verify all activities are scheduled.');
683 }
6a488035 684
c2ce41b6 685 if ($key === 12) {
686 $this->assertEquals($value['activity_type'], 'Bulk Email', 'Verify activity type is correct.');
687 $this->assertEquals('(2 recipients)', $value['recipients']);
688 $targetContactID = key($value['target_contact_name']);
689 // The 2 targets have ids 10 & 11. Since they are not sorted it could be either on some systems.
690 $this->assertTrue(in_array($targetContactID, [10, 11]));
691 }
692 elseif ($key > 8) {
693 $this->assertEquals($value['activity_type_id'], 1, 'Verify activity type is correct.');
694 }
695 else {
696 $this->assertEquals($value['activity_type_id'], 2, 'Verify activity type is correct.');
697 }
6ab43e1b 698
c2ce41b6 699 if ($key == 3) {
700 $this->assertEquals([$contactID => 'Test Contact ' . $contactID], $value['target_contact_name']);
701 }
702 elseif ($key == 4) {
703 $this->assertArrayHasKey($contactID, $value['assignee_contact_name']);
6a488035
TO
704 }
705 }
3e120a63
RLAR
706
707 // Now check that we get the scheduled meeting, if civicaseShowCaseActivities is set.
708 $this->setShowCaseActivitiesInCore(TRUE);
709 $activities = CRM_Activity_BAO_Activity::getActivities($params);
710 $this->assertEquals(6, count($activities));
711 // Scan through to find the meeting.
712 $this->assertTrue(in_array('test meeting activity', array_column($activities, 'subject')),
713 "failed to find scheduled case Meeting activity");
714 // Reset to default
715 $this->setShowCaseActivitiesInCore(FALSE);
6a488035
TO
716 }
717
718 /**
eceb18cc 719 * Test getActivities BAO method.
6a488035 720 */
5161bb0c 721 public function testGetActivitiesforContactSummaryWithActivities() {
3e120a63
RLAR
722 // Reset to default
723 $this->setShowCaseActivitiesInCore(FALSE);
a6c2ebdc 724 $this->createTestActivities();
6a488035 725
6ab43e1b 726 // parameters for different test cases, check each array key for the specific test-case
9099cab3
CW
727 $testCases = [
728 'with-no-activity' => [
729 'params' => [
5161bb0c 730 'contact_id' => 17,
731 'admin' => FALSE,
732 'caseId' => NULL,
733 'context' => 'home',
734 'activity_type_id' => NULL,
735 'offset' => 0,
736 'rowCount' => 0,
737 'sort' => NULL,
9099cab3
CW
738 ],
739 ],
740 'with-activity' => [
741 'params' => [
5161bb0c 742 'contact_id' => 1,
743 'admin' => FALSE,
744 'caseId' => NULL,
745 'context' => 'home',
746 'activity_type_id' => NULL,
747 'offset' => 0,
748 'rowCount' => 0,
749 'sort' => NULL,
9099cab3
CW
750 ],
751 ],
752 'with-activity_type' => [
753 'params' => [
5161bb0c 754 'contact_id' => 3,
755 'admin' => FALSE,
756 'caseId' => NULL,
757 'context' => 'home',
758 'activity_type_id' => 2,
759 'offset' => 0,
760 'rowCount' => 0,
761 'sort' => NULL,
9099cab3
CW
762 ],
763 ],
764 'exclude-all-activity_type' => [
765 'params' => [
5161bb0c 766 'contact_id' => 3,
767 'admin' => FALSE,
768 'caseId' => NULL,
769 'context' => 'home',
9099cab3 770 'activity_type_exclude_id' => [1, 2],
5161bb0c 771 'offset' => 0,
772 'rowCount' => 0,
773 'sort' => NULL,
9099cab3
CW
774 ],
775 ],
776 'sort-by-subject' => [
777 'params' => [
5161bb0c 778 'contact_id' => 1,
779 'admin' => FALSE,
780 'caseId' => NULL,
781 'context' => 'home',
782 'activity_type_id' => NULL,
783 'offset' => 0,
784 'rowCount' => 0,
785 'sort' => 'subject DESC',
9099cab3
CW
786 ],
787 ],
788 ];
5161bb0c 789
790 foreach ($testCases as $caseName => $testCase) {
6e793248 791 $activityCount = CRM_Activity_BAO_Activity::getActivitiesCount($testCase['params']);
6ab43e1b 792 $activitiesNew = CRM_Activity_BAO_Activity::getActivities($testCase['params']);
793
9099cab3 794 foreach ([$activitiesNew] as $activities) {
6ab43e1b 795 //$this->assertEquals($activityCount, CRM_Activity_BAO_Activity::getActivitiesCount($testCase['params']));
796 if ($caseName == 'with-no-activity') {
797 $this->assertEquals(0, count($activities));
798 $this->assertEquals(0, $activityCount);
799 }
800 elseif ($caseName == 'with-activity') {
801 // contact id 1 is assigned as source, target and assignee for activity id 1, 7 and 8 respectively
802 $this->assertEquals(3, count($activities));
803 $this->assertEquals(3, $activityCount);
804 $this->assertEquals(1, $activities[1]['source_contact_id']);
805 // @todo - this is a discrepancy between old & new - review.
806 //$this->assertEquals(TRUE, array_key_exists(1, $activities[7]['target_contact_name']));
807 $this->assertEquals(TRUE, array_key_exists(1, $activities[8]['assignee_contact_name']));
808 }
809 elseif ($caseName == 'with-activity_type') {
810 // contact id 3 for activity type 2 is assigned as assignee, source and target for
811 // activity id 1, 3 and 8 respectively
812 $this->assertEquals(3, count($activities));
813 $this->assertEquals(3, $activityCount);
814 // ensure activity type id is 2
815 $this->assertEquals(2, $activities[1]['activity_type_id']);
816 $this->assertEquals(3, $activities[3]['source_contact_id']);
817 // @todo review inconsistency between 2 versions.
818 // $this->assertEquals(TRUE, array_key_exists(3, $activities[8]['target_contact_name']));
819 $this->assertEquals(TRUE, array_key_exists(3, $activities[1]['assignee_contact_name']));
820 }
821 if ($caseName == 'exclude-all-activity_type') {
822 $this->assertEquals(0, count($activities));
823 $this->assertEquals(0, $activityCount);
824 }
825 if ($caseName == 'sort-by-subject') {
826 $this->assertEquals(3, count($activities));
827 $this->assertEquals(3, $activityCount);
828 // activities should be order by 'subject DESC'
9099cab3 829 $subjectOrder = [
6ab43e1b 830 'subject 8',
831 'subject 7',
832 'subject 1',
9099cab3 833 ];
6ab43e1b 834 $count = 0;
835 foreach ($activities as $activity) {
836 $this->assertEquals($subjectOrder[$count], $activity['subject']);
837 $count++;
838 }
5161bb0c 839 }
840 }
841 }
6a488035 842 }
96025800 843
49d4d222 844 /**
845 * CRM-20793 : Test getActivities by using activity date and status filter
846 */
afc82ed3 847 public function testByActivityDateAndStatus() {
6e793248 848 CRM_Core_Config::singleton()->userPermissionClass->permissions = ['view all contacts', 'access CiviCRM'];
a6c2ebdc 849 $this->createTestActivities();
49d4d222 850
851 // activity IDs catagorised by date
9099cab3
CW
852 $lastWeekActivities = [1, 2, 3];
853 $todayActivities = [4, 5, 6, 7];
854 $lastTwoMonthsActivities = [8, 9, 10, 11];
855 $lastOrNextYearActivities = [12, 13, 14, 15, 16];
49d4d222 856
857 // date values later used to set activity date value
858 $lastWeekDate = date('YmdHis', strtotime('1 week ago'));
859 $today = date('YmdHis');
a6d192c8 860 $lastTwoMonthAgoDate = date('YmdHis', strtotime('2 months ago'));
daff7f26 861 // if current month is Jan then choose next year date otherwise the search result will include
862 // the previous week and last two months activities which are still in previous year and hence leads to improper result
863 $lastOrNextYearDate = (date('M') == 'Jan') ? date('YmdHis', strtotime('+1 year')) : date('YmdHis', strtotime('1 year ago'));
49d4d222 864 for ($i = 1; $i <= 16; $i++) {
865 if (in_array($i, $lastWeekActivities)) {
866 $date = $lastWeekDate;
867 }
a6d192c8 868 elseif (in_array($i, $lastTwoMonthsActivities)) {
869 $date = $lastTwoMonthAgoDate;
49d4d222 870 }
daff7f26 871 elseif (in_array($i, $lastOrNextYearActivities)) {
872 $date = $lastOrNextYearDate;
49d4d222 873 }
874 elseif (in_array($i, $todayActivities)) {
875 $date = $today;
876 }
9099cab3 877 $this->callAPISuccess('Activity', 'create', [
49d4d222 878 'id' => $i,
879 'activity_date_time' => $date,
9099cab3 880 ]);
49d4d222 881 }
882
883 // parameters for different test cases, check each array key for the specific test-case
9099cab3
CW
884 $testCases = [
885 'todays-activity' => [
886 'params' => [
49d4d222 887 'contact_id' => 1,
888 'admin' => TRUE,
889 'caseId' => NULL,
890 'context' => 'activity',
6e793248 891 'activity_date_time_relative' => 'this.day',
49d4d222 892 'activity_type_id' => NULL,
893 'offset' => 0,
894 'rowCount' => 0,
895 'sort' => NULL,
9099cab3
CW
896 ],
897 ],
898 'todays-activity-filtered-by-range' => [
899 'params' => [
49d4d222 900 'contact_id' => 1,
901 'admin' => TRUE,
902 'caseId' => NULL,
903 'context' => 'activity',
6e793248 904 'activity_date_time_low' => date('Y/m/d', strtotime('yesterday')),
905 'activity_date_time_high' => date('Y/m/d'),
49d4d222 906 'activity_type_id' => NULL,
907 'offset' => 0,
908 'rowCount' => 0,
909 'sort' => NULL,
9099cab3
CW
910 ],
911 ],
912 'last-week-activity' => [
913 'params' => [
49d4d222 914 'contact_id' => 1,
915 'admin' => TRUE,
916 'caseId' => NULL,
917 'context' => 'activity',
6e793248 918 'activity_date_time_relative' => 'previous.week',
49d4d222 919 'activity_type_id' => NULL,
920 'offset' => 0,
921 'rowCount' => 0,
922 'sort' => NULL,
9099cab3
CW
923 ],
924 ],
925 'this-quarter-activity' => [
926 'params' => [
49d4d222 927 'contact_id' => 1,
928 'admin' => TRUE,
929 'caseId' => NULL,
930 'context' => 'activity',
6e793248 931 'activity_date_time_relative' => 'this.quarter',
49d4d222 932 'activity_type_id' => NULL,
933 'offset' => 0,
934 'rowCount' => 0,
935 'sort' => NULL,
9099cab3
CW
936 ],
937 ],
938 'activity-of-all-statuses' => [
939 'params' => [
49d4d222 940 'contact_id' => 1,
941 'admin' => TRUE,
942 'caseId' => NULL,
943 'context' => 'activity',
944 'activity_status_id' => '1,2',
945 'activity_type_id' => NULL,
946 'offset' => 0,
947 'rowCount' => 0,
948 'sort' => NULL,
9099cab3
CW
949 ],
950 ],
951 ];
49d4d222 952
953 foreach ($testCases as $caseName => $testCase) {
6e793248 954 CRM_Utils_Date::convertFormDateToApiFormat($testCase['params'], 'activity_date_time', FALSE);
955 $activities = CRM_Activity_BAO_Activity::getActivities($testCase['params']);
956 $activityCount = CRM_Activity_BAO_Activity::getActivitiesCount($testCase['params']);
957 asort($activities);
958 $activityIDs = array_keys($activities);
49d4d222 959
960 if ($caseName == 'todays-activity' || $caseName == 'todays-activity-filtered-by-range') {
6e793248 961 // Only one of the 4 activities today relates to contact id 1.
962 $this->assertEquals(1, $activityCount);
963 $this->assertEquals(1, count($activities));
964 $this->assertEquals([7], array_keys($activities));
49d4d222 965 }
966 elseif ($caseName == 'last-week-activity') {
6e793248 967 // Only one of the 3 activities today relates to contact id 1.
968 $this->assertEquals(1, $activityCount);
969 $this->assertEquals(1, count($activities));
970 $this->assertEquals([1], $activityIDs);
49d4d222 971 }
a6d192c8 972 elseif ($caseName == 'lhis-quarter-activity') {
973 $this->assertEquals(count($lastTwoMonthsActivities), $activityCount);
6e793248 974 $this->assertEquals(count($lastTwoMonthsActivities), count($activities));
a6d192c8 975 $this->checkArrayEquals($lastTwoMonthsActivities, $activityIDs);
49d4d222 976 }
daff7f26 977 elseif ($caseName == 'last-or-next-year-activity') {
978 $this->assertEquals(count($lastOrNextYearActivities), $activityCount);
6e793248 979 $this->assertEquals(count($lastOrNextYearActivities), count($activities));
daff7f26 980 $this->checkArrayEquals($lastOrNextYearActivities, $activityIDs);
49d4d222 981 }
982 elseif ($caseName == 'activity-of-all-statuses') {
6e793248 983 $this->assertEquals(3, $activityCount);
984 $this->assertEquals(3, count($activities));
49d4d222 985 }
986 }
987 }
988
afc82ed3 989 /**
990 * @dataProvider getActivityDateData
991 */
992 public function testActivityRelativeDateFilter($params, $expected) {
993 $thisYear = date('Y');
994 $dates = [
995 date('Y-m-d', strtotime(($thisYear - 1) . '-01-01')),
996 date('Y-m-d', strtotime(($thisYear - 1) . '-12-31')),
997 date('Y-m-d', strtotime($thisYear . '-01-01')),
998 date('Y-m-d', strtotime($thisYear . '-12-31')),
999 date('Y-m-d', strtotime(($thisYear + 1) . '-01-01')),
1000 date('Y-m-d', strtotime(($thisYear + 1) . '-12-31')),
1001 ];
1002 foreach ($dates as $date) {
1003 $this->activityCreate(['activity_date_time' => $date]);
1004 }
6e793248 1005 $activitiesDep = CRM_Activity_BAO_Activity::getActivities($params);
1006 $activityCount = CRM_Activity_BAO_Activity::getActivitiesCount($params);
afc82ed3 1007 $this->assertEquals(count($activitiesDep), $activityCount);
1008 foreach ($activitiesDep as $activity) {
1009 $this->assertTrue(strtotime($activity['activity_date_time']) >= $expected['earliest'], $activity['activity_date_time'] . ' should be no earlier than ' . date('Y-m-d H:i:s', $expected['earliest']));
1010 $this->assertTrue(strtotime($activity['activity_date_time']) < $expected['latest'], $activity['activity_date_time'] . ' should be before ' . date('Y-m-d H:i:s', $expected['latest']));
1011 }
1012
1013 }
1014
1015 /**
1016 * Get activity date data.
1017 *
1018 * Later we might migrate rework the rest of
1019 * testByActivityDateAndStatus
1020 * to use data provider methodology as it's way complex!
1021 *
1022 * @return array
1023 */
1024 public function getActivityDateData() {
1025 return [
1026 'last-year-activity' => [
1027 'params' => [
1028 'contact_id' => 1,
1029 'admin' => TRUE,
1030 'caseId' => NULL,
1031 'context' => 'activity',
1032 'activity_date_relative' => 'previous.year',
1033 'activity_type_id' => NULL,
1034 'offset' => 0,
1035 'rowCount' => 0,
1036 'sort' => NULL,
1037 ],
1038 'expected' => [
1039 'count' => 2,
1040 'earliest' => strtotime('first day of january last year'),
1041 'latest' => strtotime('first day of january this year'),
39b959db 1042 ],
afc82ed3 1043 ],
1044 ];
1045 }
1046
3cf1fae9 1047 /**
1048 * CRM-20308: Test from email address when a 'copy of Activity' event occur
1049 */
1050 public function testEmailAddressOfActivityCopy() {
1051 // Case 1: assert the 'From' Email Address of source Actvity Contact ID
1052 // create activity with source contact ID which has email address
1053 $assigneeContactId = $this->individualCreate();
9099cab3 1054 $sourceContactParams = [
3cf1fae9 1055 'first_name' => 'liz',
1056 'last_name' => 'hurleey',
1057 'email' => substr(sha1(rand()), 0, 7) . '@testemail.com',
9099cab3 1058 ];
3cf1fae9 1059 $sourceContactID = $this->individualCreate($sourceContactParams);
1060 $sourceDisplayName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $sourceContactID, 'display_name');
1061
1062 // create an activity using API
9099cab3 1063 $params = [
3cf1fae9 1064 'source_contact_id' => $sourceContactID,
1065 'subject' => 'Scheduling Meeting ' . substr(sha1(rand()), 0, 4),
1066 'activity_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Meeting'),
9099cab3 1067 'assignee_contact_id' => [$assigneeContactId],
3cf1fae9 1068 'activity_date_time' => date('Ymd'),
9099cab3 1069 ];
3cf1fae9 1070 $activity = $this->callAPISuccess('Activity', 'create', $params);
1071
1072 // Check that from address is in "Source-Display-Name <source-email>"
1073 $formAddress = CRM_Case_BAO_Case::getReceiptFrom($activity['id']);
1074 $expectedFromAddress = sprintf("%s <%s>", $sourceDisplayName, $sourceContactParams['email']);
1075 $this->assertEquals($expectedFromAddress, $formAddress);
3cf1fae9 1076
1077 // Case 2: System Default From Address
1078 // but first erase the email address of existing source contact ID
9099cab3 1079 $withoutEmailParams = [
3cf1fae9 1080 'email' => '',
9099cab3 1081 ];
3cf1fae9 1082 $sourceContactID = $this->individualCreate($withoutEmailParams);
9099cab3 1083 $params = [
3cf1fae9 1084 'source_contact_id' => $sourceContactID,
1085 'subject' => 'Scheduling Meeting ' . substr(sha1(rand()), 0, 4),
1086 'activity_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Meeting'),
1087 'activity_date_time' => date('Ymd'),
9099cab3 1088 ];
3cf1fae9 1089 $activity = $this->callAPISuccess('Activity', 'create', $params);
1090 // fetch domain info
9099cab3 1091 $domainInfo = $this->callAPISuccess('Domain', 'getsingle', ['id' => CRM_Core_Config::domainID()]);
3cf1fae9 1092
1093 $formAddress = CRM_Case_BAO_Case::getReceiptFrom($activity['id']);
1094 if (!empty($domainInfo['from_email'])) {
1095 $expectedFromAddress = sprintf("%s <%s>", $domainInfo['from_name'], $domainInfo['from_email']);
1096 }
1097 // Case 3: fetch default Organization Contact email address
1098 elseif (!empty($domainInfo['domain_email'])) {
1099 $expectedFromAddress = sprintf("%s <%s>", $domainInfo['name'], $domainInfo['domain_email']);
1100 }
e88906fc 1101 $this->assertEquals($expectedFromAddress, $formAddress);
3cf1fae9 1102
1103 // TODO: Case 4 about checking the $formAddress on basis of logged contact ID respectively needs,
1104 // to change the domain setting, which isn't straight forward in test environment
1105 }
1106
75d842f8 1107 /**
1108 * Set up for testing activity queries.
1109 */
1110 protected function setUpForActivityDashboardTests() {
a6c2ebdc 1111 $this->createTestActivities();
75d842f8 1112
9099cab3 1113 $this->_params = [
75d842f8 1114 'contact_id' => NULL,
1115 'admin' => TRUE,
1116 'caseId' => NULL,
1117 'context' => 'home',
1118 'activity_type_id' => NULL,
39b959db
SL
1119 // for dashlet the Scheduled status is set by default
1120 'activity_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'status_id', 'Scheduled'),
75d842f8 1121 'offset' => 0,
1122 'rowCount' => 0,
1123 'sort' => NULL,
9099cab3 1124 ];
75d842f8 1125 }
1126
824989b9
AS
1127 public function testSendEmailBasic() {
1128 $contactId = $this->individualCreate();
1129
1130 // create a logged in USER since the code references it for sendEmail user.
1131 $this->createLoggedInUser();
1132 $session = CRM_Core_Session::singleton();
1133 $loggedInUser = $session->get('userID');
1134
9099cab3
CW
1135 $contact = $this->civicrm_api('contact', 'getsingle', ['id' => $contactId, 'version' => $this->_apiversion]);
1136 $contactDetailsIntersectKeys = [
824989b9
AS
1137 'contact_id' => '',
1138 'sort_name' => '',
1139 'display_name' => '',
1140 'do_not_email' => '',
1141 'preferred_mail_format' => '',
1142 'is_deceased' => '',
1143 'email' => '',
1144 'on_hold' => '',
9099cab3
CW
1145 ];
1146 $contactDetails = [
824989b9 1147 array_intersect_key($contact, $contactDetailsIntersectKeys),
9099cab3 1148 ];
824989b9
AS
1149
1150 $subject = __FUNCTION__ . ' subject';
1151 $html = __FUNCTION__ . ' html';
1152 $text = __FUNCTION__ . ' text';
1153 $userID = $loggedInUser;
1154
1155 list($sent, $activity_id) = $email_result = CRM_Activity_BAO_Activity::sendEmail(
1156 $contactDetails,
1157 $subject,
1158 $text,
1159 $html,
1160 $contact['email'],
1161 $userID,
1162 $from = __FUNCTION__ . '@example.com'
1163 );
1164
9099cab3 1165 $activity = $this->civicrm_api('activity', 'getsingle', ['id' => $activity_id, 'version' => $this->_apiversion]);
824989b9
AS
1166 $details = "-ALTERNATIVE ITEM 0-
1167$html
1168-ALTERNATIVE ITEM 1-
1169$text
1170-ALTERNATIVE END-
1171";
1172 $this->assertEquals($activity['details'], $details, 'Activity details does not match.');
1173 $this->assertEquals($activity['subject'], $subject, 'Activity subject does not match.');
1174 }
1175
1176 public function testSendEmailWithCampaign() {
1177 // Create a contact and contactDetails array.
1178 $contactId = $this->individualCreate();
1179
1180 // create a logged in USER since the code references it for sendEmail user.
1181 $this->createLoggedInUser();
1182 $session = CRM_Core_Session::singleton();
1183 $loggedInUser = $session->get('userID');
1184
9099cab3
CW
1185 $contact = $this->civicrm_api('contact', 'getsingle', ['id' => $contactId, 'version' => $this->_apiversion]);
1186 $contactDetailsIntersectKeys = [
824989b9
AS
1187 'contact_id' => '',
1188 'sort_name' => '',
1189 'display_name' => '',
1190 'do_not_email' => '',
1191 'preferred_mail_format' => '',
1192 'is_deceased' => '',
1193 'email' => '',
1194 'on_hold' => '',
9099cab3
CW
1195 ];
1196 $contactDetails = [
824989b9 1197 array_intersect_key($contact, $contactDetailsIntersectKeys),
9099cab3 1198 ];
824989b9
AS
1199
1200 // Create a campaign.
9099cab3 1201 $result = $this->civicrm_api('Campaign', 'create', [
824989b9
AS
1202 'version' => $this->_apiversion,
1203 'title' => __FUNCTION__ . ' campaign',
9099cab3 1204 ]);
824989b9
AS
1205 $campaign_id = $result['id'];
1206
1207 $subject = __FUNCTION__ . ' subject';
1208 $html = __FUNCTION__ . ' html';
1209 $text = __FUNCTION__ . ' text';
1210 $userID = $loggedInUser;
1211
1212 list($sent, $activity_id) = $email_result = CRM_Activity_BAO_Activity::sendEmail(
1213 $contactDetails,
1214 $subject,
1215 $text,
1216 $html,
1217 $contact['email'],
1218 $userID,
1219 $from = __FUNCTION__ . '@example.com',
1220 $attachments = NULL,
1221 $cc = NULL,
1222 $bcc = NULL,
1223 $contactIds = NULL,
1224 $additionalDetails = NULL,
cb5d08cd 1225 NULL,
824989b9
AS
1226 $campaign_id
1227 );
9099cab3 1228 $activity = $this->civicrm_api('activity', 'getsingle', ['id' => $activity_id, 'version' => $this->_apiversion]);
824989b9
AS
1229 $this->assertEquals($activity['campaign_id'], $campaign_id, 'Activity campaign_id does not match.');
1230 }
1231
63483feb
MM
1232 /**
1233 * @expectedException CRM_Core_Exception
1234 * @expectedExceptionMessage You do not have the 'send SMS' permission
1235 */
1236 public function testSendSMSWithoutPermission() {
1237 $dummy = NULL;
1238 $session = CRM_Core_Session::singleton();
9099cab3 1239 CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM'];
63483feb
MM
1240
1241 CRM_Activity_BAO_Activity::sendSMS(
1242 $dummy,
1243 $dummy,
1244 $dummy,
1245 $dummy,
1246 $session->get('userID')
1247 );
1248 }
1249
1a7f0799
MW
1250 public function testSendSmsNoPhoneNumber() {
1251 list($sent, $activityId, $success) = $this->createSendSmsTest(0);
9099cab3 1252 $activity = $this->civicrm_api('activity', 'getsingle', ['id' => $activityId, 'version' => $this->_apiversion]);
1a7f0799
MW
1253
1254 $outBoundSmsActivityId = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'SMS');
1255 $activityStatusCompleted = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_status_id', 'Completed');
1256 $details = 'createSendSmsTest text';
1257 $this->assertEquals($activity['activity_type_id'], $outBoundSmsActivityId, 'Wrong activity type is set.');
1258 $this->assertEquals($activity['status_id'], $activityStatusCompleted, 'Expected activity status Completed.');
1259 $this->assertEquals($activity['subject'], 'createSendSmsTest subject', 'Activity subject does not match.');
1260 $this->assertEquals($activity['details'], $details, 'Activity details does not match.');
4a0e3fe7 1261 $this->assertEquals("Recipient phone number is invalid or recipient does not want to receive SMS", $sent[0], "Expected error doesn't match");
1a7f0799
MW
1262 $this->assertEquals(0, $success, "Expected success to be 0");
1263 }
1264
1265 public function testSendSmsFixedPhoneNumber() {
1266 list($sent, $activityId, $success) = $this->createSendSmsTest(1);
9099cab3 1267 $activity = $this->civicrm_api('activity', 'getsingle', ['id' => $activityId, 'version' => $this->_apiversion]);
1a7f0799
MW
1268
1269 $outBoundSmsActivityId = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'SMS');
1270 $activityStatusCompleted = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_status_id', 'Completed');
1271 $details = 'createSendSmsTest text';
1272 $this->assertEquals($activity['activity_type_id'], $outBoundSmsActivityId, 'Wrong activity type is set.');
1273 $this->assertEquals($activity['status_id'], $activityStatusCompleted, 'Expected activity status Completed.');
1274 $this->assertEquals($activity['subject'], 'createSendSmsTest subject', 'Activity subject does not match.');
1275 $this->assertEquals($activity['details'], $details, 'Activity details does not match.');
4a0e3fe7 1276 $this->assertEquals("Recipient phone number is invalid or recipient does not want to receive SMS", $sent[0], "Expected error doesn't match");
1a7f0799
MW
1277 $this->assertEquals(0, $success, "Expected success to be 0");
1278 }
1279
1280 public function testSendSmsMobilePhoneNumber() {
1281 list($sent, $activityId, $success) = $this->createSendSmsTest(2);
9099cab3 1282 $activity = $this->civicrm_api('activity', 'getsingle', ['id' => $activityId, 'version' => $this->_apiversion]);
1a7f0799
MW
1283
1284 $outBoundSmsActivityId = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'SMS');
1285 $activityStatusCompleted = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_status_id', 'Completed');
1286 $details = 'createSendSmsTest text';
1287 $this->assertEquals($activity['activity_type_id'], $outBoundSmsActivityId, 'Wrong activity type is set.');
1288 $this->assertEquals($activity['status_id'], $activityStatusCompleted, 'Expected activity status Completed.');
1289 $this->assertEquals($activity['subject'], 'createSendSmsTest subject', 'Activity subject does not match.');
1290 $this->assertEquals($activity['details'], $details, 'Activity details does not match.');
1291 $this->assertEquals(TRUE, $sent, "Expected sent should be true");
1292 $this->assertEquals(1, $success, "Expected success to be 1");
1293 }
1294
a9b7ee41
SL
1295 /**
1296 * Test that when a numbe ris specified in the To Param of the SMS provider parameters that an SMS is sent
1297 * @see dev/core/#273
1298 */
1299 public function testSendSMSMobileInToProviderParam() {
1300 list($sent, $activityId, $success) = $this->createSendSmsTest(2, TRUE);
1301 $this->assertEquals(TRUE, $sent, "Expected sent should be true");
1302 $this->assertEquals(1, $success, "Expected success to be 1");
1303 }
1304
1305 /**
1306 * Test that when a numbe ris specified in the To Param of the SMS provider parameters that an SMS is sent
1307 * @see dev/core/#273
1308 */
1309 public function testSendSMSMobileInToProviderParamWithDoNotSMS() {
1310 list($sent, $activityId, $success) = $this->createSendSmsTest(2, TRUE, ['do_not_sms' => 1]);
1311 foreach ($sent as $error) {
4a0e3fe7 1312 $this->assertEquals('Contact Does not accept SMS', $error);
a9b7ee41
SL
1313 }
1314 $this->assertEquals(1, count($sent), "Expected sent should a PEAR Error");
1315 $this->assertEquals(0, $success, "Expected success to be 0");
1316 }
1317
1a7f0799
MW
1318 /**
1319 * @param int $phoneType (0=no phone, phone_type option group (1=fixed, 2=mobile)
a9b7ee41
SL
1320 * @param bool $passPhoneTypeInContactDetails
1321 * @param array $additionalContactParams additional contact creation params
1a7f0799 1322 */
a9b7ee41 1323 public function createSendSmsTest($phoneType = 0, $passPhoneTypeInContactDetails = FALSE, $additionalContactParams = []) {
9099cab3 1324 $provider = civicrm_api3('SmsProvider', 'create', [
1a7f0799
MW
1325 'name' => "CiviTestSMSProvider",
1326 'api_type' => "1",
1327 "username" => "1",
1328 "password" => "1",
1329 "api_type" => "1",
1330 "api_url" => "1",
1331 "api_params" => "a=1",
1332 "is_default" => "1",
1333 "is_active" => "1",
1334 "domain_id" => "1",
9099cab3 1335 ]);
a9b7ee41 1336
1a7f0799
MW
1337 $smsProviderParams['provider_id'] = $provider['id'];
1338
1339 // Create a contact
1340 $contactId = $this->individualCreate();
a9b7ee41
SL
1341 if (!empty($additionalContactParams)) {
1342 $this->callAPISuccess('contact', 'create', ['id' => $contactId] + $additionalContactParams);
1343 }
1344 $contactsResult = $this->callApiSuccess('contact', 'get', ['id' => $contactId, 'version' => $this->_apiversion]);
1a7f0799
MW
1345 $contactDetails = $contactsResult['values'];
1346
1347 // Get contactIds from contact details
1348 foreach ($contactDetails as $contact) {
1349 $contactIds[] = $contact['contact_id'];
1350 }
1351
1352 $activityParams['sms_text_message'] = __FUNCTION__ . ' text';
1353 $activityParams['activity_subject'] = __FUNCTION__ . ' subject';
1354
1a7f0799
MW
1355 // Get a "logged in" user to set as source of Sms.
1356 $session = CRM_Core_Session::singleton();
1357 $sourceContactId = $session->get('userID');
1358
a627697d 1359 // Create a user
1a7f0799 1360 $this->_testSmsContactId = $this->createLoggedInUser();
a627697d
MW
1361
1362 // Give user permission to 'send SMS'
9099cab3 1363 CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM', 'send SMS'];
a627697d
MW
1364
1365 // Create a phone number
1a7f0799
MW
1366 switch ($phoneType) {
1367 case 0:
1368 // No phone number
1369 break;
1370
1371 case 2:
1372 // Create a mobile phone number
9099cab3 1373 $phone = civicrm_api3('Phone', 'create', [
1a7f0799
MW
1374 'contact_id' => $contactId,
1375 'phone' => 123456,
1376 'phone_type_id' => "Mobile",
9099cab3 1377 ]);
a9b7ee41
SL
1378 if ($passPhoneTypeInContactDetails) {
1379 $contactDetails[$contactId]['phone'] = $phone['values'][$phone['id']]['phone'];
1380 $contactDetails[$contactId]['phone_type_id'] = $phone['values'][$phone['id']]['phone_type_id'];
1381 }
1a7f0799
MW
1382 break;
1383
1384 case 1:
1385 // Create a fixed phone number
9099cab3 1386 $phone = civicrm_api3('Phone', 'create', [
1a7f0799
MW
1387 'contact_id' => $contactId,
1388 'phone' => 654321,
1389 'phone_type_id' => "Phone",
9099cab3 1390 ]);
a9b7ee41
SL
1391 if ($passPhoneTypeInContactDetails) {
1392 $contactDetails[$contactId]['phone'] = $phone['values'][$phone['id']]['phone'];
1393 $contactDetails[$contactId]['phone_type_id'] = $phone['values'][$phone['id']]['phone_type_id'];
1394 }
1a7f0799
MW
1395 break;
1396 }
1397
1398 // Now run the actual test
1399 list($sent, $activityId, $success) = CRM_Activity_BAO_Activity::sendSms(
1400 $contactDetails,
1401 $activityParams,
1402 $smsProviderParams,
1403 $contactIds,
1404 $sourceContactId
1405 );
1406
9099cab3 1407 return [$sent, $activityId, $success];
1a7f0799
MW
1408 }
1409
a6c2ebdc 1410 protected function createTestActivities() {
1d291c60 1411 $this->loadXMLDataSet(dirname(__FILE__) . '/activities_for_dashboard_count.xml');
c2ce41b6 1412 // Make changes to improve variation in php since the xml method is brittle & relies on option values being unchanged.
1413 $this->callAPISuccess('Activity', 'create', ['id' => 12, 'activity_type_id' => 'Bulk Email']);
a6c2ebdc 1414 }
1415
5123cb11
SL
1416 /**
1417 * ACL HOOK implementation for various tests
1418 */
1419 public function hook_civicrm_aclWhereClause($type, &$tables, &$whereTables, &$contactID, &$where) {
1420 if (!empty($this->allowedContactsACL)) {
1421 $contact_id_list = implode(',', $this->allowedContactsACL);
1422 $where = " contact_a.id IN ($contact_id_list)";
1423 }
1424 }
1425
cb5108b8 1426 public function testCaseTokens() {
1427 $caseTest = new CiviCaseTestCase();
1428 $caseTest->setUp();
1429 // Create a contact and contactDetails array.
1430 $contactId = $this->individualCreate();
1431
1432 // create a case for this user
f7f1cc3b 1433 $result = $this->callAPISuccess('Case', 'create', [
cb5108b8 1434 'contact_id' => $contactId,
1435 'case_type_id' => '1',
1436 'subject' => "my case",
1437 'status_id' => "Open",
f7f1cc3b 1438 ]);
cb5108b8 1439
1440 $caseId = $result['id'];
1441 $html_message = "<p>This is a test case with id: {case.id} and subject: {case.subject}</p>";
1442 $html_message = CRM_Utils_Token::replaceCaseTokens($caseId, $html_message);
1443
f7f1cc3b 1444 $this->assertTrue(strpos($html_message, 'id: ' . $caseId) !== 0);
cb5108b8 1445 $this->assertTrue(strpos($html_message, 'subject: my case') !== 0);
f7f1cc3b 1446 $caseTest->tearDown();
cb5108b8 1447 }
1448
1449 public function testSendEmailWithCaseId() {
f7f1cc3b
SL
1450 $caseTest = new CiviCaseTestCase();
1451 $caseTest->setUp();
cb5108b8 1452 // Create a contact and contactDetails array.
1453 $contactId = $this->individualCreate();
f7f1cc3b 1454 $contact = $this->callAPISuccess('Contact', 'get', ['id' => $contactId]);
cb5108b8 1455
1456 // create a logged in USER since the code references it for sendEmail user.
1457 $this->createLoggedInUser();
f7f1cc3b 1458 CRM_Core_Config::singleton()->userPermissionClass->permissions = ['view all contacts', 'access CiviCRM', 'access all cases and activities', 'administer CiviCase'];
cb5108b8 1459 $session = CRM_Core_Session::singleton();
1460 $loggedInUser = $session->get('userID');
1461
cb5108b8 1462 // create a case for this user
f7f1cc3b 1463 $result = $this->callAPISuccess('Case', 'create', [
cb5108b8 1464 'contact_id' => $contactId,
1465 'case_type_id' => 1,
1466 'subject' => "my case",
1467 'status_id' => "Open",
f7f1cc3b 1468 ]);
cb5108b8 1469
1470 $caseId = $result['id'];
1471
f7f1cc3b
SL
1472 $subject = __FUNCTION__ . ' subject {case.subject}';
1473 $html = __FUNCTION__ . ' html {case.subject}';
cb5108b8 1474 $text = __FUNCTION__ . ' text';
cb5108b8 1475
f7f1cc3b 1476 $mut = new CiviMailUtils($this, TRUE);
cb5108b8 1477 list($sent, $activity_id) = $email_result = CRM_Activity_BAO_Activity::sendEmail(
f7f1cc3b 1478 $contact['values'],
cb5108b8 1479 $subject,
1480 $text,
1481 $html,
f7f1cc3b
SL
1482 $contact['values'][$contactId]['email'],
1483 $loggedInUser,
cb5108b8 1484 $from = __FUNCTION__ . '@example.com',
cb5108b8 1485 NULL,
f7f1cc3b
SL
1486 NULL,
1487 NULL,
1488 [$contactId],
1489 NULL,
1490 NULL,
1491 NULL,
cb5108b8 1492 $caseId
1493 );
f7f1cc3b
SL
1494 $activity = $this->callAPISuccess('Activity', 'getsingle', ['id' => $activity_id, 'return' => ['case_id']]);
1495 $this->assertEquals($caseId, $activity['case_id'][0], 'Activity case_id does not match.');
1496 $mut->checkMailLog(['subject my case']);
1497 $mut->stop();
cb5108b8 1498 }
1499
3e120a63
RLAR
1500 /**
1501 * Adds a case with one activity.
1502 *
1503 */
1504 protected function addCaseWithActivity() {
1505 // case is not enabled by default do that now.
1506 $enableResult = CRM_Core_BAO_ConfigSetting::enableComponent('CiviCase');
1507 $this->assertTrue($enableResult, 'Cannot enable CiviCase in line ' . __LINE__);
1508
1509 // We need a minimal case setup.
1510 $case_type_id = civicrm_api3('CaseType', 'get', ['return' => 'id', 'name' => 'test_case_type'])['id'] ?? NULL;
1511 if (!$case_type_id) {
1512 $params = [
1513 'name' => 'test_case_type',
1514 'title' => 'test_case_type',
1515 "is_active" => "1",
1516 "definition" => [
1517 "activityTypes" => [
1518 ["name" => "Open Case", "max_instances" => "1"],
1519 ["name" => "Meeting"],
1520 ],
1521 "activitySets" => [
1522 [
1523 "name" => "standard_timeline",
1524 "label" => "Standard Timeline",
1525 "timeline" => "1",
1526 "activityTypes" => [
1527 [
1528 "name" => "Open Case",
1529 "status" => "Completed",
1530 "label" => "Open Case",
1531 "default_assignee_type" => "1",
1532 ],
1533 ],
1534 ],
1535 ],
1536 "timelineActivityTypes" => [
1537 [
1538 "name" => "Open Case",
1539 "status" => "Completed",
1540 "label" => "Open Case",
1541 "default_assignee_type" => "1",
1542 ],
1543 ],
1544 "caseRoles" => [
1545 [
1546 "name" => "Case Coordinator",
1547 "creator" => "1",
1548 "manager" => "1",
1549 ],
1550 ],
1551 ],
1552 ];
1553 $case_type_id = $this->callAPISuccess('CaseType', 'create', $params)['id'];
1554 }
1555
1556 // Create a case with Contact #3 as the client.
1557 $case_id = civicrm_api3('case', 'get', ['subject' => 'test case 1'])['id'] ?? NULL;
1558 if (!$case_id) {
1559 // Create case
1560 $params = [
1561 'subject' => 'test case 1',
1562 'contact_id' => 3,
1563 'status_id' => 'Open',
1564 'case_type_id' => $case_type_id,
1565 'creator_id' => 3,
1566 ];
1567 $case_id = $this->callAPISuccess('case', 'create', $params)['id'];
1568 }
1569
1570 // Create a scheduled 'Meeting' activity that belongs to this case, but is
1571 // assigned to contact #9
1572 $activity_id = $this->callAPISuccess('Activity', 'create', [
1573 'activity_type_id' => 'Meeting',
1574 'status_id' => 'Scheduled',
1575 'case_id' => $case_id,
1576 'source_contact_id' => 3,
1577 'assignee_id' => [9],
1578 'subject' => 'test meeting activity',
1579 ])['id'] ?? NULL;
1580 }
1581
1582 /**
1583 * Change setting, and the cache of it.
1584 */
1585 protected function setShowCaseActivitiesInCore(bool $val) {
1586 Civi::settings()->set('civicaseShowCaseActivities', $val ? 1 : 0);
1587 CRM_Core_Component::getEnabledComponents();
1588 Civi::$statics['CRM_Core_Component']['info']['CiviCase']->info['showActivitiesInCore'] = $val;
1589 }
1590
6a488035 1591}