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 TO |
82 | 'phone_type_id' => '', |
83 | 'label' => 'Test First Name', | |
84 | 'field_type' => 'Contact', | |
85 | 'is_reserved' => '', | |
86 | 'is_multi_summary' => '', | |
87 | ), | |
ee600d6f | 88 | '2' => array( |
6a488035 TO |
89 | 'id' => '2', |
90 | 'uf_group_id' => '11', | |
91 | 'field_name' => 'country', | |
92 | 'is_active' => '1', | |
93 | 'is_view' => '', | |
94 | 'is_required' => '', | |
95 | 'weight' => '2', | |
96 | 'help_post' => '', | |
97 | 'help_pre' => '', | |
98 | 'visibility' => 'Public Pages and Listings', | |
99 | 'in_selector' => '', | |
100 | 'is_searchable' => '1', | |
101 | 'location_type_id' => '1', | |
102 | 'phone_type_id' => '', | |
103 | 'label' => 'Test Country', | |
104 | 'field_type' => 'Contact', | |
105 | 'is_reserved' => '', | |
106 | 'is_multi_summary' => '', | |
107 | ), | |
ee600d6f | 108 | '3' => array( |
6a488035 TO |
109 | 'id' => '3', |
110 | 'uf_group_id' => '11', | |
111 | 'field_name' => 'phone', | |
112 | 'is_active' => '1', | |
113 | 'is_view' => '', | |
114 | 'is_required' => '', | |
115 | 'weight' => '1', | |
116 | 'help_post' => '', | |
117 | 'help_pre' => '', | |
118 | 'visibility' => 'Public Pages and Listings', | |
119 | 'in_selector' => '', | |
120 | 'is_searchable' => '1', | |
121 | 'location_type_id' => '1', | |
122 | 'phone_type_id' => '1', | |
123 | 'label' => 'Test Phone', | |
124 | 'field_type' => 'Contact', | |
125 | 'is_reserved' => '', | |
126 | 'is_multi_summary' => '', | |
127 | ), | |
128 | ), | |
129 | ); | |
130 | ||
fb32de45 | 131 | return $expectedResult; |
6a488035 TO |
132 | } |
133 | ||
134 | ||
135 | /* | |
136 | * This example has been generated from the API test suite. The test that created it is called | |
137 | * | |
138 | * testReplaceUFFields and can be found in | |
139 | * http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/UFFieldTest.php | |
140 | * | |
141 | * You can see the outcome of the API tests at | |
142 | * http://tests.dev.civicrm.org/trunk/results-api_v3 | |
143 | * | |
144 | * To Learn about the API read | |
145 | * http://book.civicrm.org/developer/current/techniques/api/ | |
146 | * | |
147 | * and review the wiki at | |
148 | * http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs | |
149 | * | |
150 | * Read more about testing here | |
151 | * http://wiki.civicrm.org/confluence/display/CRM/Testing | |
152 | * | |
153 | * API Standards documentation: | |
154 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards | |
b259a4ab | 155 | */ |