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