2 require_once 'CiviTest/CiviCaseTestCase.php';
5 * Class CRM_Case_XMLProcessor_ReportTest
8 class CRM_Case_XMLProcessor_ReportTest
extends CiviCaseTestCase
{
10 public function setUp() {
13 $this->simplifyCaseTypeDefinition();
15 $this->report
= new CRM_Case_XMLProcessor_Report();
18 public function tearDown() {
23 * Test that getCaseReport has the right output.
25 * @param $activitySetName string Also acts as data provider test identifier.
26 * @param $expected array
28 * @dataProvider caseReportDataProvider
30 public function testGetCaseReport($activitySetName, $expected) {
31 $client_id = $this->individualCreate([
32 'first_name' => 'Casey',
34 'last_name' => 'Reportee',
38 $caseObj = $this->createCase($client_id, $this->_loggedInUser
);
39 $case_id = $caseObj->id
;
41 // Add an additional meeting activity not in the timeline to the case.
42 $meetingTypeId = $this->callAPISuccess('OptionValue', 'getsingle', [
43 'return' => ["value"],
44 'option_group_id' => 'activity_type',
47 $this->callAPISuccess('activity', 'create', [
48 'case_id' => $case_id,
49 'activity_type_id' => $meetingTypeId['value'],
50 'activity_date_time' => '20191114123456',
51 'subject' => 'Test Meeting',
52 'source_contact_id' => $this->_loggedInUser
,
53 'target_contact_id' => $client_id,
58 'include_activities' => 1,
61 // run the thing we're testing and get the output vars
62 $template = CRM_Case_XMLProcessor_Report
::populateCaseReportTemplate($client_id, $case_id, $activitySetName, $caseReportParams, $this->report
);
63 $assigned_vars = $template->get_template_vars();
65 // Update $expected now since dataprovider doesn't have access to the variables from setup() because it runs before setup.
66 $this->updateExpectedBecauseDataProviderEvaluatesBeforeEverything($expected, $client_id, $case_id);
68 foreach ($expected as $key => $value) {
69 // does the assigned template var match the expected value?
70 $this->assertEquals($value, $assigned_vars[$key], "$activitySetName: $key does not match" . print_r($assigned_vars[$key], TRUE));
75 * Data provider for testGetCaseReport
78 public function caseReportDataProvider() {
83 // some expected assigned vars of CRM_Core_Smarty template
86 'clientName' => 'Casey Reportee',
87 'subject' => 'Case Subject',
88 'start_date' => '2019-11-14',
90 'caseType' => 'Housing Support',
91 'caseTypeName' => 'housing_support',
92 'status' => 'Ongoing',
99 'value' => 'Casey Reportee',
103 'label' => 'Activity Type',
104 'value' => 'Open Case',
108 'label' => 'Subject',
109 'value' => 'Case Subject',
113 'label' => 'Created By',
114 // data providers run before everything, so update this later
115 'value' => 'placeholder',
119 'label' => 'Reported By',
120 // see above - need to update this later
121 'value' => 'placeholder',
130 'label' => 'Location',
135 'label' => 'Date and Time',
136 'value' => '2019-11-14 00:00:00',
140 'label' => 'Details',
146 'value' => 'Completed',
150 'label' => 'Priority',
155 'editURL' => 'placeholder',
156 'customGroups' => NULL,
162 'value' => 'Casey Reportee',
166 'label' => 'Activity Type',
167 'value' => 'Medical evaluation',
171 'label' => 'Subject',
176 'label' => 'Created By',
177 // see above - need to update this later
178 'value' => 'placeholder',
182 'label' => 'Reported By',
183 // see above - need to update this later
184 'value' => 'placeholder',
188 'label' => 'Location',
193 'label' => 'Date and Time',
194 'value' => '2019-11-15 00:00:00',
198 'label' => 'Details',
204 'value' => 'Scheduled',
208 'label' => 'Priority',
213 'editURL' => 'placeholder',
214 'customGroups' => NULL,
220 // activity set name is blank here, meaning don't filter the activities
222 // some expected assigned vars of CRM_Core_Smarty template
225 'clientName' => 'Casey Reportee',
226 'subject' => 'Case Subject',
227 'start_date' => '2019-11-14',
229 'caseType' => 'Housing Support',
230 'caseTypeName' => 'housing_support',
231 'status' => 'Ongoing',
238 'value' => 'Casey Reportee',
242 'label' => 'Activity Type',
243 'value' => 'Open Case',
247 'label' => 'Subject',
248 'value' => 'Case Subject',
252 'label' => 'Created By',
253 // data providers run before everything, so update this later
254 'value' => 'placeholder',
258 'label' => 'Reported By',
259 // see above - need to update this later
260 'value' => 'placeholder',
269 'label' => 'Location',
274 'label' => 'Date and Time',
275 'value' => '2019-11-14 00:00:00',
279 'label' => 'Details',
285 'value' => 'Completed',
289 'label' => 'Priority',
294 'editURL' => 'placeholder',
295 'customGroups' => NULL,
301 'value' => 'Casey Reportee',
305 'label' => 'Activity Type',
306 'value' => 'Medical evaluation',
310 'label' => 'Subject',
315 'label' => 'Created By',
316 // see above - need to update this later
317 'value' => 'placeholder',
321 'label' => 'Reported By',
322 // see above - need to update this later
323 'value' => 'placeholder',
327 'label' => 'Location',
332 'label' => 'Date and Time',
333 'value' => '2019-11-15 00:00:00',
337 'label' => 'Details',
343 'value' => 'Scheduled',
347 'label' => 'Priority',
352 'editURL' => 'placeholder',
353 'customGroups' => NULL,
359 'value' => 'Casey Reportee',
363 'label' => 'Activity Type',
364 'value' => 'Meeting',
368 'label' => 'Subject',
369 'value' => 'Test Meeting',
373 'label' => 'Created By',
374 // see above - need to update this later
375 'value' => 'placeholder',
379 'label' => 'Reported By',
380 // see above - need to update this later
381 'value' => 'placeholder',
385 'label' => 'Location',
390 'label' => 'Date and Time',
391 'value' => '2019-11-14 12:34:56',
395 'label' => 'Details',
401 'value' => 'Completed',
405 'label' => 'Priority',
410 'editURL' => 'placeholder',
411 'customGroups' => NULL,
420 * Since data providers get evaluated before setup and other variable
421 * assignments, we call this during the test to update placeholders we set
422 * in the data provider.
423 * Maybe it doesn't really make sense to use a data provider here, but kinda.
425 * @param &$expected array Contains the placeholders to update.
426 * @param $client_id int
427 * @param $case_id int
429 private function updateExpectedBecauseDataProviderEvaluatesBeforeEverything(&$expected, $client_id, $case_id) {
430 $display_name = $this->callAPISuccess('Contact', 'getsingle', [
431 'return' => ["display_name"],
432 'id' => $this->_loggedInUser
,
435 foreach ($expected['activities'] as $idx => $activity) {
436 $expected['activities'][$idx]['fields'][3]['value'] = $display_name['display_name'];
437 $expected['activities'][$idx]['fields'][4]['value'] = $display_name['display_name'];
439 $activityTypeId = $this->callAPISuccess('OptionValue', 'getsingle', [
440 'return' => ["value"],
441 'option_group_id' => 'activity_type',
442 'name' => $expected['activities'][$idx]['fields'][1]['value'],
444 $expected['activities'][$idx]['editURL'] = CRM_Utils_System
::url('civicrm/case/activity', "reset=1&cid={$client_id}&caseid={$case_id}&action=update&atype={$activityTypeId['value']}&id=" . ($idx +
1));
449 * Create and return a new case object.
451 * @param $loggedInUser
452 * @return CRM_Case_BAO_Case
454 private function createCase($clientId, $loggedInUser) {
456 'activity_subject' => 'Case Subject',
457 'client_id' => $clientId,
458 'case_type_id' => $this->caseTypeId
,
460 'case_type' => $this->caseType
,
461 'subject' => 'Case Subject',
462 'start_date' => '2019-11-14',
463 'start_date_time' => '20191114000000',
465 'activity_details' => '',
467 $form = new CRM_Case_Form_Case();
468 $caseObj = $form->testSubmit($caseParams, "OpenCase", $loggedInUser, "standalone");
473 * We don't need so many activities as in the stock case type. Just makes
474 * dataprovider unnecessarily long. Just take the first two.
477 private function simplifyCaseTypeDefinition() {
478 $caseType = $this->callAPISuccess('CaseType', 'getsingle', ['id' => $this->caseTypeId
]);
479 $newActivitySet = array_slice($caseType['definition']['activitySets'][0]['activityTypes'], 0, 2);
480 $caseType['definition']['activitySets'][0]['activityTypes'] = $newActivitySet;
481 $this->callAPISuccess('CaseType', 'create', $caseType);