Merge pull request #14249 from yashodha/959_dev
[civicrm-core.git] / tests / phpunit / CRM / Activity / BAO / ActivityTest.php
1 <?php
2
3 /**
4 * Class CRM_Activity_BAO_ActivityTest
5 * @group headless
6 */
7 class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase {
8
9 public function setUp() {
10 parent::setUp();
11 $this->prepareForACLs();
12 CRM_Core_Config::singleton()->userPermissionClass->permissions = array('view all contacts', 'access CiviCRM');
13 $this->setupForSmsTests();
14 }
15
16 /**
17 * Clean up after tests.
18 */
19 public function tearDown() {
20 $tablesToTruncate = array(
21 'civicrm_activity',
22 'civicrm_activity_contact',
23 'civicrm_uf_match',
24 'civicrm_campaign',
25 'civicrm_email',
26 );
27 $this->quickCleanup($tablesToTruncate);
28 $this->cleanUpAfterACLs();
29 $this->setupForSmsTests(TRUE);
30 parent::tearDown();
31 }
32
33 /**
34 * Test case for create() method.
35 */
36 public function testCreate() {
37 $contactId = $this->individualCreate();
38
39 $params = array(
40 'source_contact_id' => $contactId,
41 'subject' => 'Scheduling Meeting',
42 'activity_type_id' => 2,
43 );
44
45 CRM_Activity_BAO_Activity::create($params);
46
47 $activityId = $this->assertDBNotNull('CRM_Activity_DAO_Activity', 'Scheduling Meeting', 'id',
48 'subject', 'Database check for created activity.'
49 );
50
51 // Now call create() to modify an existing Activity.
52 $params = array(
53 'id' => $activityId,
54 'source_contact_id' => $contactId,
55 'subject' => 'Scheduling Interview',
56 'activity_type_id' => 3,
57 );
58
59 CRM_Activity_BAO_Activity::create($params);
60
61 $activityTypeId = $this->assertDBNotNull('CRM_Activity_DAO_Activity', 'Scheduling Interview',
62 'activity_type_id',
63 'subject', 'Database check on updated activity record.'
64 );
65 $this->assertEquals($activityTypeId, 3, 'Verify activity type id is 3.');
66
67 $this->contactDelete($contactId);
68 }
69
70 /**
71 * Test case for getContactActivity() method.
72 *
73 * getContactActivity() method get activities detail for given target contact id.
74 */
75 public function testGetContactActivity() {
76 $contactId = $this->individualCreate();
77 $params = array(
78 'first_name' => 'liz',
79 'last_name' => 'hurleey',
80 );
81 $targetContactId = $this->individualCreate($params);
82
83 $params = array(
84 'source_contact_id' => $contactId,
85 'subject' => 'Scheduling Meeting',
86 'activity_type_id' => 2,
87 'target_contact_id' => array($targetContactId),
88 'activity_date_time' => date('Ymd'),
89 );
90
91 $this->callAPISuccess('Activity', 'create', $params);
92
93 $activityId = $this->assertDBNotNull('CRM_Activity_DAO_Activity', 'Scheduling Meeting',
94 'id',
95 'subject', 'Database check for created activity.'
96 );
97
98 // @todo - remove this deprecated functions
99 $activities = CRM_Activity_BAO_Activity::getContactActivity($targetContactId);
100
101 $this->assertEquals($activities[$activityId]['subject'], 'Scheduling Meeting', 'Verify activity subject is correct.');
102
103 $this->contactDelete($contactId);
104 $this->contactDelete($targetContactId);
105 }
106
107 /**
108 * Test case for retrieve() method.
109 *
110 * Retrieve($params, $defaults) method return activity detail for given params
111 * and set defaults.
112 */
113 public function testRetrieve() {
114 $contactId = $this->individualCreate();
115 $params = array(
116 'first_name' => 'liz',
117 'last_name' => 'hurleey',
118 );
119 $targetContactId = $this->individualCreate($params);
120
121 $params = array(
122 'source_contact_id' => $contactId,
123 'subject' => 'Scheduling Meeting',
124 'activity_type_id' => 2,
125 'target_contact_id' => array($targetContactId),
126 'activity_date_time' => date('Ymd'),
127 );
128
129 CRM_Activity_BAO_Activity::create($params);
130
131 $this->assertDBNotNull('CRM_Activity_DAO_Activity', 'Scheduling Meeting', 'id',
132 'subject', 'Database check for created activity.'
133 );
134
135 $this->assertDBNotNull('CRM_Activity_DAO_ActivityContact', $targetContactId,
136 'id', 'contact_id',
137 'Database check for created activity target.'
138 );
139
140 $defaults = array();
141 $activity = CRM_Activity_BAO_Activity::retrieve($params, $defaults);
142
143 $this->assertEquals($activity->subject, 'Scheduling Meeting', 'Verify activity subject is correct.');
144 $this->assertEquals($activity->activity_type_id, 2, 'Verify activity type id is correct.');
145 $this->assertEquals($defaults['source_contact_id'], $contactId, 'Verify source contact id is correct.');
146
147 $this->assertEquals($defaults['subject'], 'Scheduling Meeting', 'Verify activity subject is correct.');
148 $this->assertEquals($defaults['activity_type_id'], 2, 'Verify activity type id is correct.');
149
150 $this->assertEquals($defaults['target_contact'][0], $targetContactId, 'Verify target contact id is correct.');
151
152 $this->contactDelete($contactId);
153 $this->contactDelete($targetContactId);
154 }
155
156 /**
157 * Test case for deleteActivity() method.
158 *
159 * deleteActivity($params) method deletes activity for given params.
160 */
161 public function testDeleteActivity() {
162 $contactId = $this->individualCreate();
163 $params = array(
164 'first_name' => 'liz',
165 'last_name' => 'hurleey',
166 );
167 $targetContactId = $this->individualCreate($params);
168
169 $params = array(
170 'source_contact_id' => $contactId,
171 'source_record_id' => $contactId,
172 'subject' => 'Scheduling Meeting',
173 'activity_type_id' => 2,
174 'target_contact_id' => array($targetContactId),
175 'activity_date_time' => date('Ymd'),
176 );
177
178 CRM_Activity_BAO_Activity::create($params);
179
180 $this->assertDBNotNull('CRM_Activity_DAO_Activity', 'Scheduling Meeting', 'id',
181 'subject', 'Database check for created activity.'
182 );
183
184 $this->assertDBNotNull('CRM_Activity_DAO_ActivityContact', $targetContactId,
185 'id', 'contact_id',
186 'Database check for created activity target.'
187 );
188 $params = array(
189 'source_contact_id' => $contactId,
190 'source_record_id' => $contactId,
191 'subject' => 'Scheduling Meeting',
192 'activity_type_id' => 2,
193 );
194
195 CRM_Activity_BAO_Activity::deleteActivity($params);
196
197 $this->assertDBNull('CRM_Activity_DAO_Activity', 'Scheduling Meeting', 'id',
198 'subject', 'Database check for deleted activity.'
199 );
200 $this->contactDelete($contactId);
201 $this->contactDelete($targetContactId);
202 }
203
204 /**
205 * Test case for deleteActivityTarget() method.
206 *
207 * deleteActivityTarget($activityId) method deletes activity target for given activity id.
208 */
209 public function testDeleteActivityTarget() {
210 $contactId = $this->individualCreate();
211 $params = array(
212 'first_name' => 'liz',
213 'last_name' => 'hurleey',
214 );
215 $targetContactId = $this->individualCreate($params);
216
217 $params = array(
218 'source_contact_id' => $contactId,
219 'subject' => 'Scheduling Meeting',
220 'activity_type_id' => 2,
221 'target_contact_id' => array($targetContactId),
222 'activity_date_time' => date('Ymd'),
223 );
224
225 CRM_Activity_BAO_Activity::create($params);
226
227 $activityId = $this->assertDBNotNull('CRM_Activity_DAO_Activity', 'Scheduling Meeting', 'id',
228 'subject', 'Database check for created activity.'
229 );
230
231 $this->assertDBNotNull('CRM_Activity_DAO_ActivityContact', $targetContactId,
232 'id', 'contact_id',
233 'Database check for created activity target.'
234 );
235
236 CRM_Activity_BAO_Activity::deleteActivityContact($activityId, 3);
237
238 $this->assertDBNull('CRM_Activity_DAO_ActivityContact', $targetContactId, 'id',
239 'contact_id', 'Database check for deleted activity target.'
240 );
241
242 $this->contactDelete($contactId);
243 $this->contactDelete($targetContactId);
244 }
245
246 /**
247 * Test case for deleteActivityAssignment() method.
248 *
249 * deleteActivityAssignment($activityId) method deletes activity assignment for given activity id.
250 */
251 public function testDeleteActivityAssignment() {
252 $contactId = $this->individualCreate();
253 $params = array(
254 'first_name' => 'liz',
255 'last_name' => 'hurleey',
256 );
257 $assigneeContactId = $this->individualCreate($params);
258
259 $params = array(
260 'source_contact_id' => $contactId,
261 'subject' => 'Scheduling Meeting',
262 'activity_type_id' => 2,
263 'assignee_contact_id' => array($assigneeContactId),
264 'activity_date_time' => date('Ymd'),
265 );
266
267 CRM_Activity_BAO_Activity::create($params);
268
269 $activityId = $this->assertDBNotNull('CRM_Activity_DAO_Activity', 'Scheduling Meeting', 'id',
270 'subject', 'Database check for created activity.'
271 );
272
273 $this->assertDBNotNull('CRM_Activity_DAO_ActivityContact',
274 $assigneeContactId, 'id', 'contact_id',
275 'Database check for created activity assignment.'
276 );
277
278 CRM_Activity_BAO_Activity::deleteActivityContact($activityId, 1);
279
280 $this->assertDBNull('CRM_Activity_DAO_ActivityContact', $assigneeContactId, 'id',
281 'contact_id', 'Database check for deleted activity assignment.'
282 );
283
284 $this->contactDelete($contactId);
285 $this->contactDelete($assigneeContactId);
286 }
287
288 /**
289 * Test getActivities BAO method for getting count.
290 */
291 public function testGetActivitiesCountForAdminDashboard() {
292 $this->setUpForActivityDashboardTests();
293 $activityCount = CRM_Activity_BAO_Activity::getActivitiesCount($this->_params);
294 $this->assertEquals(8, $activityCount);
295 }
296
297 /**
298 * Test getActivities BAO method for getting count
299 */
300 public function testGetActivitiesCountforNonAdminDashboard() {
301 $this->createTestActivities();
302
303 $params = array(
304 'contact_id' => 9,
305 'admin' => FALSE,
306 'caseId' => NULL,
307 'context' => 'home',
308 'activity_type_id' => NULL,
309 // for dashlet the Scheduled status is set by default
310 'activity_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'status_id', 'Scheduled'),
311 'offset' => 0,
312 'rowCount' => 0,
313 'sort' => NULL,
314 );
315
316 //since we are loading activities from dataset, we know total number of activities for this contact
317 // 5 activities ( 2 scheduled, 3 Completed ), note that dashboard shows only scheduled activities
318 $this->assertEquals(2, CRM_Activity_BAO_Activity::getActivitiesCount($params));
319 }
320
321 /**
322 * Test getActivities BAO method for getting count
323 */
324 public function testGetActivitiesCountforContactSummary() {
325 $this->createTestActivities();
326
327 $params = array(
328 'contact_id' => 9,
329 'admin' => FALSE,
330 'caseId' => NULL,
331 'context' => 'activity',
332 'activity_type_id' => NULL,
333 'offset' => 0,
334 'rowCount' => 0,
335 'sort' => NULL,
336 );
337
338 //since we are loading activities from dataset, we know total number of activities for this contact
339 // 5 activities, Contact Summary should show all activities
340 $this->assertEquals(5, CRM_Activity_BAO_Activity::getActivitiesCount($params));
341 }
342
343 /**
344 * CRM-18706 - Test Include/Exclude Activity Filters
345 */
346 public function testActivityFilters() {
347 $this->createTestActivities();
348 Civi::settings()->set('preserve_activity_tab_filter', 1);
349 $this->createLoggedInUser();
350
351 global $_GET;
352 $_GET = array(
353 'cid' => 9,
354 'context' => 'activity',
355 'activity_type_id' => 1,
356 'is_unit_test' => 1,
357 );
358 $expectedFilters = array(
359 'activity_type_filter_id' => 1,
360 );
361
362 list($activities, $activityFilter) = CRM_Activity_Page_AJAX::getContactActivity();
363 //Assert whether filters are correctly set.
364 $this->checkArrayEquals($expectedFilters, $activityFilter);
365 // This should include activities of type Meeting only.
366 foreach ($activities['data'] as $value) {
367 $this->assertContains('Meeting', $value['activity_type']);
368 }
369 unset($_GET['activity_type_id']);
370
371 $_GET['activity_type_exclude_id'] = $expectedFilters['activity_type_exclude_filter_id'] = 1;
372 list($activities, $activityFilter) = CRM_Activity_Page_AJAX::getContactActivity();
373 $this->assertEquals(['activity_type_exclude_filter_id' => 1], $activityFilter);
374 // None of the activities should be of type Meeting.
375 foreach ($activities['data'] as $value) {
376 $this->assertNotContains('Meeting', $value['activity_type']);
377 }
378 }
379
380 /**
381 * Test getActivities BAO method for getting count
382 */
383 public function testGetActivitiesCountforContactSummaryWithNoActivities() {
384 $this->createTestActivities();
385
386 $params = array(
387 'contact_id' => 17,
388 'admin' => FALSE,
389 'caseId' => NULL,
390 'context' => 'home',
391 'activity_type_id' => NULL,
392 'offset' => 0,
393 'rowCount' => 0,
394 'sort' => NULL,
395 );
396
397 //since we are loading activities from dataset, we know total number of activities for this contact
398 // this contact does not have any activity
399 $this->assertEquals(0, CRM_Activity_BAO_Activity::getActivitiesCount($params));
400 }
401
402 /**
403 * Test getActivities BAO method.
404 */
405 public function testGetActivitiesForAdminDashboard() {
406 $this->setUpForActivityDashboardTests();
407 $activitiesNew = CRM_Activity_BAO_Activity::getActivities($this->_params);
408 // $this->assertEquals($activities, $activitiesDeprecatedFn);
409
410 //since we are loading activities from dataset, we know total number of activities
411 // with no contact ID and there should be 8 schedule activities shown on dashboard
412 $count = 8;
413 foreach (array($activitiesNew) as $activities) {
414 $this->assertEquals($count, count($activities));
415
416 foreach ($activities as $key => $value) {
417 $this->assertEquals($value['subject'], "subject {$key}", 'Verify activity subject is correct.');
418 $this->assertEquals($value['activity_type_id'], 2, 'Verify activity type is correct.');
419 $this->assertEquals($value['status_id'], 1, 'Verify all activities are scheduled.');
420 }
421 }
422 }
423
424 /**
425 * Test getActivities BAO method.
426 */
427 public function testGetActivitiesForAdminDashboardNoViewContacts() {
428 CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM');
429 $this->setUpForActivityDashboardTests();
430 foreach (array(CRM_Activity_BAO_Activity::getActivities($this->_params)) as $activities) {
431 // Skipped until we get back to the upgraded version properly.
432 $this->assertEquals(0, count($activities));
433 }
434 }
435
436 /**
437 * Test getActivities BAO method.
438 */
439 public function testGetActivitiesForAdminDashboardAclLimitedViewContacts() {
440 CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM');
441 $this->allowedContacts = array(1, 3, 4, 5);
442 $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereMultipleContacts'));
443 $this->setUpForActivityDashboardTests();
444 $this->assertEquals(7, count(CRM_Activity_BAO_Activity::getActivities($this->_params)));
445 }
446
447 /**
448 * Test getActivities BAO method.
449 */
450 public function testGetActivitiesforNonAdminDashboard() {
451 $this->createTestActivities();
452
453 $contactID = 9;
454 $params = array(
455 'contact_id' => $contactID,
456 'admin' => FALSE,
457 'caseId' => NULL,
458 'context' => 'home',
459 'activity_type_id' => NULL,
460 // for dashlet the Scheduled status is set by default
461 'activity_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'status_id', 'Scheduled'),
462 'offset' => 0,
463 'rowCount' => 0,
464 'sort' => NULL,
465 );
466
467 foreach (array(CRM_Activity_BAO_Activity::getActivities($params)) as $activities) {
468 //since we are loading activities from dataset, we know total number of activities for this contact
469 // 5 activities ( 2 scheduled, 3 Completed ), note that dashboard shows only scheduled activities
470 $count = 2;
471 $this->assertEquals($count, count($activities));
472
473 foreach ($activities as $key => $value) {
474 $this->assertEquals($value['subject'], "subject {$key}", 'Verify activity subject is correct.');
475 $this->assertEquals($value['activity_type_id'], 2, 'Verify activity type is correct.');
476 $this->assertEquals($value['status_id'], 1, 'Verify all activities are scheduled.');
477
478 if ($key == 3) {
479 $this->assertArrayHasKey($contactID, $value['target_contact_name']);
480 }
481 elseif ($key == 4) {
482 $this->assertArrayHasKey($contactID, $value['assignee_contact_name']);
483 }
484 }
485 }
486 }
487
488 /**
489 * Test target contact count.
490 */
491 public function testTargetCountforContactSummary() {
492 $targetCount = 5;
493 $contactId = $this->individualCreate();
494 $targetContactIDs = array();
495 for ($i = 0; $i < $targetCount; $i++) {
496 $targetContactIDs[] = $this->individualCreate(array(), $i);
497 }
498 // Create activities with 5 target contacts.
499 $activityParams = array(
500 'source_contact_id' => $contactId,
501 'target_contact_id' => $targetContactIDs,
502 );
503 $this->activityCreate($activityParams);
504
505 $params = array(
506 'contact_id' => $contactId,
507 'context' => 'activity',
508 );
509 $activities = CRM_Activity_BAO_Activity::getActivities($params);
510 //verify target count
511 $this->assertEquals($targetCount, $activities[1]['target_contact_count']);
512 $this->assertEquals([$targetContactIDs[0] => 'Anderson, Anthony'], $activities[1]['target_contact_name']);
513 $this->assertEquals('Anderson, Anthony', $activities[1]['source_contact_name']);
514 $this->assertEquals('Anderson, Anthony', $activities[1]['assignee_contact_name'][4]);
515 }
516
517 /**
518 * Test getActivities BAO method.
519 */
520 public function testGetActivitiesforContactSummaryWithSortOptions() {
521 $this->createTestActivities();
522 $params = [
523 'contact_id' => 9,
524 'admin' => FALSE,
525 'caseId' => NULL,
526 'context' => 'activity',
527 'activity_type_id' => NULL,
528 'offset' => 0,
529 'rowCount' => 0,
530 'sort' => 'source_contact_name desc',
531 ];
532
533 $activities = CRM_Activity_BAO_Activity::getActivities($params);
534 $alphaOrder = ['Test Contact 11', 'Test Contact 12', 'Test Contact 3', 'Test Contact 4', 'Test Contact 9'];
535 foreach ($activities as $activity) {
536 $this->assertEquals(array_pop($alphaOrder), $activity['source_contact_name']);
537 }
538
539 }
540
541 /**
542 * Test getActivities BAO method.
543 */
544 public function testGetActivitiesForContactSummary() {
545 $this->createTestActivities();
546
547 $contactID = 9;
548 $params = array(
549 'contact_id' => $contactID,
550 'admin' => FALSE,
551 'caseId' => NULL,
552 'context' => 'activity',
553 'activity_type_id' => NULL,
554 'offset' => 0,
555 'rowCount' => 0,
556 );
557
558 //since we are loading activities from dataset, we know total number of activities for this contact
559 // 5 activities, Contact Summary should show all activities
560 $count = 5;
561 $activities = CRM_Activity_BAO_Activity::getActivities($params);
562 $this->assertEquals($count, count($activities));
563 foreach ($activities as $key => $value) {
564 $this->assertEquals($value['subject'], "subject {$key}", 'Verify activity subject is correct.');
565
566 if ($key > 8) {
567 $this->assertEquals($value['status_id'], 2, 'Verify all activities are scheduled.');
568 }
569 else {
570 $this->assertEquals($value['status_id'], 1, 'Verify all activities are scheduled.');
571 }
572
573 if ($key === 12) {
574 $this->assertEquals($value['activity_type'], 'Bulk Email', 'Verify activity type is correct.');
575 $this->assertEquals('(2 recipients)', $value['recipients']);
576 $targetContactID = key($value['target_contact_name']);
577 // The 2 targets have ids 10 & 11. Since they are not sorted it could be either on some systems.
578 $this->assertTrue(in_array($targetContactID, [10, 11]));
579 }
580 elseif ($key > 8) {
581 $this->assertEquals($value['activity_type_id'], 1, 'Verify activity type is correct.');
582 }
583 else {
584 $this->assertEquals($value['activity_type_id'], 2, 'Verify activity type is correct.');
585 }
586
587 if ($key == 3) {
588 $this->assertEquals([$contactID => 'Test Contact ' . $contactID], $value['target_contact_name']);
589 }
590 elseif ($key == 4) {
591 $this->assertArrayHasKey($contactID, $value['assignee_contact_name']);
592 }
593 }
594 }
595
596 /**
597 * Test getActivities BAO method.
598 */
599 public function testGetActivitiesforContactSummaryWithActivities() {
600 $this->createTestActivities();
601
602 // parameters for different test cases, check each array key for the specific test-case
603 $testCases = array(
604 'with-no-activity' => array(
605 'params' => array(
606 'contact_id' => 17,
607 'admin' => FALSE,
608 'caseId' => NULL,
609 'context' => 'home',
610 'activity_type_id' => NULL,
611 'offset' => 0,
612 'rowCount' => 0,
613 'sort' => NULL,
614 ),
615 ),
616 'with-activity' => array(
617 'params' => array(
618 'contact_id' => 1,
619 'admin' => FALSE,
620 'caseId' => NULL,
621 'context' => 'home',
622 'activity_type_id' => NULL,
623 'offset' => 0,
624 'rowCount' => 0,
625 'sort' => NULL,
626 ),
627 ),
628 'with-activity_type' => array(
629 'params' => array(
630 'contact_id' => 3,
631 'admin' => FALSE,
632 'caseId' => NULL,
633 'context' => 'home',
634 'activity_type_id' => 2,
635 'offset' => 0,
636 'rowCount' => 0,
637 'sort' => NULL,
638 ),
639 ),
640 'exclude-all-activity_type' => array(
641 'params' => array(
642 'contact_id' => 3,
643 'admin' => FALSE,
644 'caseId' => NULL,
645 'context' => 'home',
646 'activity_type_exclude_id' => array(1, 2),
647 'offset' => 0,
648 'rowCount' => 0,
649 'sort' => NULL,
650 ),
651 ),
652 'sort-by-subject' => array(
653 'params' => array(
654 'contact_id' => 1,
655 'admin' => FALSE,
656 'caseId' => NULL,
657 'context' => 'home',
658 'activity_type_id' => NULL,
659 'offset' => 0,
660 'rowCount' => 0,
661 'sort' => 'subject DESC',
662 ),
663 ),
664 );
665
666 foreach ($testCases as $caseName => $testCase) {
667 $activityCount = CRM_Activity_BAO_Activity::getActivitiesCount($testCase['params']);
668 $activitiesNew = CRM_Activity_BAO_Activity::getActivities($testCase['params']);
669
670 foreach (array($activitiesNew) as $activities) {
671 //$this->assertEquals($activityCount, CRM_Activity_BAO_Activity::getActivitiesCount($testCase['params']));
672 if ($caseName == 'with-no-activity') {
673 $this->assertEquals(0, count($activities));
674 $this->assertEquals(0, $activityCount);
675 }
676 elseif ($caseName == 'with-activity') {
677 // contact id 1 is assigned as source, target and assignee for activity id 1, 7 and 8 respectively
678 $this->assertEquals(3, count($activities));
679 $this->assertEquals(3, $activityCount);
680 $this->assertEquals(1, $activities[1]['source_contact_id']);
681 // @todo - this is a discrepancy between old & new - review.
682 //$this->assertEquals(TRUE, array_key_exists(1, $activities[7]['target_contact_name']));
683 $this->assertEquals(TRUE, array_key_exists(1, $activities[8]['assignee_contact_name']));
684 }
685 elseif ($caseName == 'with-activity_type') {
686 // contact id 3 for activity type 2 is assigned as assignee, source and target for
687 // activity id 1, 3 and 8 respectively
688 $this->assertEquals(3, count($activities));
689 $this->assertEquals(3, $activityCount);
690 // ensure activity type id is 2
691 $this->assertEquals(2, $activities[1]['activity_type_id']);
692 $this->assertEquals(3, $activities[3]['source_contact_id']);
693 // @todo review inconsistency between 2 versions.
694 // $this->assertEquals(TRUE, array_key_exists(3, $activities[8]['target_contact_name']));
695 $this->assertEquals(TRUE, array_key_exists(3, $activities[1]['assignee_contact_name']));
696 }
697 if ($caseName == 'exclude-all-activity_type') {
698 $this->assertEquals(0, count($activities));
699 $this->assertEquals(0, $activityCount);
700 }
701 if ($caseName == 'sort-by-subject') {
702 $this->assertEquals(3, count($activities));
703 $this->assertEquals(3, $activityCount);
704 // activities should be order by 'subject DESC'
705 $subjectOrder = array(
706 'subject 8',
707 'subject 7',
708 'subject 1',
709 );
710 $count = 0;
711 foreach ($activities as $activity) {
712 $this->assertEquals($subjectOrder[$count], $activity['subject']);
713 $count++;
714 }
715 }
716 }
717 }
718 }
719
720 /**
721 * CRM-20793 : Test getActivities by using activity date and status filter
722 */
723 public function testByActivityDateAndStatus() {
724 CRM_Core_Config::singleton()->userPermissionClass->permissions = ['view all contacts', 'access CiviCRM'];
725 $this->createTestActivities();
726
727 // activity IDs catagorised by date
728 $lastWeekActivities = array(1, 2, 3);
729 $todayActivities = array(4, 5, 6, 7);
730 $lastTwoMonthsActivities = array(8, 9, 10, 11);
731 $lastOrNextYearActivities = array(12, 13, 14, 15, 16);
732
733 // date values later used to set activity date value
734 $lastWeekDate = date('YmdHis', strtotime('1 week ago'));
735 $today = date('YmdHis');
736 $lastTwoMonthAgoDate = date('YmdHis', strtotime('2 months ago'));
737 // if current month is Jan then choose next year date otherwise the search result will include
738 // the previous week and last two months activities which are still in previous year and hence leads to improper result
739 $lastOrNextYearDate = (date('M') == 'Jan') ? date('YmdHis', strtotime('+1 year')) : date('YmdHis', strtotime('1 year ago'));
740 for ($i = 1; $i <= 16; $i++) {
741 if (in_array($i, $lastWeekActivities)) {
742 $date = $lastWeekDate;
743 }
744 elseif (in_array($i, $lastTwoMonthsActivities)) {
745 $date = $lastTwoMonthAgoDate;
746 }
747 elseif (in_array($i, $lastOrNextYearActivities)) {
748 $date = $lastOrNextYearDate;
749 }
750 elseif (in_array($i, $todayActivities)) {
751 $date = $today;
752 }
753 $this->callAPISuccess('Activity', 'create', array(
754 'id' => $i,
755 'activity_date_time' => $date,
756 ));
757 }
758
759 // parameters for different test cases, check each array key for the specific test-case
760 $testCases = array(
761 'todays-activity' => array(
762 'params' => array(
763 'contact_id' => 1,
764 'admin' => TRUE,
765 'caseId' => NULL,
766 'context' => 'activity',
767 'activity_date_time_relative' => 'this.day',
768 'activity_type_id' => NULL,
769 'offset' => 0,
770 'rowCount' => 0,
771 'sort' => NULL,
772 ),
773 ),
774 'todays-activity-filtered-by-range' => array(
775 'params' => array(
776 'contact_id' => 1,
777 'admin' => TRUE,
778 'caseId' => NULL,
779 'context' => 'activity',
780 'activity_date_time_low' => date('Y/m/d', strtotime('yesterday')),
781 'activity_date_time_high' => date('Y/m/d'),
782 'activity_type_id' => NULL,
783 'offset' => 0,
784 'rowCount' => 0,
785 'sort' => NULL,
786 ),
787 ),
788 'last-week-activity' => array(
789 'params' => array(
790 'contact_id' => 1,
791 'admin' => TRUE,
792 'caseId' => NULL,
793 'context' => 'activity',
794 'activity_date_time_relative' => 'previous.week',
795 'activity_type_id' => NULL,
796 'offset' => 0,
797 'rowCount' => 0,
798 'sort' => NULL,
799 ),
800 ),
801 'this-quarter-activity' => array(
802 'params' => array(
803 'contact_id' => 1,
804 'admin' => TRUE,
805 'caseId' => NULL,
806 'context' => 'activity',
807 'activity_date_time_relative' => 'this.quarter',
808 'activity_type_id' => NULL,
809 'offset' => 0,
810 'rowCount' => 0,
811 'sort' => NULL,
812 ),
813 ),
814 'activity-of-all-statuses' => array(
815 'params' => array(
816 'contact_id' => 1,
817 'admin' => TRUE,
818 'caseId' => NULL,
819 'context' => 'activity',
820 'activity_status_id' => '1,2',
821 'activity_type_id' => NULL,
822 'offset' => 0,
823 'rowCount' => 0,
824 'sort' => NULL,
825 ),
826 ),
827 );
828
829 foreach ($testCases as $caseName => $testCase) {
830 CRM_Utils_Date::convertFormDateToApiFormat($testCase['params'], 'activity_date_time', FALSE);
831 $activities = CRM_Activity_BAO_Activity::getActivities($testCase['params']);
832 $activityCount = CRM_Activity_BAO_Activity::getActivitiesCount($testCase['params']);
833 asort($activities);
834 $activityIDs = array_keys($activities);
835
836 if ($caseName == 'todays-activity' || $caseName == 'todays-activity-filtered-by-range') {
837 // Only one of the 4 activities today relates to contact id 1.
838 $this->assertEquals(1, $activityCount);
839 $this->assertEquals(1, count($activities));
840 $this->assertEquals([7], array_keys($activities));
841 }
842 elseif ($caseName == 'last-week-activity') {
843 // Only one of the 3 activities today relates to contact id 1.
844 $this->assertEquals(1, $activityCount);
845 $this->assertEquals(1, count($activities));
846 $this->assertEquals([1], $activityIDs);
847 }
848 elseif ($caseName == 'lhis-quarter-activity') {
849 $this->assertEquals(count($lastTwoMonthsActivities), $activityCount);
850 $this->assertEquals(count($lastTwoMonthsActivities), count($activities));
851 $this->checkArrayEquals($lastTwoMonthsActivities, $activityIDs);
852 }
853 elseif ($caseName == 'last-or-next-year-activity') {
854 $this->assertEquals(count($lastOrNextYearActivities), $activityCount);
855 $this->assertEquals(count($lastOrNextYearActivities), count($activities));
856 $this->checkArrayEquals($lastOrNextYearActivities, $activityIDs);
857 }
858 elseif ($caseName == 'activity-of-all-statuses') {
859 $this->assertEquals(3, $activityCount);
860 $this->assertEquals(3, count($activities));
861 }
862 }
863 }
864
865 /**
866 * @dataProvider getActivityDateData
867 */
868 public function testActivityRelativeDateFilter($params, $expected) {
869 $thisYear = date('Y');
870 $dates = [
871 date('Y-m-d', strtotime(($thisYear - 1) . '-01-01')),
872 date('Y-m-d', strtotime(($thisYear - 1) . '-12-31')),
873 date('Y-m-d', strtotime($thisYear . '-01-01')),
874 date('Y-m-d', strtotime($thisYear . '-12-31')),
875 date('Y-m-d', strtotime(($thisYear + 1) . '-01-01')),
876 date('Y-m-d', strtotime(($thisYear + 1) . '-12-31')),
877 ];
878 foreach ($dates as $date) {
879 $this->activityCreate(['activity_date_time' => $date]);
880 }
881 $activitiesDep = CRM_Activity_BAO_Activity::getActivities($params);
882 $activityCount = CRM_Activity_BAO_Activity::getActivitiesCount($params);
883 $this->assertEquals(count($activitiesDep), $activityCount);
884 foreach ($activitiesDep as $activity) {
885 $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']));
886 $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']));
887 }
888
889 }
890
891 /**
892 * Get activity date data.
893 *
894 * Later we might migrate rework the rest of
895 * testByActivityDateAndStatus
896 * to use data provider methodology as it's way complex!
897 *
898 * @return array
899 */
900 public function getActivityDateData() {
901 return [
902 'last-year-activity' => [
903 'params' => [
904 'contact_id' => 1,
905 'admin' => TRUE,
906 'caseId' => NULL,
907 'context' => 'activity',
908 'activity_date_relative' => 'previous.year',
909 'activity_type_id' => NULL,
910 'offset' => 0,
911 'rowCount' => 0,
912 'sort' => NULL,
913 ],
914 'expected' => [
915 'count' => 2,
916 'earliest' => strtotime('first day of january last year'),
917 'latest' => strtotime('first day of january this year'),
918 ],
919 ],
920 ];
921 }
922
923 /**
924 * CRM-20308: Test from email address when a 'copy of Activity' event occur
925 */
926 public function testEmailAddressOfActivityCopy() {
927 // Case 1: assert the 'From' Email Address of source Actvity Contact ID
928 // create activity with source contact ID which has email address
929 $assigneeContactId = $this->individualCreate();
930 $sourceContactParams = array(
931 'first_name' => 'liz',
932 'last_name' => 'hurleey',
933 'email' => substr(sha1(rand()), 0, 7) . '@testemail.com',
934 );
935 $sourceContactID = $this->individualCreate($sourceContactParams);
936 $sourceDisplayName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $sourceContactID, 'display_name');
937
938 // create an activity using API
939 $params = array(
940 'source_contact_id' => $sourceContactID,
941 'subject' => 'Scheduling Meeting ' . substr(sha1(rand()), 0, 4),
942 'activity_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Meeting'),
943 'assignee_contact_id' => array($assigneeContactId),
944 'activity_date_time' => date('Ymd'),
945 );
946 $activity = $this->callAPISuccess('Activity', 'create', $params);
947
948 // Check that from address is in "Source-Display-Name <source-email>"
949 $formAddress = CRM_Case_BAO_Case::getReceiptFrom($activity['id']);
950 $expectedFromAddress = sprintf("%s <%s>", $sourceDisplayName, $sourceContactParams['email']);
951 $this->assertEquals($expectedFromAddress, $formAddress);
952
953 // Case 2: System Default From Address
954 // but first erase the email address of existing source contact ID
955 $withoutEmailParams = array(
956 'email' => '',
957 );
958 $sourceContactID = $this->individualCreate($withoutEmailParams);
959 $params = array(
960 'source_contact_id' => $sourceContactID,
961 'subject' => 'Scheduling Meeting ' . substr(sha1(rand()), 0, 4),
962 'activity_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Meeting'),
963 'activity_date_time' => date('Ymd'),
964 );
965 $activity = $this->callAPISuccess('Activity', 'create', $params);
966 // fetch domain info
967 $domainInfo = $this->callAPISuccess('Domain', 'getsingle', array('id' => CRM_Core_Config::domainID()));
968
969 $formAddress = CRM_Case_BAO_Case::getReceiptFrom($activity['id']);
970 if (!empty($domainInfo['from_email'])) {
971 $expectedFromAddress = sprintf("%s <%s>", $domainInfo['from_name'], $domainInfo['from_email']);
972 }
973 // Case 3: fetch default Organization Contact email address
974 elseif (!empty($domainInfo['domain_email'])) {
975 $expectedFromAddress = sprintf("%s <%s>", $domainInfo['name'], $domainInfo['domain_email']);
976 }
977 $this->assertEquals($expectedFromAddress, $formAddress);
978
979 // TODO: Case 4 about checking the $formAddress on basis of logged contact ID respectively needs,
980 // to change the domain setting, which isn't straight forward in test environment
981 }
982
983 /**
984 * Set up for testing activity queries.
985 */
986 protected function setUpForActivityDashboardTests() {
987 $this->createTestActivities();
988
989 $this->_params = array(
990 'contact_id' => NULL,
991 'admin' => TRUE,
992 'caseId' => NULL,
993 'context' => 'home',
994 'activity_type_id' => NULL,
995 // for dashlet the Scheduled status is set by default
996 'activity_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'status_id', 'Scheduled'),
997 'offset' => 0,
998 'rowCount' => 0,
999 'sort' => NULL,
1000 );
1001 }
1002
1003 public function testSendEmailBasic() {
1004 $contactId = $this->individualCreate();
1005
1006 // create a logged in USER since the code references it for sendEmail user.
1007 $this->createLoggedInUser();
1008 $session = CRM_Core_Session::singleton();
1009 $loggedInUser = $session->get('userID');
1010
1011 $contact = $this->civicrm_api('contact', 'getsingle', array('id' => $contactId, 'version' => $this->_apiversion));
1012 $contactDetailsIntersectKeys = array(
1013 'contact_id' => '',
1014 'sort_name' => '',
1015 'display_name' => '',
1016 'do_not_email' => '',
1017 'preferred_mail_format' => '',
1018 'is_deceased' => '',
1019 'email' => '',
1020 'on_hold' => '',
1021 );
1022 $contactDetails = array(
1023 array_intersect_key($contact, $contactDetailsIntersectKeys),
1024 );
1025
1026 $subject = __FUNCTION__ . ' subject';
1027 $html = __FUNCTION__ . ' html';
1028 $text = __FUNCTION__ . ' text';
1029 $userID = $loggedInUser;
1030
1031 list($sent, $activity_id) = $email_result = CRM_Activity_BAO_Activity::sendEmail(
1032 $contactDetails,
1033 $subject,
1034 $text,
1035 $html,
1036 $contact['email'],
1037 $userID,
1038 $from = __FUNCTION__ . '@example.com'
1039 );
1040
1041 $activity = $this->civicrm_api('activity', 'getsingle', array('id' => $activity_id, 'version' => $this->_apiversion));
1042 $details = "-ALTERNATIVE ITEM 0-
1043 $html
1044 -ALTERNATIVE ITEM 1-
1045 $text
1046 -ALTERNATIVE END-
1047 ";
1048 $this->assertEquals($activity['details'], $details, 'Activity details does not match.');
1049 $this->assertEquals($activity['subject'], $subject, 'Activity subject does not match.');
1050 }
1051
1052 public function testSendEmailWithCampaign() {
1053 // Create a contact and contactDetails array.
1054 $contactId = $this->individualCreate();
1055
1056 // create a logged in USER since the code references it for sendEmail user.
1057 $this->createLoggedInUser();
1058 $session = CRM_Core_Session::singleton();
1059 $loggedInUser = $session->get('userID');
1060
1061 $contact = $this->civicrm_api('contact', 'getsingle', array('id' => $contactId, 'version' => $this->_apiversion));
1062 $contactDetailsIntersectKeys = array(
1063 'contact_id' => '',
1064 'sort_name' => '',
1065 'display_name' => '',
1066 'do_not_email' => '',
1067 'preferred_mail_format' => '',
1068 'is_deceased' => '',
1069 'email' => '',
1070 'on_hold' => '',
1071 );
1072 $contactDetails = array(
1073 array_intersect_key($contact, $contactDetailsIntersectKeys),
1074 );
1075
1076 // Create a campaign.
1077 $result = $this->civicrm_api('Campaign', 'create', array(
1078 'version' => $this->_apiversion,
1079 'title' => __FUNCTION__ . ' campaign',
1080 ));
1081 $campaign_id = $result['id'];
1082
1083 $subject = __FUNCTION__ . ' subject';
1084 $html = __FUNCTION__ . ' html';
1085 $text = __FUNCTION__ . ' text';
1086 $userID = $loggedInUser;
1087
1088 list($sent, $activity_id) = $email_result = CRM_Activity_BAO_Activity::sendEmail(
1089 $contactDetails,
1090 $subject,
1091 $text,
1092 $html,
1093 $contact['email'],
1094 $userID,
1095 $from = __FUNCTION__ . '@example.com',
1096 $attachments = NULL,
1097 $cc = NULL,
1098 $bcc = NULL,
1099 $contactIds = NULL,
1100 $additionalDetails = NULL,
1101 NULL,
1102 $campaign_id
1103 );
1104 $activity = $this->civicrm_api('activity', 'getsingle', array('id' => $activity_id, 'version' => $this->_apiversion));
1105 $this->assertEquals($activity['campaign_id'], $campaign_id, 'Activity campaign_id does not match.');
1106 }
1107
1108 /**
1109 * @expectedException CRM_Core_Exception
1110 * @expectedExceptionMessage You do not have the 'send SMS' permission
1111 */
1112 public function testSendSMSWithoutPermission() {
1113 $dummy = NULL;
1114 $session = CRM_Core_Session::singleton();
1115 CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM');
1116
1117 CRM_Activity_BAO_Activity::sendSMS(
1118 $dummy,
1119 $dummy,
1120 $dummy,
1121 $dummy,
1122 $session->get('userID')
1123 );
1124 }
1125
1126 public function testSendSmsNoPhoneNumber() {
1127 list($sent, $activityId, $success) = $this->createSendSmsTest(0);
1128 $activity = $this->civicrm_api('activity', 'getsingle', array('id' => $activityId, 'version' => $this->_apiversion));
1129
1130 $outBoundSmsActivityId = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'SMS');
1131 $activityStatusCompleted = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_status_id', 'Completed');
1132 $details = 'createSendSmsTest text';
1133 $this->assertEquals($activity['activity_type_id'], $outBoundSmsActivityId, 'Wrong activity type is set.');
1134 $this->assertEquals($activity['status_id'], $activityStatusCompleted, 'Expected activity status Completed.');
1135 $this->assertEquals($activity['subject'], 'createSendSmsTest subject', 'Activity subject does not match.');
1136 $this->assertEquals($activity['details'], $details, 'Activity details does not match.');
1137 $this->assertEquals("Recipient phone number is invalid or recipient does not want to receive SMS", $sent[0]->message, "Expected error doesn't match");
1138 $this->assertEquals(0, $success, "Expected success to be 0");
1139 }
1140
1141 public function testSendSmsFixedPhoneNumber() {
1142 list($sent, $activityId, $success) = $this->createSendSmsTest(1);
1143 $activity = $this->civicrm_api('activity', 'getsingle', array('id' => $activityId, 'version' => $this->_apiversion));
1144
1145 $outBoundSmsActivityId = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'SMS');
1146 $activityStatusCompleted = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_status_id', 'Completed');
1147 $details = 'createSendSmsTest text';
1148 $this->assertEquals($activity['activity_type_id'], $outBoundSmsActivityId, 'Wrong activity type is set.');
1149 $this->assertEquals($activity['status_id'], $activityStatusCompleted, 'Expected activity status Completed.');
1150 $this->assertEquals($activity['subject'], 'createSendSmsTest subject', 'Activity subject does not match.');
1151 $this->assertEquals($activity['details'], $details, 'Activity details does not match.');
1152 $this->assertEquals("Recipient phone number is invalid or recipient does not want to receive SMS", $sent[0]->message, "Expected error doesn't match");
1153 $this->assertEquals(0, $success, "Expected success to be 0");
1154 }
1155
1156 public function testSendSmsMobilePhoneNumber() {
1157 list($sent, $activityId, $success) = $this->createSendSmsTest(2);
1158 $activity = $this->civicrm_api('activity', 'getsingle', array('id' => $activityId, 'version' => $this->_apiversion));
1159
1160 $outBoundSmsActivityId = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'SMS');
1161 $activityStatusCompleted = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_status_id', 'Completed');
1162 $details = 'createSendSmsTest text';
1163 $this->assertEquals($activity['activity_type_id'], $outBoundSmsActivityId, 'Wrong activity type is set.');
1164 $this->assertEquals($activity['status_id'], $activityStatusCompleted, 'Expected activity status Completed.');
1165 $this->assertEquals($activity['subject'], 'createSendSmsTest subject', 'Activity subject does not match.');
1166 $this->assertEquals($activity['details'], $details, 'Activity details does not match.');
1167 $this->assertEquals(TRUE, $sent, "Expected sent should be true");
1168 $this->assertEquals(1, $success, "Expected success to be 1");
1169 }
1170
1171 /**
1172 * Test that when a numbe ris specified in the To Param of the SMS provider parameters that an SMS is sent
1173 * @see dev/core/#273
1174 */
1175 public function testSendSMSMobileInToProviderParam() {
1176 list($sent, $activityId, $success) = $this->createSendSmsTest(2, TRUE);
1177 $this->assertEquals(TRUE, $sent, "Expected sent should be true");
1178 $this->assertEquals(1, $success, "Expected success to be 1");
1179 }
1180
1181 /**
1182 * Test that when a numbe ris specified in the To Param of the SMS provider parameters that an SMS is sent
1183 * @see dev/core/#273
1184 */
1185 public function testSendSMSMobileInToProviderParamWithDoNotSMS() {
1186 list($sent, $activityId, $success) = $this->createSendSmsTest(2, TRUE, ['do_not_sms' => 1]);
1187 foreach ($sent as $error) {
1188 $this->assertEquals('Contact Does not accept SMS', $error->getMessage());
1189 }
1190 $this->assertEquals(1, count($sent), "Expected sent should a PEAR Error");
1191 $this->assertEquals(0, $success, "Expected success to be 0");
1192 }
1193
1194 /**
1195 * @param int $phoneType (0=no phone, phone_type option group (1=fixed, 2=mobile)
1196 * @param bool $passPhoneTypeInContactDetails
1197 * @param array $additionalContactParams additional contact creation params
1198 */
1199 public function createSendSmsTest($phoneType = 0, $passPhoneTypeInContactDetails = FALSE, $additionalContactParams = []) {
1200 $provider = civicrm_api3('SmsProvider', 'create', array(
1201 'name' => "CiviTestSMSProvider",
1202 'api_type' => "1",
1203 "username" => "1",
1204 "password" => "1",
1205 "api_type" => "1",
1206 "api_url" => "1",
1207 "api_params" => "a=1",
1208 "is_default" => "1",
1209 "is_active" => "1",
1210 "domain_id" => "1",
1211 ));
1212
1213 $smsProviderParams['provider_id'] = $provider['id'];
1214
1215 // Create a contact
1216 $contactId = $this->individualCreate();
1217 if (!empty($additionalContactParams)) {
1218 $this->callAPISuccess('contact', 'create', ['id' => $contactId] + $additionalContactParams);
1219 }
1220 $contactsResult = $this->callApiSuccess('contact', 'get', ['id' => $contactId, 'version' => $this->_apiversion]);
1221 $contactDetails = $contactsResult['values'];
1222
1223 // Get contactIds from contact details
1224 foreach ($contactDetails as $contact) {
1225 $contactIds[] = $contact['contact_id'];
1226 }
1227
1228 $activityParams['sms_text_message'] = __FUNCTION__ . ' text';
1229 $activityParams['activity_subject'] = __FUNCTION__ . ' subject';
1230
1231 // Get a "logged in" user to set as source of Sms.
1232 $session = CRM_Core_Session::singleton();
1233 $sourceContactId = $session->get('userID');
1234
1235 // Create a user
1236 $this->_testSmsContactId = $this->createLoggedInUser();
1237
1238 // Give user permission to 'send SMS'
1239 CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM', 'send SMS');
1240
1241 // Create a phone number
1242 switch ($phoneType) {
1243 case 0:
1244 // No phone number
1245 break;
1246
1247 case 2:
1248 // Create a mobile phone number
1249 $phone = civicrm_api3('Phone', 'create', array(
1250 'contact_id' => $contactId,
1251 'phone' => 123456,
1252 'phone_type_id' => "Mobile",
1253 ));
1254 if ($passPhoneTypeInContactDetails) {
1255 $contactDetails[$contactId]['phone'] = $phone['values'][$phone['id']]['phone'];
1256 $contactDetails[$contactId]['phone_type_id'] = $phone['values'][$phone['id']]['phone_type_id'];
1257 }
1258 break;
1259
1260 case 1:
1261 // Create a fixed phone number
1262 $phone = civicrm_api3('Phone', 'create', array(
1263 'contact_id' => $contactId,
1264 'phone' => 654321,
1265 'phone_type_id' => "Phone",
1266 ));
1267 if ($passPhoneTypeInContactDetails) {
1268 $contactDetails[$contactId]['phone'] = $phone['values'][$phone['id']]['phone'];
1269 $contactDetails[$contactId]['phone_type_id'] = $phone['values'][$phone['id']]['phone_type_id'];
1270 }
1271 break;
1272 }
1273
1274 // Now run the actual test
1275 list($sent, $activityId, $success) = CRM_Activity_BAO_Activity::sendSms(
1276 $contactDetails,
1277 $activityParams,
1278 $smsProviderParams,
1279 $contactIds,
1280 $sourceContactId
1281 );
1282
1283 return array($sent, $activityId, $success);
1284 }
1285
1286 protected function createTestActivities() {
1287 $op = new PHPUnit_Extensions_Database_Operation_Insert();
1288 $op->execute($this->_dbconn,
1289 $this->createFlatXMLDataSet(
1290 dirname(__FILE__) . '/activities_for_dashboard_count.xml'
1291 )
1292 );
1293 // Make changes to improve variation in php since the xml method is brittle & relies on option values being unchanged.
1294 $this->callAPISuccess('Activity', 'create', ['id' => 12, 'activity_type_id' => 'Bulk Email']);
1295 }
1296
1297 }