From a9410a638f438428530de7893aa289af3f971d94 Mon Sep 17 00:00:00 2001 From: demeritcowboy Date: Thu, 28 Nov 2019 16:35:38 -0500 Subject: [PATCH] bypass nonfunctioning interactive screen and go straight to report --- CRM/Case/Form/Report.php | 19 +++-- CRM/Case/XMLProcessor/Report.php | 4 +- .../CRM/Case/XMLProcessor/ReportTest.php | 77 ++++++++++++++++++- 3 files changed, 90 insertions(+), 10 deletions(-) diff --git a/CRM/Case/Form/Report.php b/CRM/Case/Form/Report.php index 21a44c5977..d286484315 100644 --- a/CRM/Case/Form/Report.php +++ b/CRM/Case/Form/Report.php @@ -106,13 +106,20 @@ class CRM_Case_Form_Report extends CRM_Core_Form { // store the submitted values in an array $params = $this->controller->exportValues($this->_name); - $xmlProcessor = new CRM_Case_XMLProcessor_Report(); - $contents = $xmlProcessor->run($this->_clientID, - $this->_caseID, - $this->_activitySetName, - $params + // this is either a 1 or a 2, but the url expects a 1 or 0 + $all = ($params['include_activities'] == 1) ? 1 : 0; + + // similar but comes from a checkbox that's either 1 or not present + $is_redact = empty($params['is_redact']) ? 0 : 1; + + $asn = rawurlencode($this->_activitySetName); + + CRM_Utils_System::redirect( + CRM_Utils_System::url( + 'civicrm/case/report/print', + "caseID={$this->_caseID}&cid={$this->_clientID}&asn={$asn}&redact={$is_redact}&all={$all}" + ) ); - $this->set('report', $contents); } } diff --git a/CRM/Case/XMLProcessor/Report.php b/CRM/Case/XMLProcessor/Report.php index b240b3c77c..fc4d6a2d3e 100644 --- a/CRM/Case/XMLProcessor/Report.php +++ b/CRM/Case/XMLProcessor/Report.php @@ -131,7 +131,7 @@ class CRM_Case_XMLProcessor_Report extends CRM_Case_XMLProcessor { foreach ($activitySetsXML->ActivitySet as $activitySetXML) { if ((string ) $activitySetXML->name == $activitySetName) { $activityTypes = array(); - $allActivityTypes = &$this->allActivityTypes(); + $allActivityTypes = CRM_Case_PseudoConstant::caseActivityType(TRUE, TRUE); foreach ($activitySetXML->ActivityTypes as $activityTypesXML) { foreach ($activityTypesXML as $activityTypeXML) { $activityTypeName = (string ) $activityTypeXML->name; @@ -752,7 +752,7 @@ LIMIT 1 $case = $form->caseInfo($clientID, $caseID); $template->assign_by_ref('case', $case); - if ($params['include_activities'] == 1) { + if (CRM_Utils_Array::value('include_activities', $params) == 1) { $template->assign('includeActivities', 'All'); } else { diff --git a/tests/phpunit/CRM/Case/XMLProcessor/ReportTest.php b/tests/phpunit/CRM/Case/XMLProcessor/ReportTest.php index e199f65683..78021056c9 100644 --- a/tests/phpunit/CRM/Case/XMLProcessor/ReportTest.php +++ b/tests/phpunit/CRM/Case/XMLProcessor/ReportTest.php @@ -71,6 +71,60 @@ class CRM_Case_XMLProcessor_ReportTest extends CiviCaseTestCase { } } + /** + * This is similar to testGetCaseReport but test with a timeline that + * does have Meeting in it. + */ + public function testGetCaseReportWithMeetingInTimeline() { + $client_id = $this->individualCreate([ + 'first_name' => 'Casey', + 'middle_name' => '', + 'last_name' => 'Reportee', + 'prefix_id' => NULL, + 'suffix_id' => NULL, + ]); + $caseObj = $this->createCase($client_id, $this->_loggedInUser); + $case_id = $caseObj->id; + + // Now update the timeline so it has Meeting in it. + $this->addMeetingToTimeline(); + + // Add a meeting activity to the case. + $meetingTypeId = $this->callAPISuccess('OptionValue', 'getsingle', [ + 'return' => ["value"], + 'option_group_id' => 'activity_type', + 'name' => 'Meeting', + ]); + $this->callAPISuccess('activity', 'create', [ + 'case_id' => $case_id, + 'activity_type_id' => $meetingTypeId['value'], + 'activity_date_time' => '20191114123456', + 'subject' => 'Test Meeting', + 'source_contact_id' => $this->_loggedInUser, + 'target_contact_id' => $client_id, + ]); + + $caseReportParams = [ + 'is_redact' => FALSE, + 'include_activities' => 1, + ]; + + // run the thing we're testing and get the output vars + $template = CRM_Case_XMLProcessor_Report::populateCaseReportTemplate($client_id, $case_id, 'standard_timeline', $caseReportParams, $this->report); + $assigned_vars = $template->get_template_vars(); + + // We don't want to run all the data in the dataprovider but we know + // in this case it should be the same as the second one in the + // dataprovider so we can reuse it. + $expected = $this->caseReportDataProvider()[1][1]; + $this->updateExpectedBecauseDataProviderEvaluatesBeforeEverything($expected, $client_id, $case_id); + + foreach ($expected as $key => $value) { + // does the assigned template var match the expected value? + $this->assertEquals($value, $assigned_vars[$key], "$key does not match" . print_r($assigned_vars[$key], TRUE)); + } + } + /** * Data provider for testGetCaseReport * @return array @@ -80,7 +134,9 @@ class CRM_Case_XMLProcessor_ReportTest extends CiviCaseTestCase { [ // activity set name 'standard_timeline', - // some expected assigned vars of CRM_Core_Smarty template + // Some expected assigned vars of CRM_Core_Smarty template. + // In particular we shouldn't have meeting in the output since it's + // not in the timeline. [ 'case' => [ 'clientName' => 'Casey Reportee', @@ -219,7 +275,8 @@ class CRM_Case_XMLProcessor_ReportTest extends CiviCaseTestCase { [ // activity set name is blank here, meaning don't filter the activities '', - // some expected assigned vars of CRM_Core_Smarty template + // Some expected assigned vars of CRM_Core_Smarty template. + // In particular now we will have Meeting in the output. [ 'case' => [ 'clientName' => 'Casey Reportee', @@ -481,4 +538,20 @@ class CRM_Case_XMLProcessor_ReportTest extends CiviCaseTestCase { $this->callAPISuccess('CaseType', 'create', $caseType); } + /** + * Add Meeting to the standard timeline. + */ + private function addMeetingToTimeline() { + $caseType = $this->callAPISuccess('CaseType', 'getsingle', ['id' => $this->caseTypeId]); + $activityTypes = $caseType['definition']['activitySets'][0]['activityTypes']; + // Make a copy of the second activity type and change the type. + $activityType = $activityTypes[1]; + $activityType['name'] = 'Meeting'; + $activityType['label'] = 'Meeting'; + + $activityTypes[] = $activityType; + $caseType['definition']['activitySets'][0]['activityTypes'] = $activityTypes; + $this->callAPISuccess('CaseType', 'create', $caseType); + } + } -- 2.25.1