Skip to content

Commit

Permalink
fix notice warning
Browse files Browse the repository at this point in the history
  • Loading branch information
demeritcowboy committed Apr 30, 2019
1 parent 1d322b8 commit ef8a614
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 4 deletions.
5 changes: 4 additions & 1 deletion CRM/Case/Form/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,10 @@ public function postProcess($params = NULL) {
}

// store the submitted values in an array
$params = $this->controller->exportValues($this->_name);
// Maintain some backwards compatibility in case anybody is actually calling this function with a non-null $params parameter, despite the fact that prior to this check it would have been overwritten anyway. See PR #2077 for some discussion of when the $params parameter was added as a passed in variable. The reason now for adding this check is just in case some incorrect code happened to be working inadvertently before, it will still inadvertently work now. And then at the same time we can pass in a value for unit tests without it being overwritten.
if (empty($params) || !defined('CIVICRM_UF') || CIVICRM_UF != 'UnitTests') {
$params = $this->controller->exportValues($this->_name);
}

//set parent id if its edit mode
if ($parentId = CRM_Utils_Array::value('parent_id', $this->_defaults)) {
Expand Down
2 changes: 1 addition & 1 deletion CRM/Case/Form/Activity/ChangeCaseStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public static function formRule($values, $files, $form) {
public static function beginPostProcess(&$form, &$params) {
$params['id'] = CRM_Utils_Array::value('case_id', $params);

if ($params['updateLinkedCases'] === '1') {
if (!empty($params['updateLinkedCases']) && ($params['updateLinkedCases'] === '1')) {
$caseID = CRM_Utils_Array::first($form->_caseId);
$cases = CRM_Case_BAO_Case::getRelatedCases($caseID);

Expand Down
104 changes: 102 additions & 2 deletions tests/phpunit/CRM/Case/BAO/CaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,14 @@ public function testAddCaseToContact() {
/**
* Create and return case object of given Client ID.
* @param $clientId
* @param $loggedInUser
* @return CRM_Case_BAO_Case
*/
private function createCase($clientId) {
private function createCase($clientId, $loggedInUser = NULL) {
if (empty($loggedInUser)) {
// backwards compatibility - but it's more typical that the creator is a different person than the client
$loggedInUser = $clientId;
}
$caseParams = array(
'activity_subject' => 'Case Subject',
'client_id' => $clientId,
Expand All @@ -88,7 +93,7 @@ private function createCase($clientId) {
'activity_details' => '',
);
$form = new CRM_Case_Form_Case();
$caseObj = $form->testSubmit($caseParams, "OpenCase", $clientId, "standalone");
$caseObj = $form->testSubmit($caseParams, "OpenCase", $loggedInUser, "standalone");
return $caseObj;
}

Expand Down Expand Up @@ -183,4 +188,99 @@ public function testGetCasesSummary() {
* }
*/

/**
* Test various things after a case is closed.
*/
public function testCaseClosure() {
$loggedInUser = $this->createLoggedInUser();
$client_id = $this->individualCreate();
$caseObj = $this->createCase($client_id, $loggedInUser);
$case_id = $caseObj->id;

// Get the case status option value for "Resolved" (name="Closed").
$closed_status = $this->callAPISuccess('OptionValue', 'getValue', [
'return' => 'value',
'option_group_id' => 'case_status',
'name' => 'Closed',
]);
$this->assertNotEmpty($closed_status);

// Get the activity status option value for "Completed"
$completed_status = $this->callAPISuccess('OptionValue', 'getValue', [
'return' => 'value',
'option_group_id' => 'activity_status',
'name' => 'Completed',
]);
$this->assertNotEmpty($completed_status);

// Get the value for the activity type id we need to create
$atype = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Change Case Status');

// Now it gets weird. There doesn't seem to be a good way to test this, so we simulate a form and the various bits that go with it.

// http vars needed because that's how the form determines stuff
$_SERVER['REQUEST_METHOD'] = 'GET';
$_GET['caseid'] = $case_id;
$_REQUEST['caseid'] = $case_id;
$_GET['cid'] = $client_id;
$_REQUEST['cid'] = $client_id;
$_GET['action'] = 'add';
$_REQUEST['action'] = 'add';
$_GET['reset'] = 1;
$_REQUEST['reset'] = 1;
$_GET['atype'] = $atype;
$_REQUEST['atype'] = $atype;

$form = new CRM_Case_Form_Activity();
$form->controller = new CRM_Core_Controller_Simple('CRM_Case_Form_Activity', 'Case Activity');
$form->_activityTypeId = $atype;
$form->_activityTypeName = 'Change Case Status';
$form->_activityTypeFile = 'ChangeCaseStatus';

$form->preProcess();
$form->buildQuickForm();
$form->setDefaultValues();

// Now submit the form. Store the date used so we can check it later.

$t = time();
$now_date = date('Y-m-d H:i:s', $t);
$now_date_date_only = date('Y-m-d', $t);
$actParams = [
'case_status_id' => $closed_status,
'activity_date_time' => $now_date,
'target_contact_id' => $client_id,
'source_contact_id' => $loggedInUser,
'subject' => 'null', // yeah this is extra weird, but without it you get the wrong subject
];

$form->postProcess($actParams);

// Ok now let's check some things

$result = $this->callAPISuccess('Case', 'get', [
'sequential' => 1,
'id' => $case_id,
]);
$caseData = array_shift($result['values']);

$this->assertEquals($caseData['end_date'], $now_date_date_only);
$this->assertEquals($caseData['status_id'], $closed_status);

// now get the latest activity and check some things for it

$actId = max($caseData['activities']);
$this->assertNotEmpty($actId);

$result = $this->callAPISuccess('Activity', 'get', [
'sequential' => 1,
'id' => $actId,
]);
$activity = array_shift($result['values']);

$this->assertEquals($activity['subject'], 'Case status changed from Ongoing to Resolved');
$this->assertEquals($activity['activity_date_time'], $now_date);
$this->assertEquals($activity['status_id'], $completed_status);
}

}

0 comments on commit ef8a614

Please sign in to comment.