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