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