Merge pull request #5020 from pratikshad/4.6-alpha4
[civicrm-core.git] / api / v3 / examples / UFField / Replace.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 uf_field replace API.
10 *
11 *
12 * @return array
13 * API result array
14 */
15 function uf_field_replace_example() {
16 $params = array(
17 'uf_group_id' => 11,
18 'option.autoweight' => '',
19 'values' => array(
20 '0' => array(
21 'field_name' => 'first_name',
22 'field_type' => 'Contact',
23 'visibility' => 'Public Pages and Listings',
24 'weight' => 3,
25 'label' => 'Test First Name',
26 'is_searchable' => 1,
27 'is_active' => 1,
28 ),
29 '1' => array(
30 'field_name' => 'country',
31 'field_type' => 'Contact',
32 'visibility' => 'Public Pages and Listings',
33 'weight' => 2,
34 'label' => 'Test Country',
35 'is_searchable' => 1,
36 'is_active' => 1,
37 'location_type_id' => 1,
38 ),
39 '2' => array(
40 'field_name' => 'phone',
41 'field_type' => 'Contact',
42 'visibility' => 'Public Pages and Listings',
43 'weight' => 1,
44 'label' => 'Test Phone',
45 'is_searchable' => 1,
46 'is_active' => 1,
47 'location_type_id' => 1,
48 'phone_type_id' => 1,
49 ),
50 ),
51 );
52
53 try{
54 $result = civicrm_api3('uf_field', 'replace', $params);
55 }
56 catch (CiviCRM_API3_Exception $e) {
57 // Handle error here.
58 $errorMessage = $e->getMessage();
59 $errorCode = $e->getErrorCode();
60 $errorData = $e->getExtraParams();
61 return array(
62 'error' => $errorMessage,
63 'error_code' => $errorCode,
64 'error_data' => $errorData,
65 );
66 }
67
68 return $result;
69 }
70
71 /**
72 * Function returns array of result expected from previous function.
73 *
74 * @return array
75 * API result array
76 */
77 function uf_field_replace_expectedresult() {
78
79 $expectedResult = array(
80 'is_error' => 0,
81 'version' => 3,
82 'count' => 3,
83 'values' => array(
84 '1' => array(
85 'id' => '1',
86 'uf_group_id' => '11',
87 'field_name' => 'first_name',
88 'is_active' => '1',
89 'is_view' => '',
90 'is_required' => '',
91 'weight' => '3',
92 'help_post' => '',
93 'help_pre' => '',
94 'visibility' => 'Public Pages and Listings',
95 'in_selector' => '',
96 'is_searchable' => '1',
97 'location_type_id' => '',
98 'phone_type_id' => '',
99 'website_type_id' => '',
100 'label' => 'Test First Name',
101 'field_type' => 'Contact',
102 'is_reserved' => '',
103 'is_multi_summary' => '',
104 ),
105 '2' => array(
106 'id' => '2',
107 'uf_group_id' => '11',
108 'field_name' => 'country',
109 'is_active' => '1',
110 'is_view' => '',
111 'is_required' => '',
112 'weight' => '2',
113 'help_post' => '',
114 'help_pre' => '',
115 'visibility' => 'Public Pages and Listings',
116 'in_selector' => '',
117 'is_searchable' => '1',
118 'location_type_id' => '1',
119 'phone_type_id' => '',
120 'website_type_id' => '',
121 'label' => 'Test Country',
122 'field_type' => 'Contact',
123 'is_reserved' => '',
124 'is_multi_summary' => '',
125 ),
126 '3' => array(
127 'id' => '3',
128 'uf_group_id' => '11',
129 'field_name' => 'phone',
130 'is_active' => '1',
131 'is_view' => '',
132 'is_required' => '',
133 'weight' => '1',
134 'help_post' => '',
135 'help_pre' => '',
136 'visibility' => 'Public Pages and Listings',
137 'in_selector' => '',
138 'is_searchable' => '1',
139 'location_type_id' => '1',
140 'phone_type_id' => '1',
141 'website_type_id' => '',
142 'label' => 'Test Phone',
143 'field_type' => 'Contact',
144 'is_reserved' => '',
145 'is_multi_summary' => '',
146 ),
147 ),
148 );
149
150 return $expectedResult;
151 }
152
153 /**
154 * This example has been generated from the API test suite.
155 * The test that created it is called
156 * testReplaceUFFields
157 * and can be found in
158 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/UFFieldTest.php
159 *
160 * You can see the outcome of the API tests at
161 * https://test.civicrm.org/job/CiviCRM-master-git/
162 *
163 * To Learn about the API read
164 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
165 *
166 * Browse the api on your own site with the api explorer
167 * http://MYSITE.ORG/path/to/civicrm/api/explorer
168 *
169 * Read more about testing here
170 * http://wiki.civicrm.org/confluence/display/CRM/Testing
171 *
172 * API Standards documentation:
173 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
174 */