Commit | Line | Data |
---|---|---|
fb32de45 | 1 | <?php |
2 | /** | |
3 | * Test Generated example of using tag getfields API | |
9657ccf2 | 4 | * demonstrate use of getfields to interrogate api * |
fb32de45 | 5 | */ |
6 | function tag_getfields_example(){ | |
7 | $params = array( | |
8 | 'action' => 'create', | |
9 | ); | |
10 | ||
11 | try{ | |
12 | $result = civicrm_api3('tag', 'getfields', $params); | |
13 | } | |
14 | catch (CiviCRM_API3_Exception $e) { | |
15 | // handle error here | |
16 | $errorMessage = $e->getMessage(); | |
17 | $errorCode = $e->getErrorCode(); | |
18 | $errorData = $e->getExtraParams(); | |
19 | return array('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData); | |
20 | } | |
21 | ||
22 | return $result; | |
23 | } | |
24 | ||
25 | /** | |
26 | * Function returns array of result expected from previous function | |
27 | */ | |
28 | function tag_getfields_expectedresult(){ | |
29 | ||
30 | $expectedResult = array( | |
31 | 'is_error' => 0, | |
32 | 'version' => 3, | |
33 | 'count' => 10, | |
34 | 'values' => array( | |
35 | 'id' => array( | |
36 | 'name' => 'id', | |
37 | 'type' => 1, | |
89bf81b4 | 38 | 'title' => 'Tag ID', |
fb32de45 | 39 | 'required' => true, |
40 | 'api.aliases' => array( | |
41 | '0' => 'tag', | |
42 | ), | |
43 | ), | |
44 | 'name' => array( | |
45 | 'name' => 'name', | |
46 | 'type' => 2, | |
89bf81b4 | 47 | 'title' => 'Tag Name', |
fb32de45 | 48 | 'required' => true, |
49 | 'maxlength' => 64, | |
50 | 'size' => 30, | |
51 | 'api.required' => 1, | |
52 | ), | |
53 | 'description' => array( | |
54 | 'name' => 'description', | |
55 | 'type' => 2, | |
56 | 'title' => 'Description', | |
57 | 'maxlength' => 255, | |
58 | 'size' => 45, | |
59 | ), | |
60 | 'parent_id' => array( | |
61 | 'name' => 'parent_id', | |
62 | 'type' => 1, | |
89bf81b4 | 63 | 'title' => 'Parent Tag', |
b259a4ab | 64 | 'default' => 'NULL', |
fb32de45 | 65 | 'FKClassName' => 'CRM_Core_DAO_Tag', |
66 | ), | |
67 | 'is_selectable' => array( | |
68 | 'name' => 'is_selectable', | |
69 | 'type' => 16, | |
89bf81b4 | 70 | 'title' => 'Display Tag?', |
b259a4ab | 71 | 'default' => '1', |
fb32de45 | 72 | ), |
73 | 'is_reserved' => array( | |
74 | 'name' => 'is_reserved', | |
75 | 'type' => 16, | |
89bf81b4 | 76 | 'title' => 'Reserved', |
fb32de45 | 77 | ), |
78 | 'is_tagset' => array( | |
79 | 'name' => 'is_tagset', | |
80 | 'type' => 16, | |
89bf81b4 | 81 | 'title' => 'Tagset', |
fb32de45 | 82 | ), |
83 | 'used_for' => array( | |
84 | 'name' => 'used_for', | |
85 | 'type' => 2, | |
86 | 'title' => 'Used For', | |
87 | 'maxlength' => 64, | |
88 | 'size' => 30, | |
b259a4ab | 89 | 'default' => 'NULL', |
89bf81b4 | 90 | 'html' => array( |
91 | 'type' => 'Select', | |
92 | ), | |
93 | 'pseudoconstant' => array( | |
94 | 'optionGroupName' => 'tag_used_for', | |
95 | ), | |
fb32de45 | 96 | 'api.default' => 'civicrm_contact', |
97 | ), | |
98 | 'created_id' => array( | |
99 | 'name' => 'created_id', | |
100 | 'type' => 1, | |
89bf81b4 | 101 | 'title' => 'Tag Created By', |
fb32de45 | 102 | 'FKClassName' => 'CRM_Contact_DAO_Contact', |
103 | ), | |
104 | 'created_date' => array( | |
105 | 'name' => 'created_date', | |
106 | 'type' => 12, | |
107 | 'title' => 'Tag Created Date', | |
108 | ), | |
109 | ), | |
110 | ); | |
111 | ||
112 | return $expectedResult; | |
113 | } | |
114 | ||
115 | ||
116 | /* | |
117 | * This example has been generated from the API test suite. The test that created it is called | |
118 | * | |
119 | * testTagGetfields and can be found in | |
69d79249 | 120 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/TagTest.php |
fb32de45 | 121 | * |
122 | * You can see the outcome of the API tests at | |
69d79249 | 123 | * https://test.civicrm.org/job/CiviCRM-master-git/ |
fb32de45 | 124 | * |
125 | * To Learn about the API read | |
69d79249 | 126 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API |
fb32de45 | 127 | * |
69d79249 E |
128 | * Browse the api on your own site with the api explorer |
129 | * http://MYSITE.ORG/path/to/civicrm/api/explorer | |
fb32de45 | 130 | * |
131 | * Read more about testing here | |
132 | * http://wiki.civicrm.org/confluence/display/CRM/Testing | |
133 | * | |
134 | * API Standards documentation: | |
135 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards | |
b259a4ab | 136 | */ |