Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
fb32de45 | 2 | /** |
50fb255d | 3 | * @file |
4 | * Test Generated API Example. | |
5 | * See bottom of this file for more detail. | |
6a488035 | 6 | */ |
50fb255d | 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( | |
ee600d6f | 20 | '0' => array( |
50fb255d | 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 | ), | |
ee600d6f | 29 | '1' => array( |
50fb255d | 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 | ), | |
ee600d6f | 39 | '2' => array( |
50fb255d | 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 | ), | |
6a488035 | 50 | ), |
50fb255d | 51 | ); |
6a488035 | 52 | |
50fb255d | 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 | } | |
6a488035 | 67 | |
50fb255d | 68 | return $result; |
6a488035 TO |
69 | } |
70 | ||
fb32de45 | 71 | /** |
50fb255d | 72 | * Function returns array of result expected from previous function. |
73 | * | |
74 | * @return array | |
75 | * API result array | |
6a488035 | 76 | */ |
50fb255d | 77 | function uf_field_replace_expectedresult() { |
6a488035 | 78 | |
ee600d6f | 79 | $expectedResult = array( |
50fb255d | 80 | 'is_error' => 0, |
81 | 'version' => 3, | |
82 | 'count' => 3, | |
83 | 'values' => array( | |
ee600d6f | 84 | '1' => array( |
50fb255d | 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 | ), | |
ee600d6f | 105 | '2' => array( |
50fb255d | 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 | ), | |
ee600d6f | 126 | '3' => array( |
50fb255d | 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 | ), | |
6a488035 | 147 | ), |
50fb255d | 148 | ); |
6a488035 | 149 | |
fb32de45 | 150 | return $expectedResult; |
6a488035 TO |
151 | } |
152 | ||
50fb255d | 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 | |
69d79249 | 158 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/UFFieldTest.php |
6a488035 TO |
159 | * |
160 | * You can see the outcome of the API tests at | |
69d79249 | 161 | * https://test.civicrm.org/job/CiviCRM-master-git/ |
6a488035 TO |
162 | * |
163 | * To Learn about the API read | |
69d79249 | 164 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API |
6a488035 | 165 | * |
69d79249 E |
166 | * Browse the api on your own site with the api explorer |
167 | * http://MYSITE.ORG/path/to/civicrm/api/explorer | |
6a488035 TO |
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 | |
b259a4ab | 174 | */ |