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

CRM-19956: Fix case getlist api with 'id' and 'case_id' param #9766

Merged
merged 1 commit into from
Feb 7, 2017
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
6 changes: 6 additions & 0 deletions api/v3/Case.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,11 @@ function _civicrm_api3_case_format_params(&$params) {
function civicrm_api3_case_getList($params) {
require_once 'api/v3/Generic/Getlist.php';
require_once 'api/v3/CaseContact.php';
//CRM:19956 - Assign case_id param if both id and case_id is passed to retrieve the case
if (!empty($params['id']) && !empty($params['params']) && !empty($params['params']['case_id'])) {
$params['params']['case_id'] = array('IN' => $params['id']);
unset($params['id']);
}
$params['id_field'] = 'case_id';
$params['label_field'] = $params['search_field'] = 'contact_id.sort_name';
$params['description_field'] = array(
Expand All @@ -463,6 +468,7 @@ function civicrm_api3_case_getList($params) {
'case_id.start_date',
);
$apiRequest = array(
'version' => 3,
'entity' => 'CaseContact',
'action' => 'getlist',
'params' => $params,
Expand Down
32 changes: 32 additions & 0 deletions tests/phpunit/api/v3/CaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,38 @@ public function testCaseCreateWithoutRequired() {
$this->callAPIFailure('case', 'create', $params);
}

/**
* Test Getlist with id and case_id
*/
public function testCaseGetListById() {
$params = $this->_params;
$params['contact_id'] = $this->individualCreate();

//Create 3 sample Cases.
$case1 = $this->callAPISuccess('case', 'create', $params);
$params['subject'] = 'Test Case 2';
$case2 = $this->callAPISuccess('case', 'create', $params);
$params['subject'] = 'Test Case 3';
$case3 = $this->callAPISuccess('case', 'create', $params);

$getParams = array(
'id' => array($case1['id']),
'extra' => array('contact_id'),
'params' => array(
'version' => 3,
'case_id' => array('!=' => $case2['id']),
'case_id.is_deleted' => 0,
'case_id.status_id' => array('!=' => "Closed"),
'case_id.end_date' => array('IS NULL' => 1),
),
);
$result = $this->callAPISuccess('case', 'getlist', $getParams);

//Only 1 case should be returned.
$this->assertEquals(count($result['values']), 1);
$this->assertEquals($result['values'][0]['id'], $case1['id']);
}

/**
* Test create function with valid parameters.
*/
Expand Down