Commit | Line | Data |
---|---|---|
ceb6db34 | 1 | <?php |
50fb255d | 2 | /** |
a828d7b8 | 3 | * Test Generated example demonstrating the Case.create API. |
50fb255d | 4 | * |
50fb255d | 5 | * @return array |
6 | * API result array | |
7 | */ | |
8 | function case_create_example() { | |
cf8f0fff | 9 | $params = [ |
50fb255d | 10 | 'subject' => 'Test case', |
11 | 'contact_id' => 17, | |
12 | 'case_type' => 'housing_support', | |
cf8f0fff | 13 | ]; |
ceb6db34 | 14 | |
50fb255d | 15 | try{ |
a828d7b8 | 16 | $result = civicrm_api3('Case', 'create', $params); |
50fb255d | 17 | } |
18 | catch (CiviCRM_API3_Exception $e) { | |
19 | // Handle error here. | |
20 | $errorMessage = $e->getMessage(); | |
21 | $errorCode = $e->getErrorCode(); | |
22 | $errorData = $e->getExtraParams(); | |
cf8f0fff | 23 | return [ |
5be22f39 | 24 | 'is_error' => 1, |
25 | 'error_message' => $errorMessage, | |
50fb255d | 26 | 'error_code' => $errorCode, |
27 | 'error_data' => $errorData, | |
cf8f0fff | 28 | ]; |
50fb255d | 29 | } |
30 | ||
31 | return $result; | |
ceb6db34 E |
32 | } |
33 | ||
34 | /** | |
50fb255d | 35 | * Function returns array of result expected from previous function. |
36 | * | |
37 | * @return array | |
38 | * API result array | |
ceb6db34 | 39 | */ |
50fb255d | 40 | function case_create_expectedresult() { |
ceb6db34 | 41 | |
cf8f0fff | 42 | $expectedResult = [ |
50fb255d | 43 | 'is_error' => 0, |
44 | 'version' => 3, | |
45 | 'count' => 1, | |
46 | 'id' => 2, | |
cf8f0fff CW |
47 | 'values' => [ |
48 | '2' => [ | |
50fb255d | 49 | 'id' => '2', |
50 | 'case_type_id' => '1', | |
51 | 'subject' => 'Test case', | |
52 | 'start_date' => '2013-07-29 00:00:00', | |
53 | 'end_date' => '', | |
54 | 'details' => '', | |
55 | 'status_id' => '1', | |
56 | 'is_deleted' => '', | |
cf8f0fff CW |
57 | ], |
58 | ], | |
59 | ]; | |
ceb6db34 E |
60 | |
61 | return $expectedResult; | |
62 | } | |
63 | ||
a828d7b8 | 64 | /* |
50fb255d | 65 | * This example has been generated from the API test suite. |
a828d7b8 CW |
66 | * The test that created it is called "testCaseCreate" |
67 | * and can be found at: | |
ceb6db34 E |
68 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/CaseTest.php |
69 | * | |
70 | * You can see the outcome of the API tests at | |
71 | * https://test.civicrm.org/job/CiviCRM-master-git/ | |
72 | * | |
73 | * To Learn about the API read | |
74 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API | |
75 | * | |
76 | * Browse the api on your own site with the api explorer | |
41d4d31f | 77 | * http://MYSITE.ORG/path/to/civicrm/api |
ceb6db34 E |
78 | * |
79 | * Read more about testing here | |
80 | * http://wiki.civicrm.org/confluence/display/CRM/Testing | |
81 | * | |
82 | * API Standards documentation: | |
83 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards | |
84 | */ |