Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
50fb255d | 2 | /** |
a828d7b8 | 3 | * Test Generated example demonstrating the UFField.create API. |
50fb255d | 4 | * |
50fb255d | 5 | * @return array |
6 | * API result array | |
7 | */ | |
8 | function uf_field_create_example() { | |
9 | $params = array( | |
10 | 'field_name' => 'phone', | |
11 | 'field_type' => 'Contact', | |
12 | 'visibility' => 'Public Pages and Listings', | |
13 | 'weight' => 1, | |
14 | 'label' => 'Test Phone', | |
15 | 'is_searchable' => 1, | |
16 | 'is_active' => 1, | |
17 | 'location_type_id' => 1, | |
18 | 'phone_type_id' => 1, | |
19 | 'uf_group_id' => 11, | |
20 | ); | |
6a488035 | 21 | |
50fb255d | 22 | try{ |
a828d7b8 | 23 | $result = civicrm_api3('UFField', 'create', $params); |
50fb255d | 24 | } |
25 | catch (CiviCRM_API3_Exception $e) { | |
26 | // Handle error here. | |
27 | $errorMessage = $e->getMessage(); | |
28 | $errorCode = $e->getErrorCode(); | |
29 | $errorData = $e->getExtraParams(); | |
30 | return array( | |
31 | 'error' => $errorMessage, | |
32 | 'error_code' => $errorCode, | |
33 | 'error_data' => $errorData, | |
34 | ); | |
35 | } | |
36 | ||
37 | return $result; | |
6a488035 TO |
38 | } |
39 | ||
fb32de45 | 40 | /** |
50fb255d | 41 | * Function returns array of result expected from previous function. |
42 | * | |
43 | * @return array | |
44 | * API result array | |
6a488035 | 45 | */ |
50fb255d | 46 | function uf_field_create_expectedresult() { |
6a488035 | 47 | |
ee600d6f | 48 | $expectedResult = array( |
50fb255d | 49 | 'is_error' => 0, |
50 | 'version' => 3, | |
51 | 'count' => 1, | |
52 | 'id' => 1, | |
53 | 'values' => array( | |
ee600d6f | 54 | '1' => array( |
50fb255d | 55 | 'id' => '1', |
56 | 'uf_group_id' => '11', | |
57 | 'field_name' => 'phone', | |
58 | 'is_active' => '1', | |
59 | 'is_view' => '', | |
60 | 'is_required' => '', | |
61 | 'weight' => '1', | |
62 | 'help_post' => '', | |
63 | 'help_pre' => '', | |
64 | 'visibility' => 'Public Pages and Listings', | |
65 | 'in_selector' => '', | |
66 | 'is_searchable' => '1', | |
67 | 'location_type_id' => '1', | |
68 | 'phone_type_id' => '1', | |
69 | 'website_type_id' => '', | |
70 | 'label' => 'Test Phone', | |
71 | 'field_type' => 'Contact', | |
72 | 'is_reserved' => '', | |
73 | 'is_multi_summary' => '', | |
74 | ), | |
6a488035 | 75 | ), |
50fb255d | 76 | ); |
6a488035 | 77 | |
fb32de45 | 78 | return $expectedResult; |
6a488035 TO |
79 | } |
80 | ||
a828d7b8 | 81 | /* |
50fb255d | 82 | * This example has been generated from the API test suite. |
a828d7b8 CW |
83 | * The test that created it is called "testCreateUFField" |
84 | * and can be found at: | |
69d79249 | 85 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/UFFieldTest.php |
6a488035 TO |
86 | * |
87 | * You can see the outcome of the API tests at | |
69d79249 | 88 | * https://test.civicrm.org/job/CiviCRM-master-git/ |
6a488035 TO |
89 | * |
90 | * To Learn about the API read | |
69d79249 | 91 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API |
6a488035 | 92 | * |
69d79249 | 93 | * Browse the api on your own site with the api explorer |
41d4d31f | 94 | * http://MYSITE.ORG/path/to/civicrm/api |
6a488035 TO |
95 | * |
96 | * Read more about testing here | |
97 | * http://wiki.civicrm.org/confluence/display/CRM/Testing | |
98 | * | |
99 | * API Standards documentation: | |
100 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards | |
b259a4ab | 101 | */ |