Skip to content

Commit

Permalink
Merge pull request civicrm#9766 from jitendrapurohit/CRM-19956
Browse files Browse the repository at this point in the history
CRM-19956: Fix case getlist api with 'id' and 'case_id' param
  • Loading branch information
colemanw authored Feb 7, 2017
2 parents 19fc0c4 + 01a58cd commit a6231e4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
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

0 comments on commit a6231e4

Please sign in to comment.