Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
50fb255d | 2 | /** |
a828d7b8 | 3 | * Test Generated example demonstrating the Contact.get API. |
50fb255d | 4 | * |
50fb255d | 5 | * @return array |
6 | * API result array | |
7 | */ | |
8 | function contact_get_example() { | |
9 | $params = array( | |
10 | 'email' => 'man2@yahoo.com', | |
11 | ); | |
6a488035 | 12 | |
50fb255d | 13 | try{ |
a828d7b8 | 14 | $result = civicrm_api3('Contact', 'get', $params); |
50fb255d | 15 | } |
16 | catch (CiviCRM_API3_Exception $e) { | |
17 | // Handle error here. | |
18 | $errorMessage = $e->getMessage(); | |
19 | $errorCode = $e->getErrorCode(); | |
20 | $errorData = $e->getExtraParams(); | |
21 | return array( | |
22 | 'error' => $errorMessage, | |
23 | 'error_code' => $errorCode, | |
24 | 'error_data' => $errorData, | |
25 | ); | |
26 | } | |
27 | ||
28 | return $result; | |
6a488035 TO |
29 | } |
30 | ||
fb32de45 | 31 | /** |
50fb255d | 32 | * Function returns array of result expected from previous function. |
33 | * | |
34 | * @return array | |
35 | * API result array | |
6a488035 | 36 | */ |
50fb255d | 37 | function contact_get_expectedresult() { |
6a488035 | 38 | |
edb0d67a | 39 | $expectedResult = array( |
50fb255d | 40 | 'is_error' => 0, |
41 | 'version' => 3, | |
42 | 'count' => 1, | |
43 | 'id' => 1, | |
44 | 'values' => array( | |
edb0d67a | 45 | '1' => array( |
50fb255d | 46 | 'contact_id' => '1', |
47 | 'contact_type' => 'Individual', | |
48 | 'contact_sub_type' => '', | |
49 | 'sort_name' => 'man2@yahoo.com', | |
50 | 'display_name' => 'man2@yahoo.com', | |
51 | 'do_not_email' => 0, | |
52 | 'do_not_phone' => 0, | |
53 | 'do_not_mail' => 0, | |
54 | 'do_not_sms' => 0, | |
55 | 'do_not_trade' => 0, | |
56 | 'is_opt_out' => 0, | |
57 | 'legal_identifier' => '', | |
58 | 'external_identifier' => '', | |
59 | 'nick_name' => '', | |
60 | 'legal_name' => '', | |
61 | 'image_URL' => '', | |
62 | 'preferred_communication_method' => '', | |
63 | 'preferred_language' => 'en_US', | |
64 | 'preferred_mail_format' => 'Both', | |
65 | 'first_name' => '', | |
66 | 'middle_name' => '', | |
67 | 'last_name' => '', | |
68 | 'prefix_id' => '', | |
69 | 'suffix_id' => '', | |
70 | 'formal_title' => '', | |
71 | 'communication_style_id' => '', | |
72 | 'job_title' => '', | |
73 | 'gender_id' => '', | |
74 | 'birth_date' => '', | |
75 | 'is_deceased' => 0, | |
76 | 'deceased_date' => '', | |
77 | 'household_name' => '', | |
78 | 'organization_name' => '', | |
79 | 'sic_code' => '', | |
80 | 'contact_is_deleted' => 0, | |
81 | 'current_employer' => '', | |
82 | 'address_id' => '2', | |
83 | 'street_address' => '1 my road', | |
84 | 'supplemental_address_1' => '', | |
85 | 'supplemental_address_2' => '', | |
86 | 'city' => '', | |
87 | 'postal_code_suffix' => '', | |
88 | 'postal_code' => '', | |
89 | 'geo_code_1' => '', | |
90 | 'geo_code_2' => '', | |
91 | 'state_province_id' => '', | |
92 | 'country_id' => '', | |
93 | 'phone_id' => '', | |
94 | 'phone_type_id' => '', | |
95 | 'phone' => '', | |
96 | 'email_id' => '1', | |
97 | 'email' => 'man2@yahoo.com', | |
98 | 'on_hold' => 0, | |
99 | 'im_id' => '', | |
100 | 'provider_id' => '', | |
101 | 'im' => '', | |
102 | 'worldregion_id' => '', | |
103 | 'world_region' => '', | |
104 | 'individual_prefix' => '', | |
105 | 'individual_suffix' => '', | |
106 | 'communication_style' => '', | |
107 | 'gender' => '', | |
108 | 'state_province_name' => '', | |
109 | 'state_province' => '', | |
110 | 'country' => '', | |
111 | 'id' => '1', | |
112 | ), | |
6a488035 | 113 | ), |
50fb255d | 114 | ); |
6a488035 | 115 | |
fb32de45 | 116 | return $expectedResult; |
6a488035 TO |
117 | } |
118 | ||
a828d7b8 | 119 | /* |
50fb255d | 120 | * This example has been generated from the API test suite. |
a828d7b8 CW |
121 | * The test that created it is called "testContactGetEmail" |
122 | * and can be found at: | |
69d79249 | 123 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContactTest.php |
6a488035 TO |
124 | * |
125 | * You can see the outcome of the API tests at | |
69d79249 | 126 | * https://test.civicrm.org/job/CiviCRM-master-git/ |
6a488035 TO |
127 | * |
128 | * To Learn about the API read | |
69d79249 | 129 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API |
6a488035 | 130 | * |
69d79249 | 131 | * Browse the api on your own site with the api explorer |
41d4d31f | 132 | * http://MYSITE.ORG/path/to/civicrm/api |
6a488035 TO |
133 | * |
134 | * Read more about testing here | |
135 | * http://wiki.civicrm.org/confluence/display/CRM/Testing | |
136 | * | |
137 | * API Standards documentation: | |
138 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards | |
b259a4ab | 139 | */ |