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