Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
50fb255d | 2 | /** |
a828d7b8 | 3 | * Test Generated example demonstrating the Contact.get API. |
50fb255d | 4 | * |
5c49fee0 | 5 | * Demonstrates use of Replace in a nested API call. |
50fb255d | 6 | * |
7 | * @return array | |
8 | * API result array | |
9 | */ | |
a828d7b8 | 10 | function contact_get_example() { |
50fb255d | 11 | $params = array( |
12 | 'id' => 10, | |
13 | 'api.email.replace' => array( | |
53ca8fd7 | 14 | 'values' => array( |
50fb255d | 15 | '0' => array( |
16 | 'location_type_id' => 20, | |
17 | 'email' => '1-1@example.com', | |
18 | 'is_primary' => 1, | |
19 | ), | |
20 | '1' => array( | |
21 | 'location_type_id' => 20, | |
22 | 'email' => '1-2@example.com', | |
23 | 'is_primary' => 0, | |
24 | ), | |
25 | '2' => array( | |
26 | 'location_type_id' => 20, | |
27 | 'email' => '1-3@example.com', | |
28 | 'is_primary' => 0, | |
29 | ), | |
30 | '3' => array( | |
31 | 'location_type_id' => 21, | |
32 | 'email' => '2-1@example.com', | |
33 | 'is_primary' => 0, | |
34 | ), | |
35 | '4' => array( | |
36 | 'location_type_id' => 21, | |
37 | 'email' => '2-2@example.com', | |
38 | 'is_primary' => 0, | |
39 | ), | |
40 | ), | |
41 | ), | |
42 | ); | |
43 | ||
44 | try{ | |
a828d7b8 | 45 | $result = civicrm_api3('Contact', 'get', $params); |
50fb255d | 46 | } |
47 | catch (CiviCRM_API3_Exception $e) { | |
48 | // Handle error here. | |
49 | $errorMessage = $e->getMessage(); | |
50 | $errorCode = $e->getErrorCode(); | |
51 | $errorData = $e->getExtraParams(); | |
52 | return array( | |
5be22f39 | 53 | 'is_error' => 1, |
54 | 'error_message' => $errorMessage, | |
50fb255d | 55 | 'error_code' => $errorCode, |
56 | 'error_data' => $errorData, | |
57 | ); | |
58 | } | |
59 | ||
60 | return $result; | |
61 | } | |
62 | ||
63 | /** | |
64 | * Function returns array of result expected from previous function. | |
65 | * | |
66 | * @return array | |
67 | * API result array | |
68 | */ | |
a828d7b8 | 69 | function contact_get_expectedresult() { |
50fb255d | 70 | |
71 | $expectedResult = array( | |
72 | 'is_error' => 0, | |
73 | 'version' => 3, | |
74 | 'count' => 1, | |
75 | 'id' => 10, | |
76 | 'values' => array( | |
77 | '10' => array( | |
78 | 'contact_id' => '10', | |
79 | 'contact_type' => 'Organization', | |
80 | 'contact_sub_type' => '', | |
81 | 'sort_name' => 'Unit Test Organization', | |
82 | 'display_name' => 'Unit Test Organization', | |
83 | 'do_not_email' => 0, | |
84 | 'do_not_phone' => 0, | |
85 | 'do_not_mail' => 0, | |
86 | 'do_not_sms' => 0, | |
87 | 'do_not_trade' => 0, | |
88 | 'is_opt_out' => 0, | |
89 | 'legal_identifier' => '', | |
90 | 'external_identifier' => '', | |
91 | 'nick_name' => '', | |
92 | 'legal_name' => '', | |
93 | 'image_URL' => '', | |
94 | 'preferred_communication_method' => '', | |
95 | 'preferred_language' => 'en_US', | |
96 | 'preferred_mail_format' => 'Both', | |
97 | 'first_name' => '', | |
98 | 'middle_name' => '', | |
99 | 'last_name' => '', | |
100 | 'prefix_id' => '', | |
101 | 'suffix_id' => '', | |
102 | 'formal_title' => '', | |
103 | 'communication_style_id' => '', | |
104 | 'job_title' => '', | |
105 | 'gender_id' => '', | |
106 | 'birth_date' => '', | |
107 | 'is_deceased' => 0, | |
108 | 'deceased_date' => '', | |
109 | 'household_name' => '', | |
110 | 'organization_name' => 'Unit Test Organization', | |
111 | 'sic_code' => '', | |
112 | 'contact_is_deleted' => 0, | |
113 | 'current_employer' => '', | |
114 | 'address_id' => '', | |
115 | 'street_address' => '', | |
116 | 'supplemental_address_1' => '', | |
117 | 'supplemental_address_2' => '', | |
207f62c6 | 118 | 'supplemental_address_3' => '', |
50fb255d | 119 | 'city' => '', |
120 | 'postal_code_suffix' => '', | |
121 | 'postal_code' => '', | |
122 | 'geo_code_1' => '', | |
123 | 'geo_code_2' => '', | |
124 | 'state_province_id' => '', | |
125 | 'country_id' => '', | |
126 | 'phone_id' => '', | |
127 | 'phone_type_id' => '', | |
128 | 'phone' => '', | |
129 | 'email_id' => '', | |
130 | 'email' => '', | |
131 | 'on_hold' => '', | |
132 | 'im_id' => '', | |
133 | 'provider_id' => '', | |
134 | 'im' => '', | |
135 | 'worldregion_id' => '', | |
136 | 'world_region' => '', | |
137 | 'individual_prefix' => '', | |
138 | 'individual_suffix' => '', | |
139 | 'communication_style' => '', | |
140 | 'gender' => '', | |
141 | 'state_province_name' => '', | |
142 | 'state_province' => '', | |
143 | 'country' => '', | |
144 | 'id' => '10', | |
145 | 'api.email.replace' => array( | |
146 | 'is_error' => 0, | |
147 | 'version' => 3, | |
148 | 'count' => 5, | |
149 | 'values' => array( | |
150 | '0' => array( | |
151 | 'id' => '18', | |
152 | 'contact_id' => '10', | |
153 | 'location_type_id' => '20', | |
6a488035 | 154 | 'email' => '1-1@example.com', |
50fb255d | 155 | 'is_primary' => '1', |
156 | 'is_billing' => '', | |
157 | 'on_hold' => '', | |
158 | 'is_bulkmail' => '', | |
159 | 'hold_date' => '', | |
160 | 'reset_date' => '', | |
161 | 'signature_text' => '', | |
162 | 'signature_html' => '', | |
6a488035 | 163 | ), |
50fb255d | 164 | '1' => array( |
165 | 'id' => '19', | |
166 | 'contact_id' => '10', | |
167 | 'location_type_id' => '20', | |
6a488035 TO |
168 | 'email' => '1-2@example.com', |
169 | 'is_primary' => 0, | |
50fb255d | 170 | 'is_billing' => '', |
171 | 'on_hold' => '', | |
172 | 'is_bulkmail' => '', | |
173 | 'hold_date' => '', | |
174 | 'reset_date' => '', | |
175 | 'signature_text' => '', | |
176 | 'signature_html' => '', | |
6a488035 | 177 | ), |
50fb255d | 178 | '2' => array( |
179 | 'id' => '20', | |
180 | 'contact_id' => '10', | |
181 | 'location_type_id' => '20', | |
6a488035 TO |
182 | 'email' => '1-3@example.com', |
183 | 'is_primary' => 0, | |
50fb255d | 184 | 'is_billing' => '', |
185 | 'on_hold' => '', | |
186 | 'is_bulkmail' => '', | |
187 | 'hold_date' => '', | |
188 | 'reset_date' => '', | |
189 | 'signature_text' => '', | |
190 | 'signature_html' => '', | |
6a488035 | 191 | ), |
50fb255d | 192 | '3' => array( |
193 | 'id' => '21', | |
194 | 'contact_id' => '10', | |
195 | 'location_type_id' => '21', | |
6a488035 TO |
196 | 'email' => '2-1@example.com', |
197 | 'is_primary' => 0, | |
50fb255d | 198 | 'is_billing' => '', |
199 | 'on_hold' => '', | |
200 | 'is_bulkmail' => '', | |
201 | 'hold_date' => '', | |
202 | 'reset_date' => '', | |
203 | 'signature_text' => '', | |
204 | 'signature_html' => '', | |
6a488035 | 205 | ), |
50fb255d | 206 | '4' => array( |
207 | 'id' => '22', | |
208 | 'contact_id' => '10', | |
209 | 'location_type_id' => '21', | |
6a488035 TO |
210 | 'email' => '2-2@example.com', |
211 | 'is_primary' => 0, | |
50fb255d | 212 | 'is_billing' => '', |
213 | 'on_hold' => '', | |
214 | 'is_bulkmail' => '', | |
215 | 'hold_date' => '', | |
216 | 'reset_date' => '', | |
217 | 'signature_text' => '', | |
218 | 'signature_html' => '', | |
6a488035 | 219 | ), |
50fb255d | 220 | ), |
6a488035 | 221 | ), |
50fb255d | 222 | ), |
6a488035 | 223 | ), |
50fb255d | 224 | ); |
6a488035 | 225 | |
fb32de45 | 226 | return $expectedResult; |
6a488035 TO |
227 | } |
228 | ||
a828d7b8 | 229 | /* |
50fb255d | 230 | * This example has been generated from the API test suite. |
a828d7b8 CW |
231 | * The test that created it is called "testReplaceEmailsInChain" |
232 | * and can be found at: | |
69d79249 | 233 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/EmailTest.php |
6a488035 TO |
234 | * |
235 | * You can see the outcome of the API tests at | |
69d79249 | 236 | * https://test.civicrm.org/job/CiviCRM-master-git/ |
6a488035 TO |
237 | * |
238 | * To Learn about the API read | |
69d79249 | 239 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API |
6a488035 | 240 | * |
69d79249 | 241 | * Browse the api on your own site with the api explorer |
41d4d31f | 242 | * http://MYSITE.ORG/path/to/civicrm/api |
6a488035 TO |
243 | * |
244 | * Read more about testing here | |
245 | * http://wiki.civicrm.org/confluence/display/CRM/Testing | |
246 | * | |
247 | * API Standards documentation: | |
248 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards | |
b259a4ab | 249 | */ |