From 09d55aa3fe8037e0eb5f8d21e647521b30b1ac1c Mon Sep 17 00:00:00 2001 From: jitendrapurohit Date: Thu, 2 Feb 2017 16:54:39 +0530 Subject: [PATCH] CRM-19956: Fix case getlist api with 'id' and 'case_id' param --- api/v3/Case.php | 6 ++++++ tests/phpunit/api/v3/CaseTest.php | 32 +++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/api/v3/Case.php b/api/v3/Case.php index 8cfdfe1d2db9..efddd0904b97 100644 --- a/api/v3/Case.php +++ b/api/v3/Case.php @@ -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( @@ -463,6 +468,7 @@ function civicrm_api3_case_getList($params) { 'case_id.start_date', ); $apiRequest = array( + 'version' => 3, 'entity' => 'CaseContact', 'action' => 'getlist', 'params' => $params, diff --git a/tests/phpunit/api/v3/CaseTest.php b/tests/phpunit/api/v3/CaseTest.php index 8357d62c5c2b..61558e5f06d4 100644 --- a/tests/phpunit/api/v3/CaseTest.php +++ b/tests/phpunit/api/v3/CaseTest.php @@ -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. */