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