Merge pull request #5058 from eileenmcnaughton/test-examples
[civicrm-core.git] / api / v3 / examples / Contact / Create.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 * /*this demonstrates setting a custom field through the API
12 *
13 * @return array
14 * API result array
15 */
16 function contact_create_example() {
17 $params = array(
18 'first_name' => 'abc1',
19 'contact_type' => 'Individual',
20 'last_name' => 'xyz1',
21 'custom_1' => 'custom string',
22 );
23
24 try{
25 $result = civicrm_api3('contact', 'create', $params);
26 }
27 catch (CiviCRM_API3_Exception $e) {
28 // Handle error here.
29 $errorMessage = $e->getMessage();
30 $errorCode = $e->getErrorCode();
31 $errorData = $e->getExtraParams();
32 return array(
33 'error' => $errorMessage,
34 'error_code' => $errorCode,
35 'error_data' => $errorData,
36 );
37 }
38
39 return $result;
40 }
41
42 /**
43 * Function returns array of result expected from previous function.
44 *
45 * @return array
46 * API result array
47 */
48 function contact_create_expectedresult() {
49
50 $expectedResult = array(
51 'is_error' => 0,
52 'version' => 3,
53 'count' => 1,
54 'id' => 1,
55 'values' => array(
56 '1' => array(
57 'id' => '1',
58 'contact_type' => 'Individual',
59 'contact_sub_type' => '',
60 'do_not_email' => 0,
61 'do_not_phone' => 0,
62 'do_not_mail' => 0,
63 'do_not_sms' => 0,
64 'do_not_trade' => 0,
65 'is_opt_out' => 0,
66 'legal_identifier' => '',
67 'external_identifier' => '',
68 'sort_name' => 'xyz1, abc1',
69 'display_name' => 'abc1 xyz1',
70 'nick_name' => '',
71 'legal_name' => '',
72 'image_URL' => '',
73 'preferred_communication_method' => '',
74 'preferred_language' => 'en_US',
75 'preferred_mail_format' => 'Both',
76 'hash' => '67eac7789eaee00',
77 'api_key' => '',
78 'first_name' => 'abc1',
79 'middle_name' => '',
80 'last_name' => 'xyz1',
81 'prefix_id' => '',
82 'suffix_id' => '',
83 'formal_title' => '',
84 'communication_style_id' => '',
85 'email_greeting_id' => '1',
86 'email_greeting_custom' => '',
87 'email_greeting_display' => '',
88 'postal_greeting_id' => '1',
89 'postal_greeting_custom' => '',
90 'postal_greeting_display' => '',
91 'addressee_id' => '1',
92 'addressee_custom' => '',
93 'addressee_display' => '',
94 'job_title' => '',
95 'gender_id' => '',
96 'birth_date' => '',
97 'is_deceased' => 0,
98 'deceased_date' => '',
99 'household_name' => '',
100 'primary_contact_id' => '',
101 'organization_name' => '',
102 'sic_code' => '',
103 'user_unique_id' => '',
104 'created_date' => '2013-07-28 08:49:19',
105 'modified_date' => '2012-11-14 16:02:35',
106 ),
107 ),
108 );
109
110 return $expectedResult;
111 }
112
113 /**
114 * This example has been generated from the API test suite.
115 * The test that created it is called
116 * testCreateWithCustom
117 * and can be found in
118 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContactTest.php
119 *
120 * You can see the outcome of the API tests at
121 * https://test.civicrm.org/job/CiviCRM-master-git/
122 *
123 * To Learn about the API read
124 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
125 *
126 * Browse the api on your own site with the api explorer
127 * http://MYSITE.ORG/path/to/civicrm/api/explorer
128 *
129 * Read more about testing here
130 * http://wiki.civicrm.org/confluence/display/CRM/Testing
131 *
132 * API Standards documentation:
133 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
134 */