test tweaks and updated examples
[civicrm-core.git] / api / v3 / examples / Email / NestedReplaceEmail.php
CommitLineData
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 */
6function 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 40try{
41 $result = civicrm_api3('email', 'replace', $params);
42}
43catch (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 51return $result;
6a488035
TO
52}
53
fb32de45 54/**
6a488035
TO
55 * Function returns array of result expected from previous function
56 */
57function 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' => '',
82 'preferred_mail_format' => 'Both',
83 'first_name' => '',
84 'middle_name' => '',
85 'last_name' => '',
86 'job_title' => '',
87 'birth_date' => '',
88 'is_deceased' => 0,
89 'deceased_date' => '',
90 'household_name' => '',
91 'organization_name' => 'Unit Test Organization',
92 'sic_code' => '',
93 'contact_is_deleted' => 0,
6a488035
TO
94 'current_employer' => '',
95 'address_id' => '',
96 'street_address' => '',
97 'supplemental_address_1' => '',
98 'supplemental_address_2' => '',
99 'city' => '',
100 'postal_code_suffix' => '',
101 'postal_code' => '',
102 'geo_code_1' => '',
103 'geo_code_2' => '',
104 'state_province_id' => '',
6a488035 105 'country_id' => '',
6a488035
TO
106 'phone_id' => '',
107 'phone_type_id' => '',
108 'phone' => '',
109 'email_id' => '',
110 'email' => '',
111 'on_hold' => '',
112 'im_id' => '',
113 'provider_id' => '',
114 'im' => '',
115 'worldregion_id' => '',
116 'world_region' => '',
9f1b81e0 117 'state_province_name' => '',
118 'state_province' => '',
119 'country' => '',
6a488035 120 'id' => '10',
53ca8fd7 121 'api.email.replace' => array(
6a488035
TO
122 'is_error' => 0,
123 'version' => 3,
124 'count' => 5,
53ca8fd7 125 'values' => array(
126 '0' => array(
6a488035
TO
127 'id' => '18',
128 'contact_id' => '10',
129 'location_type_id' => '20',
130 'email' => '1-1@example.com',
131 'is_primary' => '1',
132 'is_billing' => '',
133 'on_hold' => '',
134 'is_bulkmail' => '',
135 'hold_date' => '',
136 'reset_date' => '',
137 'signature_text' => '',
138 'signature_html' => '',
139 ),
53ca8fd7 140 '1' => array(
6a488035
TO
141 'id' => '19',
142 'contact_id' => '10',
143 'location_type_id' => '20',
144 'email' => '1-2@example.com',
145 'is_primary' => 0,
146 'is_billing' => '',
147 'on_hold' => '',
148 'is_bulkmail' => '',
149 'hold_date' => '',
150 'reset_date' => '',
151 'signature_text' => '',
152 'signature_html' => '',
153 ),
53ca8fd7 154 '2' => array(
6a488035
TO
155 'id' => '20',
156 'contact_id' => '10',
157 'location_type_id' => '20',
158 'email' => '1-3@example.com',
159 'is_primary' => 0,
160 'is_billing' => '',
161 'on_hold' => '',
162 'is_bulkmail' => '',
163 'hold_date' => '',
164 'reset_date' => '',
165 'signature_text' => '',
166 'signature_html' => '',
167 ),
53ca8fd7 168 '3' => array(
6a488035
TO
169 'id' => '21',
170 'contact_id' => '10',
171 'location_type_id' => '21',
172 'email' => '2-1@example.com',
173 'is_primary' => 0,
174 'is_billing' => '',
175 'on_hold' => '',
176 'is_bulkmail' => '',
177 'hold_date' => '',
178 'reset_date' => '',
179 'signature_text' => '',
180 'signature_html' => '',
181 ),
53ca8fd7 182 '4' => array(
6a488035
TO
183 'id' => '22',
184 'contact_id' => '10',
185 'location_type_id' => '21',
186 'email' => '2-2@example.com',
187 'is_primary' => 0,
188 'is_billing' => '',
189 'on_hold' => '',
190 'is_bulkmail' => '',
191 'hold_date' => '',
192 'reset_date' => '',
193 'signature_text' => '',
194 'signature_html' => '',
195 ),
196 ),
197 ),
198 ),
199 ),
200);
201
fb32de45 202 return $expectedResult;
6a488035
TO
203}
204
205
206/*
207* This example has been generated from the API test suite. The test that created it is called
208*
209* testReplaceEmailsInChain and can be found in
210* http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/EmailTest.php
211*
212* You can see the outcome of the API tests at
213* http://tests.dev.civicrm.org/trunk/results-api_v3
214*
215* To Learn about the API read
216* http://book.civicrm.org/developer/current/techniques/api/
217*
218* and review the wiki at
219* http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs
220*
221* Read more about testing here
222* http://wiki.civicrm.org/confluence/display/CRM/Testing
223*
224* API Standards documentation:
225* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
226*/