Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Case Manager is not shown for closed cases (Gitlab issue 542) #13831

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CRM/Case/BAO/Case.php
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ public static function getCaseRoles($contactID, $caseID, $relationshipID = NULL,
AND con.is_deleted = 0';

if ($activeOnly) {
$query .= ' AND rel.is_active = 1 AND (rel.end_date IS NULL OR rel.end_date > NOW())';
$query .= ' AND rel.is_active = 1';
}

$params = array(
Expand Down
64 changes: 56 additions & 8 deletions tests/phpunit/api/v3/CaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,6 @@ public function testCaseCreateWithResolvedStatus() {
foreach ($relationships['values'] as $key => $values) {
$this->assertEquals($values['end_date'], date('Y-m-d'));
}

//Verify there are no active relationships.
$activeCaseRelationships = CRM_Case_BAO_Case::getCaseRoles($result['values'][$id]['client_id'][1], $id);
$this->assertEquals(count($activeCaseRelationships), 0, "Checking for empty array");

//Check if getCaseRoles() is able to return inactive relationships.
$caseRelationships = CRM_Case_BAO_Case::getCaseRoles($result['values'][$id]['client_id'][1], $id, NULL, FALSE);
$this->assertEquals(count($caseRelationships), 1);
}

/**
Expand Down Expand Up @@ -363,6 +355,62 @@ public function testCaseRoleRelationships() {
'contact_id' => $relContact,
'activity_id' => $activity['id'],
));

// test scenario :replace a caserole (create a new relationship with the same type)
// expected - old relationship is deactivated
// - old relationship has an end_data
// - new relationship is active

$oldRelationShipId = $relationship['id'];
$sndRelContact = $this->individualCreate(array('first_name' => 'Second', 'last_name' => 'the very Last'));

$_REQUEST = array(
'rel_type' => "{$relType}_b_a",
'rel_contact' => $sndRelContact,
'case_id' => $case['id'],
'rel_id' => $oldRelationShipId,
'cid' => $relContact,
'is_unit_test' => TRUE,
);

CRM_Contact_Page_AJAX::relationship();

// Reload the oldRelationShip
$oldRelationship = $this->callAPISuccess('Relationship', 'get', array(
'sequential' => 1,
'id' => $oldRelationShipId,
));
// Recheck the old values - nothing should be changed
$this->assertEquals($relContact, $oldRelationship['values'][0]['contact_id_a']);
$this->assertEquals($this->_params['contact_id'], $oldRelationship['values'][0]['contact_id_b']);
// What is changed is the enddate and the active flag
$this->assertEquals(0, $oldRelationship['values'][0]['is_active']);
$this->assertNotEmpty($oldRelationship['values'][0]['end_date']);

// the new relationship can be identified with the active flag
$newRelationship = $this->callAPISuccess('Relationship', 'get', array(
'sequential' => 1,
'relationship_type_id' => $relType,
'case_id' => $case['id'],
'is_active' => 1,
));

// check the old values - nothing should be changed
$this->assertEquals($sndRelContact, $newRelationship['values'][0]['contact_id_a']);
$this->assertEquals($this->_params['contact_id'], $newRelationship['values'][0]['contact_id_b']);
// What is changed is the enddate and the active flag
$this->assertEquals(1, $newRelationship['values'][0]['is_active']);
$this->assertFalse(isset($newRelationship['values'][0]['end_date']));
// and it has a start date
$this->assertNotEmpty($oldRelationship['values'][0]['start_date']);

// Case role counting +1 for the case ownder +1 for the first relationship +1 for the snd relationship total = 3
$activeCaseRelationships = CRM_Case_BAO_Case::getCaseRoles($this->_params['contact_id'], $case['id'], NULL, FALSE);
$this->assertEquals(count($activeCaseRelationships), 3, "Checking for empty array");

// But -1 if only active relationships are selected makes total 2
$activeCaseRelationships = CRM_Case_BAO_Case::getCaseRoles($this->_params['contact_id'], $case['id'], NULL, TRUE);
$this->assertEquals(count($activeCaseRelationships), 2, "Checking for empty array");
}

/**
Expand Down