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