From: richard Date: Wed, 13 Nov 2013 15:37:56 +0000 (+0000) Subject: CRM-13023 - API Case - Allow Get method to be called with no parameters or with entit... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=f21557af84b7e1a97017cf7d61a08532e15645c7;p=civicrm-core.git CRM-13023 - API Case - Allow Get method to be called with no parameters or with entity fields as normal ---------------------------------------- * CRM-13023: API Case Entity and Get Action can not be called without search fields http://issues.civicrm.org/jira/browse/CRM-13023 --- diff --git a/api/v3/Case.php b/api/v3/Case.php index 063d6de4f3..30a5b13ffa 100644 --- a/api/v3/Case.php +++ b/api/v3/Case.php @@ -190,10 +190,6 @@ function _civicrm_api3_case_delete_spec(&$params) { * @todo Erik Hommel 16 dec 2010 check if all DB fields are returned */ function civicrm_api3_case_get($params) { - civicrm_api3_verify_mandatory($params, NULL, array( - array('case_id', 'contact_id', 'activity_id', 'contact_id') - )); - $options = _civicrm_api3_get_options_from_params($params); // Get by id @@ -265,6 +261,16 @@ SELECT DISTINCT case_id } return civicrm_api3_create_success($cases, $params, 'case', 'get'); } + + $foundcases = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, TRUE, 'Case'); + $cases = array(); + foreach ($foundcases['values'] as $foundcase) { + if ($case = _civicrm_api3_case_read($foundcase['id'], $options)) { + $cases[$foundcase['id']] = $case; + } + } + + return civicrm_api3_create_success($cases, $params, 'case', 'get'); } /** diff --git a/tests/phpunit/api/v3/CaseTest.php b/tests/phpunit/api/v3/CaseTest.php index 10197f68b1..c698924cdb 100644 --- a/tests/phpunit/api/v3/CaseTest.php +++ b/tests/phpunit/api/v3/CaseTest.php @@ -361,6 +361,50 @@ class api_v3_CaseTest extends CiviUnitTestCase { $this->assertAPIArrayComparison($result['values'][$id], $case); } + /** + * Test get function based on subject + */ + function testCaseGetBySubject() { + // Create Case + $result = $this->callAPISuccess('case', 'create', $this->_params); + $id = $result['id']; + + // Store result for later + $case = $this->callAPISuccess('case', 'getsingle', array('id' => $id)); + + // Fetch case based on client contact id + $result = $this->callAPISuccess('case', 'get', array('subject' => $this->_params['subject'], 'return' => array('activities', 'contacts'))); + $this->assertAPIArrayComparison($result['values'][$id], $case); + } + + /** + * Test get function based on wrong subject + */ + function testCaseGetByWrongSubject() { + // Create Case + $result = $this->callAPISuccess('case', 'create', $this->_params); + $id = $result['id']; + + // Append 'wrong' to subject so that it is no longer the same + $result = $this->callAPISuccess('case', 'get', array('subject' => $this->_params['subject'] . 'wrong', 'return' => array('activities', 'contacts'))); + $this->assertEquals(0, $result['count'], 'in line ' . __LINE__); + } + + /** + * Test get function with no criteria + */ + function testCaseGetNoCriteria() { + // Create Case + $result = $this->callAPISuccess('case', 'create', $this->_params); + $id = $result['id']; + + // Store result for later + $case = $this->callAPISuccess('case', 'getsingle', array('id' => $id)); + + $result = $this->callAPISuccess('case', 'get', array('return' => array('activities', 'contacts'))); + $this->assertAPIArrayComparison($result['values'][$id], $case); + } + /** * Test activity api create for case activities */