4 * Class CRM_Activity_BAO_ActivityTest
7 class CRM_Activity_BAO_ActivityTest
extends CiviUnitTestCase
{
9 private $allowedContactsACL = [];
11 public function setUp() {
13 $this->prepareForACLs();
14 CRM_Core_Config
::singleton()->userPermissionClass
->permissions
= ['view all contacts', 'access CiviCRM'];
15 $this->setupForSmsTests();
19 * Clean up after tests.
21 public function tearDown() {
24 'civicrm_activity_contact',
29 $this->quickCleanup($tablesToTruncate);
30 $this->cleanUpAfterACLs();
31 $this->setupForSmsTests(TRUE);
36 * Test case for create() method.
38 public function testCreate() {
39 $contactId = $this->individualCreate();
42 'source_contact_id' => $contactId,
43 'subject' => 'Scheduling Meeting',
44 'activity_type_id' => 2,
47 CRM_Activity_BAO_Activity
::create($params);
49 $activityId = $this->assertDBNotNull('CRM_Activity_DAO_Activity', 'Scheduling Meeting', 'id',
50 'subject', 'Database check for created activity.'
53 // Now call create() to modify an existing Activity.
56 'source_contact_id' => $contactId,
57 'subject' => 'Scheduling Interview',
58 'activity_type_id' => 3,
61 CRM_Activity_BAO_Activity
::create($params);
63 $activityTypeId = $this->assertDBNotNull('CRM_Activity_DAO_Activity', 'Scheduling Interview',
65 'subject', 'Database check on updated activity record.'
67 $this->assertEquals($activityTypeId, 3, 'Verify activity type id is 3.');
69 $this->contactDelete($contactId);
73 * Test case for getContactActivity() method.
75 * getContactActivity() method get activities detail for given target contact id.
77 public function testGetContactActivity() {
78 $contactId = $this->individualCreate();
80 'first_name' => 'liz',
81 'last_name' => 'hurleey',
83 $targetContactId = $this->individualCreate($params);
86 'source_contact_id' => $contactId,
87 'subject' => 'Scheduling Meeting',
88 'activity_type_id' => 2,
89 'target_contact_id' => [$targetContactId],
90 'activity_date_time' => date('Ymd'),
93 $this->callAPISuccess('Activity', 'create', $params);
95 $activityId = $this->assertDBNotNull('CRM_Activity_DAO_Activity', 'Scheduling Meeting',
97 'subject', 'Database check for created activity.'
100 // @todo - remove this deprecated functions
101 $activities = CRM_Activity_BAO_Activity
::getContactActivity($targetContactId);
103 $this->assertEquals($activities[$activityId]['subject'], 'Scheduling Meeting', 'Verify activity subject is correct.');
105 $this->contactDelete($contactId);
106 $this->contactDelete($targetContactId);
110 * Test case for retrieve() method.
112 * Retrieve($params, $defaults) method return activity detail for given params
115 public function testRetrieve() {
116 $contactId = $this->individualCreate();
118 'first_name' => 'liz',
119 'last_name' => 'hurleey',
121 $targetContactId = $this->individualCreate($params);
124 'source_contact_id' => $contactId,
125 'subject' => 'Scheduling Meeting',
126 'activity_type_id' => 2,
127 'target_contact_id' => [$targetContactId],
128 'activity_date_time' => date('Ymd'),
131 CRM_Activity_BAO_Activity
::create($params);
133 $this->assertDBNotNull('CRM_Activity_DAO_Activity', 'Scheduling Meeting', 'id',
134 'subject', 'Database check for created activity.'
137 $this->assertDBNotNull('CRM_Activity_DAO_ActivityContact', $targetContactId,
139 'Database check for created activity target.'
143 $activity = CRM_Activity_BAO_Activity
::retrieve($params, $defaults);
145 $this->assertEquals($activity->subject
, 'Scheduling Meeting', 'Verify activity subject is correct.');
146 $this->assertEquals($activity->activity_type_id
, 2, 'Verify activity type id is correct.');
147 $this->assertEquals($defaults['source_contact_id'], $contactId, 'Verify source contact id is correct.');
149 $this->assertEquals($defaults['subject'], 'Scheduling Meeting', 'Verify activity subject is correct.');
150 $this->assertEquals($defaults['activity_type_id'], 2, 'Verify activity type id is correct.');
152 $this->assertEquals($defaults['target_contact'][0], $targetContactId, 'Verify target contact id is correct.');
154 $this->contactDelete($contactId);
155 $this->contactDelete($targetContactId);
159 * Test Assigning a target contact but then the logged in user cannot see the contact
161 public function testTargetContactNotavaliable() {
162 $contactId = $this->individualCreate();
164 'first_name' => 'liz',
165 'last_name' => 'hurleey',
167 $targetContactId = $this->individualCreate($params);
170 'source_contact_id' => $contactId,
171 'subject' => 'Scheduling Meeting',
172 'activity_type_id' => 2,
173 'target_contact_id' => [$targetContactId],
174 'activity_date_time' => date('Ymd'),
177 CRM_Activity_BAO_Activity
::create($params);
180 $this->hookClass
->setHook('civicrm_aclWhereClause', [$this, 'hook_civicrm_aclWhereClause']);
182 CRM_Core_Config
::singleton()->userPermissionClass
->permissions
= ['access CiviCRM'];
184 $this->allowedContactsACL
= [$contactId];
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);
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']);
197 $this->cleanUpAfterACLs();
201 * Test case for deleteActivity() method.
203 * deleteActivity($params) method deletes activity for given params.
205 public function testDeleteActivity() {
206 $contactId = $this->individualCreate();
208 'first_name' => 'liz',
209 'last_name' => 'hurleey',
211 $targetContactId = $this->individualCreate($params);
214 'source_contact_id' => $contactId,
215 'source_record_id' => $contactId,
216 'subject' => 'Scheduling Meeting',
217 'activity_type_id' => 2,
218 'target_contact_id' => [$targetContactId],
219 'activity_date_time' => date('Ymd'),
222 CRM_Activity_BAO_Activity
::create($params);
224 $this->assertDBNotNull('CRM_Activity_DAO_Activity', 'Scheduling Meeting', 'id',
225 'subject', 'Database check for created activity.'
228 $this->assertDBNotNull('CRM_Activity_DAO_ActivityContact', $targetContactId,
230 'Database check for created activity target.'
233 'source_contact_id' => $contactId,
234 'source_record_id' => $contactId,
235 'subject' => 'Scheduling Meeting',
236 'activity_type_id' => 2,
239 CRM_Activity_BAO_Activity
::deleteActivity($params);
241 $this->assertDBNull('CRM_Activity_DAO_Activity', 'Scheduling Meeting', 'id',
242 'subject', 'Database check for deleted activity.'
244 $this->contactDelete($contactId);
245 $this->contactDelete($targetContactId);
249 * Test case for deleteActivityTarget() method.
251 * deleteActivityTarget($activityId) method deletes activity target for given activity id.
253 public function testDeleteActivityTarget() {
254 $contactId = $this->individualCreate();
256 'first_name' => 'liz',
257 'last_name' => 'hurleey',
259 $targetContactId = $this->individualCreate($params);
262 'source_contact_id' => $contactId,
263 'subject' => 'Scheduling Meeting',
264 'activity_type_id' => 2,
265 'target_contact_id' => [$targetContactId],
266 'activity_date_time' => date('Ymd'),
269 CRM_Activity_BAO_Activity
::create($params);
271 $activityId = $this->assertDBNotNull('CRM_Activity_DAO_Activity', 'Scheduling Meeting', 'id',
272 'subject', 'Database check for created activity.'
275 $this->assertDBNotNull('CRM_Activity_DAO_ActivityContact', $targetContactId,
277 'Database check for created activity target.'
280 CRM_Activity_BAO_Activity
::deleteActivityContact($activityId, 3);
282 $this->assertDBNull('CRM_Activity_DAO_ActivityContact', $targetContactId, 'id',
283 'contact_id', 'Database check for deleted activity target.'
286 $this->contactDelete($contactId);
287 $this->contactDelete($targetContactId);
291 * Test case for deleteActivityAssignment() method.
293 * deleteActivityAssignment($activityId) method deletes activity assignment for given activity id.
295 public function testDeleteActivityAssignment() {
296 $contactId = $this->individualCreate();
298 'first_name' => 'liz',
299 'last_name' => 'hurleey',
301 $assigneeContactId = $this->individualCreate($params);
304 'source_contact_id' => $contactId,
305 'subject' => 'Scheduling Meeting',
306 'activity_type_id' => 2,
307 'assignee_contact_id' => [$assigneeContactId],
308 'activity_date_time' => date('Ymd'),
311 CRM_Activity_BAO_Activity
::create($params);
313 $activityId = $this->assertDBNotNull('CRM_Activity_DAO_Activity', 'Scheduling Meeting', 'id',
314 'subject', 'Database check for created activity.'
317 $this->assertDBNotNull('CRM_Activity_DAO_ActivityContact',
318 $assigneeContactId, 'id', 'contact_id',
319 'Database check for created activity assignment.'
322 CRM_Activity_BAO_Activity
::deleteActivityContact($activityId, 1);
324 $this->assertDBNull('CRM_Activity_DAO_ActivityContact', $assigneeContactId, 'id',
325 'contact_id', 'Database check for deleted activity assignment.'
328 $this->contactDelete($contactId);
329 $this->contactDelete($assigneeContactId);
333 * Test getActivities BAO method for getting count.
336 public function testGetActivitiesCountForAdminDashboard() {
338 $this->setShowCaseActivitiesInCore(FALSE);
339 $this->setUpForActivityDashboardTests();
340 $this->addCaseWithActivity();
341 CRM_Core_Config
::singleton()->userPermissionClass
->permissions
[] = 'access all cases and activities';
343 $activityCount = CRM_Activity_BAO_Activity
::getActivitiesCount($this->_params
);
344 $this->assertEquals(8, $activityCount);
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);
351 $this->setShowCaseActivitiesInCore(FALSE);
355 * Test getActivities BAO method for getting count
358 public function testGetActivitiesCountforNonAdminDashboard() {
360 $this->setShowCaseActivitiesInCore(FALSE);
361 $this->createTestActivities();
362 $this->addCaseWithActivity();
363 CRM_Core_Config
::singleton()->userPermissionClass
->permissions
[] = 'access all cases and activities';
370 'activity_type_id' => NULL,
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'),
378 //since we are loading activities from dataset, we know total number of activities for this contact
379 // 5 activities ( 2 scheduled, 3 Completed, 1 Scheduled Case activity ),
380 // note that dashboard shows only scheduled activities
381 $this->assertEquals(2, CRM_Activity_BAO_Activity
::getActivitiesCount($params));
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));
387 $this->setShowCaseActivitiesInCore(FALSE);
391 * Test getActivities BAO method for getting count
394 public function testGetActivitiesCountforContactSummary() {
396 $this->setShowCaseActivitiesInCore(FALSE);
397 $this->createTestActivities();
398 $this->addCaseWithActivity();
399 CRM_Core_Config
::singleton()->userPermissionClass
->permissions
[] = 'access all cases and activities';
405 'context' => 'activity',
406 'activity_type_id' => NULL,
412 //since we are loading activities from dataset, we know total number of activities for this contact
414 $this->assertEquals(5, CRM_Activity_BAO_Activity
::getActivitiesCount($params));
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));
420 $this->setShowCaseActivitiesInCore(FALSE);
424 * CRM-18706 - Test Include/Exclude Activity Filters
426 public function testActivityFilters() {
427 $this->createTestActivities();
428 Civi
::settings()->set('preserve_activity_tab_filter', 1);
429 $this->createLoggedInUser();
434 'context' => 'activity',
435 'activity_type_id' => 1,
439 'activity_type_filter_id' => 1,
442 list($activities, $activityFilter) = CRM_Activity_Page_AJAX
::getContactActivity();
443 //Assert whether filters are correctly set.
444 $this->checkArrayEquals($expectedFilters, $activityFilter);
445 // This should include activities of type Meeting only.
446 foreach ($activities['data'] as $value) {
447 $this->assertContains('Meeting', $value['activity_type']);
449 unset($_GET['activity_type_id']);
451 $_GET['activity_type_exclude_id'] = $expectedFilters['activity_type_exclude_filter_id'] = 1;
452 list($activities, $activityFilter) = CRM_Activity_Page_AJAX
::getContactActivity();
453 $this->assertEquals(['activity_type_exclude_filter_id' => 1], $activityFilter);
454 // None of the activities should be of type Meeting.
455 foreach ($activities['data'] as $value) {
456 $this->assertNotContains('Meeting', $value['activity_type']);
461 * Test getActivities BAO method for getting count
463 public function testGetActivitiesCountforContactSummaryWithNoActivities() {
464 $this->createTestActivities();
471 'activity_type_id' => NULL,
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
479 $this->assertEquals(0, CRM_Activity_BAO_Activity
::getActivitiesCount($params));
483 * Test getActivities BAO method.
485 public function testGetActivitiesForAdminDashboard() {
486 $this->setShowCaseActivitiesInCore(FALSE);
487 $this->setUpForActivityDashboardTests();
488 $this->addCaseWithActivity();
489 CRM_Core_Config
::singleton()->userPermissionClass
->permissions
[] = 'access all cases and activities';
491 $activitiesNew = CRM_Activity_BAO_Activity
::getActivities($this->_params
);
492 // $this->assertEquals($activities, $activitiesDeprecatedFn);
494 //since we are loading activities from dataset, we know total number of activities
495 // with no contact ID and there should be 8 schedule activities shown on dashboard
497 foreach ([$activitiesNew] as $activities) {
498 $this->assertEquals($count, count($activities));
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.');
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");
515 $this->setShowCaseActivitiesInCore(FALSE);
519 * Test getActivities BAO method.
521 public function testGetActivitiesForAdminDashboardNoViewContacts() {
522 CRM_Core_Config
::singleton()->userPermissionClass
->permissions
= ['access CiviCRM'];
523 $this->setUpForActivityDashboardTests();
524 foreach ([CRM_Activity_BAO_Activity
::getActivities($this->_params
)] as $activities) {
525 // Skipped until we get back to the upgraded version properly.
526 $this->assertEquals(0, count($activities));
531 * Test getActivities BAO method.
533 public function testGetActivitiesForAdminDashboardAclLimitedViewContacts() {
534 CRM_Core_Config
::singleton()->userPermissionClass
->permissions
= ['access CiviCRM'];
535 $this->allowedContacts
= [1, 3, 4, 5];
536 $this->hookClass
->setHook('civicrm_aclWhereClause', [$this, 'aclWhereMultipleContacts']);
537 $this->setUpForActivityDashboardTests();
538 $this->assertEquals(7, count(CRM_Activity_BAO_Activity
::getActivities($this->_params
)));
542 * Test getActivities BAO method.
544 public function testGetActivitiesforNonAdminDashboard() {
545 $this->setShowCaseActivitiesInCore(FALSE);
546 $this->createTestActivities();
547 $this->addCaseWithActivity();
548 CRM_Core_Config
::singleton()->userPermissionClass
->permissions
[] = 'access all cases and activities';
552 'contact_id' => $contactID,
556 'activity_type_id' => NULL,
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'),
564 foreach ([CRM_Activity_BAO_Activity
::getActivities($params)] as $activities) {
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
568 $this->assertEquals($count, count($activities));
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.');
576 $this->assertArrayHasKey($contactID, $value['target_contact_name']);
579 $this->assertArrayHasKey($contactID, $value['assignee_contact_name']);
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");
593 $this->setShowCaseActivitiesInCore(FALSE);
597 * Test target contact count.
599 public function testTargetCountforContactSummary() {
601 $contactId = $this->individualCreate();
602 $targetContactIDs = [];
603 for ($i = 0; $i < $targetCount; $i++
) {
604 $targetContactIDs[] = $this->individualCreate([], $i);
606 // Create activities with 5 target contacts.
608 'source_contact_id' => $contactId,
609 'target_contact_id' => $targetContactIDs,
611 $this->activityCreate($activityParams);
614 'contact_id' => $contactId,
615 'context' => 'activity',
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]);
626 * Test getActivities BAO method.
628 public function testGetActivitiesforContactSummaryWithSortOptions() {
629 $this->createTestActivities();
634 'context' => 'activity',
635 'activity_type_id' => NULL,
638 'sort' => 'source_contact_name desc',
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']);
650 * Test getActivities BAO method.
652 public function testGetActivitiesForContactSummary() {
654 $this->setShowCaseActivitiesInCore(FALSE);
655 $this->createTestActivities();
656 $this->addCaseWithActivity();
657 CRM_Core_Config
::singleton()->userPermissionClass
->permissions
[] = 'access all cases and activities';
661 'contact_id' => $contactID,
664 'context' => 'activity',
665 'activity_type_id' => NULL,
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
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.');
679 $this->assertEquals($value['status_id'], 2, 'Verify all activities are scheduled.');
682 $this->assertEquals($value['status_id'], 1, 'Verify all activities are scheduled.');
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]));
693 $this->assertEquals($value['activity_type_id'], 1, 'Verify activity type is correct.');
696 $this->assertEquals($value['activity_type_id'], 2, 'Verify activity type is correct.');
700 $this->assertEquals([$contactID => 'Test Contact ' . $contactID], $value['target_contact_name']);
703 $this->assertArrayHasKey($contactID, $value['assignee_contact_name']);
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");
715 $this->setShowCaseActivitiesInCore(FALSE);
719 * Test getActivities BAO method.
721 public function testGetActivitiesforContactSummaryWithActivities() {
723 $this->setShowCaseActivitiesInCore(FALSE);
724 $this->createTestActivities();
726 // parameters for different test cases, check each array key for the specific test-case
728 'with-no-activity' => [
734 'activity_type_id' => NULL,
746 'activity_type_id' => NULL,
752 'with-activity_type' => [
758 'activity_type_id' => 2,
764 'exclude-all-activity_type' => [
770 'activity_type_exclude_id' => [1, 2],
776 'sort-by-subject' => [
782 'activity_type_id' => NULL,
785 'sort' => 'subject DESC',
790 foreach ($testCases as $caseName => $testCase) {
791 $activityCount = CRM_Activity_BAO_Activity
::getActivitiesCount($testCase['params']);
792 $activitiesNew = CRM_Activity_BAO_Activity
::getActivities($testCase['params']);
794 foreach ([$activitiesNew] as $activities) {
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);
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']));
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']));
821 if ($caseName == 'exclude-all-activity_type') {
822 $this->assertEquals(0, count($activities));
823 $this->assertEquals(0, $activityCount);
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'
835 foreach ($activities as $activity) {
836 $this->assertEquals($subjectOrder[$count], $activity['subject']);
845 * CRM-20793 : Test getActivities by using activity date and status filter
847 public function testByActivityDateAndStatus() {
848 CRM_Core_Config
::singleton()->userPermissionClass
->permissions
= ['view all contacts', 'access CiviCRM'];
849 $this->createTestActivities();
851 // activity IDs catagorised by date
852 $lastWeekActivities = [1, 2, 3];
853 $todayActivities = [4, 5, 6, 7];
854 $lastTwoMonthsActivities = [8, 9, 10, 11];
855 $lastOrNextYearActivities = [12, 13, 14, 15, 16];
857 // date values later used to set activity date value
858 $lastWeekDate = date('YmdHis', strtotime('1 week ago'));
859 $today = date('YmdHis');
860 $lastTwoMonthAgoDate = date('YmdHis', strtotime('2 months ago'));
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'));
864 for ($i = 1; $i <= 16; $i++
) {
865 if (in_array($i, $lastWeekActivities)) {
866 $date = $lastWeekDate;
868 elseif (in_array($i, $lastTwoMonthsActivities)) {
869 $date = $lastTwoMonthAgoDate;
871 elseif (in_array($i, $lastOrNextYearActivities)) {
872 $date = $lastOrNextYearDate;
874 elseif (in_array($i, $todayActivities)) {
877 $this->callAPISuccess('Activity', 'create', [
879 'activity_date_time' => $date,
883 // parameters for different test cases, check each array key for the specific test-case
885 'todays-activity' => [
890 'context' => 'activity',
891 'activity_date_time_relative' => 'this.day',
892 'activity_type_id' => NULL,
898 'todays-activity-filtered-by-range' => [
903 'context' => 'activity',
904 'activity_date_time_low' => date('Y/m/d', strtotime('yesterday')),
905 'activity_date_time_high' => date('Y/m/d'),
906 'activity_type_id' => NULL,
912 'last-week-activity' => [
917 'context' => 'activity',
918 'activity_date_time_relative' => 'previous.week',
919 'activity_type_id' => NULL,
925 'this-quarter-activity' => [
930 'context' => 'activity',
931 'activity_date_time_relative' => 'this.quarter',
932 'activity_type_id' => NULL,
938 'activity-of-all-statuses' => [
943 'context' => 'activity',
944 'activity_status_id' => '1,2',
945 'activity_type_id' => NULL,
953 foreach ($testCases as $caseName => $testCase) {
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']);
958 $activityIDs = array_keys($activities);
960 if ($caseName == 'todays-activity' ||
$caseName == 'todays-activity-filtered-by-range') {
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));
966 elseif ($caseName == 'last-week-activity') {
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);
972 elseif ($caseName == 'lhis-quarter-activity') {
973 $this->assertEquals(count($lastTwoMonthsActivities), $activityCount);
974 $this->assertEquals(count($lastTwoMonthsActivities), count($activities));
975 $this->checkArrayEquals($lastTwoMonthsActivities, $activityIDs);
977 elseif ($caseName == 'last-or-next-year-activity') {
978 $this->assertEquals(count($lastOrNextYearActivities), $activityCount);
979 $this->assertEquals(count($lastOrNextYearActivities), count($activities));
980 $this->checkArrayEquals($lastOrNextYearActivities, $activityIDs);
982 elseif ($caseName == 'activity-of-all-statuses') {
983 $this->assertEquals(3, $activityCount);
984 $this->assertEquals(3, count($activities));
990 * @dataProvider getActivityDateData
992 public function testActivityRelativeDateFilter($params, $expected) {
993 $thisYear = date('Y');
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')),
1002 foreach ($dates as $date) {
1003 $this->activityCreate(['activity_date_time' => $date]);
1005 $activitiesDep = CRM_Activity_BAO_Activity
::getActivities($params);
1006 $activityCount = CRM_Activity_BAO_Activity
::getActivitiesCount($params);
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']));
1016 * Get activity date data.
1018 * Later we might migrate rework the rest of
1019 * testByActivityDateAndStatus
1020 * to use data provider methodology as it's way complex!
1024 public function getActivityDateData() {
1026 'last-year-activity' => [
1031 'context' => 'activity',
1032 'activity_date_relative' => 'previous.year',
1033 'activity_type_id' => NULL,
1040 'earliest' => strtotime('first day of january last year'),
1041 'latest' => strtotime('first day of january this year'),
1048 * CRM-20308: Test from email address when a 'copy of Activity' event occur
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();
1054 $sourceContactParams = [
1055 'first_name' => 'liz',
1056 'last_name' => 'hurleey',
1057 'email' => substr(sha1(rand()), 0, 7) . '@testemail.com',
1059 $sourceContactID = $this->individualCreate($sourceContactParams);
1060 $sourceDisplayName = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $sourceContactID, 'display_name');
1062 // create an activity using API
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'),
1067 'assignee_contact_id' => [$assigneeContactId],
1068 'activity_date_time' => date('Ymd'),
1070 $activity = $this->callAPISuccess('Activity', 'create', $params);
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);
1077 // Case 2: System Default From Address
1078 // but first erase the email address of existing source contact ID
1079 $withoutEmailParams = [
1082 $sourceContactID = $this->individualCreate($withoutEmailParams);
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'),
1089 $activity = $this->callAPISuccess('Activity', 'create', $params);
1090 // fetch domain info
1091 $domainInfo = $this->callAPISuccess('Domain', 'getsingle', ['id' => CRM_Core_Config
::domainID()]);
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']);
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']);
1101 $this->assertEquals($expectedFromAddress, $formAddress);
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
1108 * Set up for testing activity queries.
1110 protected function setUpForActivityDashboardTests() {
1111 $this->createTestActivities();
1114 'contact_id' => NULL,
1117 'context' => 'home',
1118 'activity_type_id' => NULL,
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'),
1127 public function testSendEmailBasic() {
1128 $contactId = $this->individualCreate();
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');
1135 $contact = $this->civicrm_api('contact', 'getsingle', ['id' => $contactId, 'version' => $this->_apiversion
]);
1136 $contactDetailsIntersectKeys = [
1139 'display_name' => '',
1140 'do_not_email' => '',
1141 'preferred_mail_format' => '',
1142 'is_deceased' => '',
1147 array_intersect_key($contact, $contactDetailsIntersectKeys),
1150 $subject = __FUNCTION__
. ' subject';
1151 $html = __FUNCTION__
. ' html';
1152 $text = __FUNCTION__
. ' text';
1153 $userID = $loggedInUser;
1155 list($sent, $activity_id) = $email_result = CRM_Activity_BAO_Activity
::sendEmail(
1162 $from = __FUNCTION__
. '@example.com'
1165 $activity = $this->civicrm_api('activity', 'getsingle', ['id' => $activity_id, 'version' => $this->_apiversion
]);
1166 $details = "-ALTERNATIVE ITEM 0-
1168 -ALTERNATIVE ITEM 1-
1172 $this->assertEquals($activity['details'], $details, 'Activity details does not match.');
1173 $this->assertEquals($activity['subject'], $subject, 'Activity subject does not match.');
1176 public function testSendEmailWithCampaign() {
1177 // Create a contact and contactDetails array.
1178 $contactId = $this->individualCreate();
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');
1185 $contact = $this->civicrm_api('contact', 'getsingle', ['id' => $contactId, 'version' => $this->_apiversion
]);
1186 $contactDetailsIntersectKeys = [
1189 'display_name' => '',
1190 'do_not_email' => '',
1191 'preferred_mail_format' => '',
1192 'is_deceased' => '',
1197 array_intersect_key($contact, $contactDetailsIntersectKeys),
1200 // Create a campaign.
1201 $result = $this->civicrm_api('Campaign', 'create', [
1202 'version' => $this->_apiversion
,
1203 'title' => __FUNCTION__
. ' campaign',
1205 $campaign_id = $result['id'];
1207 $subject = __FUNCTION__
. ' subject';
1208 $html = __FUNCTION__
. ' html';
1209 $text = __FUNCTION__
. ' text';
1210 $userID = $loggedInUser;
1212 list($sent, $activity_id) = $email_result = CRM_Activity_BAO_Activity
::sendEmail(
1219 $from = __FUNCTION__
. '@example.com',
1220 $attachments = NULL,
1224 $additionalDetails = NULL,
1228 $activity = $this->civicrm_api('activity', 'getsingle', ['id' => $activity_id, 'version' => $this->_apiversion
]);
1229 $this->assertEquals($activity['campaign_id'], $campaign_id, 'Activity campaign_id does not match.');
1233 * @expectedException CRM_Core_Exception
1234 * @expectedExceptionMessage You do not have the 'send SMS' permission
1236 public function testSendSMSWithoutPermission() {
1238 $session = CRM_Core_Session
::singleton();
1239 CRM_Core_Config
::singleton()->userPermissionClass
->permissions
= ['access CiviCRM'];
1241 CRM_Activity_BAO_Activity
::sendSMS(
1246 $session->get('userID')
1250 public function testSendSmsNoPhoneNumber() {
1251 list($sent, $activityId, $success) = $this->createSendSmsTest(0);
1252 $activity = $this->civicrm_api('activity', 'getsingle', ['id' => $activityId, 'version' => $this->_apiversion
]);
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.');
1261 $this->assertEquals("Recipient phone number is invalid or recipient does not want to receive SMS", $sent[0], "Expected error doesn't match");
1262 $this->assertEquals(0, $success, "Expected success to be 0");
1265 public function testSendSmsFixedPhoneNumber() {
1266 list($sent, $activityId, $success) = $this->createSendSmsTest(1);
1267 $activity = $this->civicrm_api('activity', 'getsingle', ['id' => $activityId, 'version' => $this->_apiversion
]);
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.');
1276 $this->assertEquals("Recipient phone number is invalid or recipient does not want to receive SMS", $sent[0], "Expected error doesn't match");
1277 $this->assertEquals(0, $success, "Expected success to be 0");
1280 public function testSendSmsMobilePhoneNumber() {
1281 list($sent, $activityId, $success) = $this->createSendSmsTest(2);
1282 $activity = $this->civicrm_api('activity', 'getsingle', ['id' => $activityId, 'version' => $this->_apiversion
]);
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");
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
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");
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
1309 public function testSendSMSMobileInToProviderParamWithDoNotSMS() {
1310 list($sent, $activityId, $success) = $this->createSendSmsTest(2, TRUE, ['do_not_sms' => 1]);
1311 foreach ($sent as $error) {
1312 $this->assertEquals('Contact Does not accept SMS', $error);
1314 $this->assertEquals(1, count($sent), "Expected sent should a PEAR Error");
1315 $this->assertEquals(0, $success, "Expected success to be 0");
1319 * @param int $phoneType (0=no phone, phone_type option group (1=fixed, 2=mobile)
1320 * @param bool $passPhoneTypeInContactDetails
1321 * @param array $additionalContactParams additional contact creation params
1323 public function createSendSmsTest($phoneType = 0, $passPhoneTypeInContactDetails = FALSE, $additionalContactParams = []) {
1324 $provider = civicrm_api3('SmsProvider', 'create', [
1325 'name' => "CiviTestSMSProvider",
1331 "api_params" => "a=1",
1332 "is_default" => "1",
1337 $smsProviderParams['provider_id'] = $provider['id'];
1340 $contactId = $this->individualCreate();
1341 if (!empty($additionalContactParams)) {
1342 $this->callAPISuccess('contact', 'create', ['id' => $contactId] +
$additionalContactParams);
1344 $contactsResult = $this->callApiSuccess('contact', 'get', ['id' => $contactId, 'version' => $this->_apiversion
]);
1345 $contactDetails = $contactsResult['values'];
1347 // Get contactIds from contact details
1348 foreach ($contactDetails as $contact) {
1349 $contactIds[] = $contact['contact_id'];
1352 $activityParams['sms_text_message'] = __FUNCTION__
. ' text';
1353 $activityParams['activity_subject'] = __FUNCTION__
. ' subject';
1355 // Get a "logged in" user to set as source of Sms.
1356 $session = CRM_Core_Session
::singleton();
1357 $sourceContactId = $session->get('userID');
1360 $this->_testSmsContactId
= $this->createLoggedInUser();
1362 // Give user permission to 'send SMS'
1363 CRM_Core_Config
::singleton()->userPermissionClass
->permissions
= ['access CiviCRM', 'send SMS'];
1365 // Create a phone number
1366 switch ($phoneType) {
1372 // Create a mobile phone number
1373 $phone = civicrm_api3('Phone', 'create', [
1374 'contact_id' => $contactId,
1376 'phone_type_id' => "Mobile",
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'];
1385 // Create a fixed phone number
1386 $phone = civicrm_api3('Phone', 'create', [
1387 'contact_id' => $contactId,
1389 'phone_type_id' => "Phone",
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'];
1398 // Now run the actual test
1399 list($sent, $activityId, $success) = CRM_Activity_BAO_Activity
::sendSms(
1407 return [$sent, $activityId, $success];
1410 protected function createTestActivities() {
1411 $this->loadXMLDataSet(dirname(__FILE__
) . '/activities_for_dashboard_count.xml');
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']);
1417 * ACL HOOK implementation for various tests
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)";
1426 public function testCaseTokens() {
1427 $caseTest = new CiviCaseTestCase();
1429 // Create a contact and contactDetails array.
1430 $contactId = $this->individualCreate();
1432 // create a case for this user
1433 $result = $this->callAPISuccess('Case', 'create', [
1434 'contact_id' => $contactId,
1435 'case_type_id' => '1',
1436 'subject' => "my case",
1437 'status_id' => "Open",
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);
1444 $this->assertTrue(strpos($html_message, 'id: ' . $caseId) !== 0);
1445 $this->assertTrue(strpos($html_message, 'subject: my case') !== 0);
1446 $caseTest->tearDown();
1449 public function testSendEmailWithCaseId() {
1450 $caseTest = new CiviCaseTestCase();
1452 // Create a contact and contactDetails array.
1453 $contactId = $this->individualCreate();
1454 $contact = $this->callAPISuccess('Contact', 'get', ['id' => $contactId]);
1456 // create a logged in USER since the code references it for sendEmail user.
1457 $this->createLoggedInUser();
1458 CRM_Core_Config
::singleton()->userPermissionClass
->permissions
= ['view all contacts', 'access CiviCRM', 'access all cases and activities', 'administer CiviCase'];
1459 $session = CRM_Core_Session
::singleton();
1460 $loggedInUser = $session->get('userID');
1462 // create a case for this user
1463 $result = $this->callAPISuccess('Case', 'create', [
1464 'contact_id' => $contactId,
1465 'case_type_id' => 1,
1466 'subject' => "my case",
1467 'status_id' => "Open",
1470 $caseId = $result['id'];
1472 $subject = __FUNCTION__
. ' subject {case.subject}';
1473 $html = __FUNCTION__
. ' html {case.subject}';
1474 $text = __FUNCTION__
. ' text';
1476 $mut = new CiviMailUtils($this, TRUE);
1477 list($sent, $activity_id) = $email_result = CRM_Activity_BAO_Activity
::sendEmail(
1482 $contact['values'][$contactId]['email'],
1484 $from = __FUNCTION__
. '@example.com',
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']);
1501 * Adds a case with one activity.
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__
);
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) {
1513 'name' => 'test_case_type',
1514 'title' => 'test_case_type',
1517 "activityTypes" => [
1518 ["name" => "Open Case", "max_instances" => "1"],
1519 ["name" => "Meeting"],
1523 "name" => "standard_timeline",
1524 "label" => "Standard Timeline",
1526 "activityTypes" => [
1528 "name" => "Open Case",
1529 "status" => "Completed",
1530 "label" => "Open Case",
1531 "default_assignee_type" => "1",
1536 "timelineActivityTypes" => [
1538 "name" => "Open Case",
1539 "status" => "Completed",
1540 "label" => "Open Case",
1541 "default_assignee_type" => "1",
1546 "name" => "Case Coordinator",
1553 $case_type_id = $this->callAPISuccess('CaseType', 'create', $params)['id'];
1556 // Create a case with Contact #3 as the client.
1557 $case_id = civicrm_api3('case', 'get', ['subject' => 'test case 1'])['id'] ??
NULL;
1561 'subject' => 'test case 1',
1563 'status_id' => 'Open',
1564 'case_type_id' => $case_type_id,
1567 $case_id = $this->callAPISuccess('case', 'create', $params)['id'];
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',
1583 * Change setting, and the cache of it.
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;