Commit | Line | Data |
---|---|---|
dc5a7701 | 1 | <?php |
50fb255d | 2 | /** |
3 | * Test Generated example of using website get API. | |
4 | * | |
5 | * Demonostrates returning field metadata | |
6 | * | |
7 | * @return array | |
8 | * API result array | |
9 | */ | |
10 | function website_get_example() { | |
11 | $params = array( | |
12 | 'options' => array( | |
dc5a7701 | 13 | 'metadata' => array( |
50fb255d | 14 | '0' => 'fields', |
15 | ), | |
dc5a7701 | 16 | ), |
50fb255d | 17 | ); |
dc5a7701 | 18 | |
50fb255d | 19 | try{ |
20 | $result = civicrm_api3('website', 'get', $params); | |
21 | } | |
22 | catch (CiviCRM_API3_Exception $e) { | |
23 | // Handle error here. | |
24 | $errorMessage = $e->getMessage(); | |
25 | $errorCode = $e->getErrorCode(); | |
26 | $errorData = $e->getExtraParams(); | |
27 | return array( | |
28 | 'error' => $errorMessage, | |
29 | 'error_code' => $errorCode, | |
30 | 'error_data' => $errorData, | |
31 | ); | |
32 | } | |
dc5a7701 | 33 | |
50fb255d | 34 | return $result; |
dc5a7701 E |
35 | } |
36 | ||
37 | /** | |
50fb255d | 38 | * Function returns array of result expected from previous function. |
39 | * | |
40 | * @return array | |
41 | * API result array | |
dc5a7701 | 42 | */ |
50fb255d | 43 | function website_get_expectedresult() { |
dc5a7701 E |
44 | |
45 | $expectedResult = array( | |
50fb255d | 46 | 'is_error' => 0, |
47 | 'version' => 3, | |
48 | 'count' => 0, | |
49 | 'values' => array(), | |
50 | 'metadata' => array( | |
dc5a7701 | 51 | 'fields' => array( |
50fb255d | 52 | 'id' => array( |
53 | 'name' => 'id', | |
54 | 'type' => '1', | |
55 | 'title' => 'Website ID', | |
56 | 'required' => '1', | |
57 | 'api.aliases' => array( | |
58 | '0' => 'website_id', | |
59 | ), | |
dc5a7701 | 60 | ), |
50fb255d | 61 | 'contact_id' => array( |
62 | 'name' => 'contact_id', | |
63 | 'type' => '1', | |
64 | 'title' => 'Contact', | |
65 | 'FKClassName' => 'CRM_Contact_DAO_Contact', | |
66 | 'FKApiName' => 'Contact', | |
67 | ), | |
68 | 'url' => array( | |
69 | 'name' => 'url', | |
70 | 'type' => '2', | |
71 | 'title' => 'Website', | |
72 | 'maxlength' => '128', | |
73 | 'size' => '30', | |
74 | 'import' => '1', | |
75 | 'where' => 'civicrm_website.url', | |
76 | 'headerPattern' => '/Website/i', | |
77 | 'dataPattern' => '/^[A-Za-z][0-9A-Za-z]{20,}$/', | |
78 | 'export' => '1', | |
79 | 'html' => array( | |
80 | 'type' => 'Text', | |
81 | ), | |
82 | ), | |
83 | 'website_type_id' => array( | |
84 | 'name' => 'website_type_id', | |
85 | 'type' => '1', | |
86 | 'title' => 'Website Type', | |
87 | 'html' => array( | |
88 | 'type' => 'Select', | |
89 | ), | |
90 | 'pseudoconstant' => array( | |
91 | 'optionGroupName' => 'website_type', | |
92 | ), | |
93 | ), | |
94 | ), | |
dc5a7701 | 95 | ), |
50fb255d | 96 | ); |
dc5a7701 E |
97 | |
98 | return $expectedResult; | |
99 | } | |
100 | ||
50fb255d | 101 | /** |
102 | * This example has been generated from the API test suite. | |
103 | * The test that created it is called | |
104 | * testGetMetadata | |
105 | * and can be found in | |
69d79249 | 106 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/WebsiteTest.php |
dc5a7701 E |
107 | * |
108 | * You can see the outcome of the API tests at | |
69d79249 | 109 | * https://test.civicrm.org/job/CiviCRM-master-git/ |
dc5a7701 E |
110 | * |
111 | * To Learn about the API read | |
69d79249 | 112 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API |
dc5a7701 | 113 | * |
69d79249 | 114 | * Browse the api on your own site with the api explorer |
41d4d31f | 115 | * http://MYSITE.ORG/path/to/civicrm/api |
dc5a7701 E |
116 | * |
117 | * Read more about testing here | |
118 | * http://wiki.civicrm.org/confluence/display/CRM/Testing | |
119 | * | |
120 | * API Standards documentation: | |
121 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards | |
122 | */ |