missing semicolon, other cleanup, add test
[civicrm-core.git] / tests / phpunit / CRM / Activity / Page / AJAXTest.php
1 <?php
2
3 /**
4 * @group headless
5 */
6 class CRM_Activity_Page_AJAXTest extends CiviUnitTestCase {
7
8 public function setUp() {
9 parent::setUp();
10
11 $this->loadAllFixtures();
12
13 CRM_Core_BAO_ConfigSetting::enableComponent('CiviCase');
14
15 $this->loggedInUser = $this->createLoggedInUser();
16 $this->target = $this->individualCreate();
17 }
18
19 /**
20 * Test the underlying function that implements file-on-case.
21 *
22 * The UI is a quickform but it's only realized as a popup ajax form that
23 * doesn't have its own postProcess. Instead the values are ultimately
24 * passed to the function this test is testing. So there's no form or ajax
25 * being tested here, just the final act of filing the activity.
26 */
27 public function testConvertToCaseActivity() {
28 $activity = $this->callAPISuccess('Activity', 'create', [
29 'source_contact_id' => $this->loggedInUser,
30 'activity_type_id' => 'Meeting',
31 'subject' => 'test file on case',
32 'status_id' => 'Completed',
33 'target_id' => $this->target,
34 ]);
35
36 $case = $this->callAPISuccess('Case', 'create', [
37 'contact_id' => $this->target,
38 'case_type_id' => 'housing_support',
39 'subject' => 'Needs housing',
40 ]);
41
42 $params = [
43 'activityID' => $activity['id'],
44 'caseID' => $case['id'],
45 'mode' => 'file',
46 'targetContactIds' => $this->target,
47 ];
48 $result = CRM_Activity_Page_AJAX::_convertToCaseActivity($params);
49
50 $this->assertEmpty($result['error_msg']);
51 $newActivityId = $result['newId'];
52
53 $caseActivities = $this->callAPISuccess('Activity', 'get', [
54 'case_id' => $case['id'],
55 ])['values'];
56 $this->assertEquals('test file on case', $caseActivities[$newActivityId]['subject']);
57 // This should be a different physical activity, not the same db record as the original.
58 $this->assertNotEquals($activity['id'], $caseActivities[$newActivityId]['id']);
59 }
60
61 }