Merge pull request #5058 from eileenmcnaughton/test-examples
[civicrm-core.git] / api / v3 / examples / Contact / ChainTwoWebsites.php
1 <?php
2 /**
3 * @file
4 * Test Generated API Example.
5 * See bottom of this file for more detail.
6 */
7
8 /**
9 * Test Generated example of using contact create API.
10 *
11 * test demonstrates the syntax to create 2 chained entities
12 *
13 * @return array
14 * API result array
15 */
16 function contact_create_example() {
17 $params = array(
18 'first_name' => 'abc3',
19 'last_name' => 'xyz3',
20 'contact_type' => 'Individual',
21 'email' => 'man3@yahoo.com',
22 'api.contribution.create' => array(
23 'receive_date' => '2010-01-01',
24 'total_amount' => '100',
25 'financial_type_id' => 1,
26 'payment_instrument_id' => 1,
27 'non_deductible_amount' => '10',
28 'fee_amount' => '50',
29 'net_amount' => '90',
30 'trxn_id' => 15345,
31 'invoice_id' => 67990,
32 'source' => 'SSF',
33 'contribution_status_id' => 1,
34 ),
35 'api.website.create' => array(
36 'url' => 'http://civicrm.org',
37 ),
38 'api.website.create.2' => array(
39 'url' => 'http://chained.org',
40 ),
41 );
42
43 try{
44 $result = civicrm_api3('contact', 'create', $params);
45 }
46 catch (CiviCRM_API3_Exception $e) {
47 // Handle error here.
48 $errorMessage = $e->getMessage();
49 $errorCode = $e->getErrorCode();
50 $errorData = $e->getExtraParams();
51 return array(
52 'error' => $errorMessage,
53 'error_code' => $errorCode,
54 'error_data' => $errorData,
55 );
56 }
57
58 return $result;
59 }
60
61 /**
62 * Function returns array of result expected from previous function.
63 *
64 * @return array
65 * API result array
66 */
67 function contact_create_expectedresult() {
68
69 $expectedResult = array(
70 'is_error' => 0,
71 'version' => 3,
72 'count' => 1,
73 'id' => 1,
74 'values' => array(
75 '1' => array(
76 'id' => '1',
77 'contact_type' => 'Individual',
78 'contact_sub_type' => '',
79 'do_not_email' => 0,
80 'do_not_phone' => 0,
81 'do_not_mail' => 0,
82 'do_not_sms' => 0,
83 'do_not_trade' => 0,
84 'is_opt_out' => 0,
85 'legal_identifier' => '',
86 'external_identifier' => '',
87 'sort_name' => 'xyz3, abc3',
88 'display_name' => 'abc3 xyz3',
89 'nick_name' => '',
90 'legal_name' => '',
91 'image_URL' => '',
92 'preferred_communication_method' => '',
93 'preferred_language' => 'en_US',
94 'preferred_mail_format' => 'Both',
95 'hash' => '67eac7789eaee00',
96 'api_key' => '',
97 'first_name' => 'abc3',
98 'middle_name' => '',
99 'last_name' => 'xyz3',
100 'prefix_id' => '',
101 'suffix_id' => '',
102 'formal_title' => '',
103 'communication_style_id' => '',
104 'email_greeting_id' => '1',
105 'email_greeting_custom' => '',
106 'email_greeting_display' => '',
107 'postal_greeting_id' => '1',
108 'postal_greeting_custom' => '',
109 'postal_greeting_display' => '',
110 'addressee_id' => '1',
111 'addressee_custom' => '',
112 'addressee_display' => '',
113 'job_title' => '',
114 'gender_id' => '',
115 'birth_date' => '',
116 'is_deceased' => 0,
117 'deceased_date' => '',
118 'household_name' => '',
119 'primary_contact_id' => '',
120 'organization_name' => '',
121 'sic_code' => '',
122 'user_unique_id' => '',
123 'created_date' => '2013-07-28 08:49:19',
124 'modified_date' => '2012-11-14 16:02:35',
125 'api.contribution.create' => array(
126 'is_error' => 0,
127 'version' => 3,
128 'count' => 1,
129 'id' => 1,
130 'values' => array(
131 '0' => array(
132 'id' => '1',
133 'contact_id' => '1',
134 'financial_type_id' => '1',
135 'contribution_page_id' => '',
136 'payment_instrument_id' => '1',
137 'receive_date' => '20100101000000',
138 'non_deductible_amount' => '10',
139 'total_amount' => '100',
140 'fee_amount' => '50',
141 'net_amount' => '90',
142 'trxn_id' => '15345',
143 'invoice_id' => '67990',
144 'currency' => 'USD',
145 'cancel_date' => '',
146 'cancel_reason' => '',
147 'receipt_date' => '',
148 'thankyou_date' => '',
149 'source' => 'SSF',
150 'amount_level' => '',
151 'contribution_recur_id' => '',
152 'is_test' => '',
153 'is_pay_later' => '',
154 'contribution_status_id' => '1',
155 'address_id' => '',
156 'check_number' => '',
157 'campaign_id' => '',
158 'creditnote_id' => '',
159 'tax_amount' => '',
160 'contribution_type_id' => '1',
161 ),
162 ),
163 ),
164 'api.website.create' => array(
165 'is_error' => 0,
166 'version' => 3,
167 'count' => 1,
168 'id' => 1,
169 'values' => array(
170 '0' => array(
171 'id' => '1',
172 'contact_id' => '1',
173 'url' => 'http://civicrm.org',
174 'website_type_id' => '',
175 ),
176 ),
177 ),
178 'api.website.create.2' => array(
179 'is_error' => 0,
180 'version' => 3,
181 'count' => 1,
182 'id' => 2,
183 'values' => array(
184 '0' => array(
185 'id' => '2',
186 'contact_id' => '1',
187 'url' => 'http://chained.org',
188 'website_type_id' => '',
189 ),
190 ),
191 ),
192 ),
193 ),
194 );
195
196 return $expectedResult;
197 }
198
199 /**
200 * This example has been generated from the API test suite.
201 * The test that created it is called
202 * testCreateIndividualWithContributionDottedSyntax
203 * and can be found in
204 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContactTest.php
205 *
206 * You can see the outcome of the API tests at
207 * https://test.civicrm.org/job/CiviCRM-master-git/
208 *
209 * To Learn about the API read
210 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
211 *
212 * Browse the api on your own site with the api explorer
213 * http://MYSITE.ORG/path/to/civicrm/api/explorer
214 *
215 * Read more about testing here
216 * http://wiki.civicrm.org/confluence/display/CRM/Testing
217 *
218 * API Standards documentation:
219 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
220 */