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