Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
fb32de45 | 2 | /** |
50fb255d | 3 | * @file |
4 | * Test Generated API Example. | |
5 | * See bottom of this file for more detail. | |
6a488035 | 6 | */ |
50fb255d | 7 | |
8 | /** | |
9 | * Test Generated example of using contact get API. | |
10 | * | |
11 | * /*this demonstrates the usage of chained api functions. In this case no notes or custom fields have been created | |
12 | * | |
13 | * @return array | |
14 | * API result array | |
15 | */ | |
16 | function contact_get_example() { | |
17 | $params = array( | |
18 | 'id' => 1, | |
19 | 'api.website.get' => array(), | |
20 | 'api.Contribution.get' => array( | |
6a488035 TO |
21 | 'total_amount' => '120.00', |
22 | ), | |
50fb255d | 23 | 'api.CustomValue.get' => 1, |
24 | 'api.Note.get' => 1, | |
25 | ); | |
6a488035 | 26 | |
50fb255d | 27 | try{ |
28 | $result = civicrm_api3('contact', 'get', $params); | |
29 | } | |
30 | catch (CiviCRM_API3_Exception $e) { | |
31 | // Handle error here. | |
32 | $errorMessage = $e->getMessage(); | |
33 | $errorCode = $e->getErrorCode(); | |
34 | $errorData = $e->getExtraParams(); | |
35 | return array( | |
36 | 'error' => $errorMessage, | |
37 | 'error_code' => $errorCode, | |
38 | 'error_data' => $errorData, | |
39 | ); | |
40 | } | |
6a488035 | 41 | |
50fb255d | 42 | return $result; |
6a488035 TO |
43 | } |
44 | ||
fb32de45 | 45 | /** |
50fb255d | 46 | * Function returns array of result expected from previous function. |
47 | * | |
48 | * @return array | |
49 | * API result array | |
6a488035 | 50 | */ |
50fb255d | 51 | function contact_get_expectedresult() { |
6a488035 | 52 | |
edb0d67a | 53 | $expectedResult = array( |
50fb255d | 54 | 'is_error' => 0, |
55 | 'version' => 3, | |
56 | 'count' => 1, | |
57 | 'id' => 1, | |
58 | 'values' => array( | |
edb0d67a | 59 | '1' => array( |
50fb255d | 60 | 'contact_id' => '1', |
61 | 'contact_type' => 'Individual', | |
62 | 'contact_sub_type' => '', | |
63 | 'sort_name' => 'xyz3, abc3', | |
64 | 'display_name' => 'abc3 xyz3', | |
65 | 'do_not_email' => 0, | |
66 | 'do_not_phone' => 0, | |
67 | 'do_not_mail' => 0, | |
68 | 'do_not_sms' => 0, | |
69 | 'do_not_trade' => 0, | |
70 | 'is_opt_out' => 0, | |
71 | 'legal_identifier' => '', | |
72 | 'external_identifier' => '', | |
73 | 'nick_name' => '', | |
74 | 'legal_name' => '', | |
75 | 'image_URL' => '', | |
76 | 'preferred_communication_method' => '', | |
77 | 'preferred_language' => 'en_US', | |
78 | 'preferred_mail_format' => 'Both', | |
79 | 'first_name' => 'abc3', | |
80 | 'middle_name' => '', | |
81 | 'last_name' => 'xyz3', | |
82 | 'prefix_id' => '', | |
83 | 'suffix_id' => '', | |
84 | 'formal_title' => '', | |
85 | 'communication_style_id' => '', | |
86 | 'job_title' => '', | |
87 | 'gender_id' => '', | |
88 | 'birth_date' => '', | |
89 | 'is_deceased' => 0, | |
90 | 'deceased_date' => '', | |
91 | 'household_name' => '', | |
92 | 'organization_name' => '', | |
93 | 'sic_code' => '', | |
94 | 'contact_is_deleted' => 0, | |
95 | 'current_employer' => '', | |
96 | 'address_id' => '2', | |
97 | 'street_address' => '1 my road', | |
98 | 'supplemental_address_1' => '', | |
99 | 'supplemental_address_2' => '', | |
100 | 'city' => '', | |
101 | 'postal_code_suffix' => '', | |
102 | 'postal_code' => '', | |
103 | 'geo_code_1' => '', | |
104 | 'geo_code_2' => '', | |
105 | 'state_province_id' => '', | |
106 | 'country_id' => '', | |
107 | 'phone_id' => '', | |
108 | 'phone_type_id' => '', | |
109 | 'phone' => '', | |
110 | 'email_id' => '1', | |
111 | 'email' => 'man3@yahoo.com', | |
112 | 'on_hold' => 0, | |
113 | 'im_id' => '', | |
114 | 'provider_id' => '', | |
115 | 'im' => '', | |
116 | 'worldregion_id' => '', | |
117 | 'world_region' => '', | |
118 | 'individual_prefix' => '', | |
119 | 'individual_suffix' => '', | |
120 | 'communication_style' => '', | |
121 | 'gender' => '', | |
122 | 'state_province_name' => '', | |
123 | 'state_province' => '', | |
124 | 'country' => '', | |
125 | 'id' => '1', | |
126 | 'api.website.get' => array( | |
127 | 'is_error' => 0, | |
128 | 'version' => 3, | |
129 | 'count' => 1, | |
130 | 'id' => 1, | |
131 | 'values' => array( | |
132 | '0' => array( | |
133 | 'id' => '1', | |
134 | 'contact_id' => '1', | |
135 | 'url' => 'http://civicrm.org', | |
6a488035 | 136 | ), |
50fb255d | 137 | ), |
138 | ), | |
139 | 'api.Contribution.get' => array( | |
140 | 'is_error' => 0, | |
141 | 'version' => 3, | |
142 | 'count' => 1, | |
143 | 'id' => 2, | |
144 | 'values' => array( | |
145 | '0' => array( | |
146 | 'contact_id' => '1', | |
147 | 'contact_type' => 'Individual', | |
148 | 'contact_sub_type' => '', | |
149 | 'sort_name' => 'xyz3, abc3', | |
150 | 'display_name' => 'abc3 xyz3', | |
151 | 'contribution_id' => '2', | |
152 | 'currency' => 'USD', | |
153 | 'receive_date' => '2011-01-01 00:00:00', | |
154 | 'non_deductible_amount' => '10.00', | |
155 | 'total_amount' => '120.00', | |
156 | 'fee_amount' => '50.00', | |
157 | 'net_amount' => '90.00', | |
158 | 'trxn_id' => '12335', | |
159 | 'invoice_id' => '67830', | |
160 | 'cancel_date' => '', | |
161 | 'cancel_reason' => '', | |
162 | 'receipt_date' => '', | |
163 | 'thankyou_date' => '', | |
164 | 'contribution_source' => 'SSF', | |
165 | 'amount_level' => '', | |
166 | 'is_test' => 0, | |
167 | 'is_pay_later' => 0, | |
168 | 'contribution_status_id' => '1', | |
169 | 'check_number' => '', | |
170 | 'contribution_campaign_id' => '', | |
171 | 'financial_type_id' => '1', | |
172 | 'financial_type' => 'Donation', | |
173 | 'instrument_id' => '86', | |
174 | 'payment_instrument' => 'Credit Card', | |
175 | 'product_id' => '', | |
176 | 'product_name' => '', | |
177 | 'sku' => '', | |
178 | 'contribution_product_id' => '', | |
179 | 'product_option' => '', | |
180 | 'fulfilled_date' => '', | |
181 | 'contribution_start_date' => '', | |
182 | 'contribution_end_date' => '', | |
183 | 'contribution_recur_id' => '', | |
184 | 'financial_account_id' => '1', | |
185 | 'accounting_code' => '4200', | |
186 | 'contribution_note' => '', | |
187 | 'contribution_batch' => '', | |
188 | 'contribution_status' => 'Completed', | |
189 | 'contribution_payment_instrument' => 'Credit Card', | |
190 | 'contribution_check_number' => '', | |
191 | 'id' => '2', | |
192 | 'contribution_type_id' => '1', | |
6a488035 | 193 | ), |
50fb255d | 194 | ), |
195 | ), | |
196 | 'api.CustomValue.get' => array( | |
197 | 'is_error' => 0, | |
198 | 'version' => 3, | |
199 | 'count' => 0, | |
200 | 'values' => array(), | |
201 | ), | |
202 | 'api.Note.get' => array( | |
203 | 'is_error' => 0, | |
204 | 'version' => 3, | |
205 | 'count' => 0, | |
206 | 'values' => array(), | |
6a488035 | 207 | ), |
50fb255d | 208 | ), |
6a488035 | 209 | ), |
50fb255d | 210 | ); |
6a488035 | 211 | |
fb32de45 | 212 | return $expectedResult; |
6a488035 TO |
213 | } |
214 | ||
50fb255d | 215 | /** |
216 | * This example has been generated from the API test suite. | |
217 | * The test that created it is called | |
218 | * testGetIndividualWithChainedArrays | |
219 | * and can be found in | |
69d79249 | 220 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContactTest.php |
6a488035 TO |
221 | * |
222 | * You can see the outcome of the API tests at | |
69d79249 | 223 | * https://test.civicrm.org/job/CiviCRM-master-git/ |
6a488035 TO |
224 | * |
225 | * To Learn about the API read | |
69d79249 | 226 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API |
6a488035 | 227 | * |
69d79249 E |
228 | * Browse the api on your own site with the api explorer |
229 | * http://MYSITE.ORG/path/to/civicrm/api/explorer | |
6a488035 TO |
230 | * |
231 | * Read more about testing here | |
232 | * http://wiki.civicrm.org/confluence/display/CRM/Testing | |
233 | * | |
234 | * API Standards documentation: | |
235 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards | |
b259a4ab | 236 | */ |