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

[NFC/TEST] Resurrect unfinished test for getRelatedCases() #16885

Merged
Merged
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/Form/Activity/LinkCases.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public static function beginPostProcess(&$form, &$params) {
* @param array $params
* @param CRM_Activity_BAO_Activity $activity
*/
public static function endPostProcess(&$form, &$params, &$activity) {
public static function endPostProcess($form, $params, $activity) {
$activityId = $activity->id;
$linkCaseID = $params['link_to_case_id'] ?? NULL;

Expand Down
45 changes: 42 additions & 3 deletions tests/phpunit/CRM/Case/BAO/CaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,49 @@ public function testGetCasesSummary() {
$this->assertEquals(1, $cases['rows']['Housing Support']['Ongoing']['count']);
}

/* FIXME: requires activities
* function testGetRelatedCases() {
* }
/**
* Test that getRelatedCases() returns the other case when you create a
* Link Cases activity on one of the cases.
*/
public function testGetRelatedCases() {
$loggedInUser = $this->createLoggedInUser();
// create some cases
$client_id_1 = $this->individualCreate([], 0);
$caseObj_1 = $this->createCase($client_id_1, $loggedInUser);
$case_id_1 = $caseObj_1->id;
$client_id_2 = $this->individualCreate([], 1);
$caseObj_2 = $this->createCase($client_id_2, $loggedInUser);
$case_id_2 = $caseObj_2->id;

// Create link case activity. We could go thru the whole form processes
// but we really just want to test the BAO function so just need the
// activity to exist.
$result = $this->callAPISuccess('activity', 'create', [
'activity_type_id' => 'Link Cases',
'subject' => 'Test Link Cases',
'status_id' => 'Completed',
'source_contact_id' => $loggedInUser,
'target_contact_id' => $client_id_1,
'case_id' => $case_id_1,
]);

// Put it in the format needed for endPostProcess
$activity = new StdClass();
$activity->id = $result['id'];
$params = [
'link_to_case_id' => $case_id_2,
];
CRM_Case_Form_Activity_LinkCases::endPostProcess(NULL, $params, $activity);

// Get related cases for case 1
$cases = CRM_Case_BAO_Case::getRelatedCases($case_id_1);
// It should have case 2
$this->assertEquals($case_id_2, $cases[$case_id_2]['case_id']);

// Ditto but reverse the cases
$cases = CRM_Case_BAO_Case::getRelatedCases($case_id_2);
$this->assertEquals($case_id_1, $cases[$case_id_1]['case_id']);
}

/**
* Test various things after a case is closed.
Expand Down