* @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
}
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');
}
/**
$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
*/