Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
50fb255d | 2 | /** |
a828d7b8 | 3 | * Test Generated example demonstrating the OptionValue.get API. |
50fb255d | 4 | * |
50fb255d | 5 | * @return array |
6 | * API result array | |
7 | */ | |
8 | function option_value_get_example() { | |
cf8f0fff | 9 | $params = [ |
50fb255d | 10 | 'option_group_id' => 1, |
cf8f0fff | 11 | ]; |
6a488035 | 12 | |
50fb255d | 13 | try{ |
a828d7b8 | 14 | $result = civicrm_api3('OptionValue', 'get', $params); |
50fb255d | 15 | } |
16 | catch (CiviCRM_API3_Exception $e) { | |
17 | // Handle error here. | |
18 | $errorMessage = $e->getMessage(); | |
19 | $errorCode = $e->getErrorCode(); | |
20 | $errorData = $e->getExtraParams(); | |
cf8f0fff | 21 | return [ |
5be22f39 | 22 | 'is_error' => 1, |
23 | 'error_message' => $errorMessage, | |
50fb255d | 24 | 'error_code' => $errorCode, |
25 | 'error_data' => $errorData, | |
cf8f0fff | 26 | ]; |
50fb255d | 27 | } |
28 | ||
29 | return $result; | |
6a488035 TO |
30 | } |
31 | ||
fb32de45 | 32 | /** |
50fb255d | 33 | * Function returns array of result expected from previous function. |
34 | * | |
35 | * @return array | |
36 | * API result array | |
6a488035 | 37 | */ |
50fb255d | 38 | function option_value_get_expectedresult() { |
6a488035 | 39 | |
cf8f0fff | 40 | $expectedResult = [ |
50fb255d | 41 | 'is_error' => 0, |
42 | 'version' => 3, | |
43 | 'count' => 5, | |
cf8f0fff CW |
44 | 'values' => [ |
45 | '1' => [ | |
50fb255d | 46 | 'id' => '1', |
47 | 'option_group_id' => '1', | |
48 | 'label' => 'Phone', | |
49 | 'value' => '1', | |
5be22f39 | 50 | 'name' => 'Phone', |
50fb255d | 51 | 'filter' => 0, |
52 | 'weight' => '1', | |
53 | 'is_optgroup' => 0, | |
54 | 'is_reserved' => 0, | |
55 | 'is_active' => '1', | |
cf8f0fff CW |
56 | ], |
57 | '2' => [ | |
50fb255d | 58 | 'id' => '2', |
59 | 'option_group_id' => '1', | |
60 | 'label' => 'Email', | |
61 | 'value' => '2', | |
5be22f39 | 62 | 'name' => 'Email', |
50fb255d | 63 | 'filter' => 0, |
64 | 'weight' => '2', | |
65 | 'is_optgroup' => 0, | |
66 | 'is_reserved' => 0, | |
67 | 'is_active' => '1', | |
cf8f0fff CW |
68 | ], |
69 | '3' => [ | |
50fb255d | 70 | 'id' => '3', |
71 | 'option_group_id' => '1', | |
72 | 'label' => 'Postal Mail', | |
73 | 'value' => '3', | |
5be22f39 | 74 | 'name' => 'Postal Mail', |
50fb255d | 75 | 'filter' => 0, |
76 | 'weight' => '3', | |
77 | 'is_optgroup' => 0, | |
78 | 'is_reserved' => 0, | |
79 | 'is_active' => '1', | |
cf8f0fff CW |
80 | ], |
81 | '4' => [ | |
50fb255d | 82 | 'id' => '4', |
83 | 'option_group_id' => '1', | |
84 | 'label' => 'SMS', | |
85 | 'value' => '4', | |
5be22f39 | 86 | 'name' => 'SMS', |
50fb255d | 87 | 'filter' => 0, |
88 | 'weight' => '4', | |
89 | 'is_optgroup' => 0, | |
90 | 'is_reserved' => 0, | |
91 | 'is_active' => '1', | |
cf8f0fff CW |
92 | ], |
93 | '5' => [ | |
50fb255d | 94 | 'id' => '5', |
95 | 'option_group_id' => '1', | |
96 | 'label' => 'Fax', | |
97 | 'value' => '5', | |
5be22f39 | 98 | 'name' => 'Fax', |
50fb255d | 99 | 'filter' => 0, |
100 | 'weight' => '5', | |
101 | 'is_optgroup' => 0, | |
102 | 'is_reserved' => 0, | |
103 | 'is_active' => '1', | |
cf8f0fff CW |
104 | ], |
105 | ], | |
106 | ]; | |
6a488035 | 107 | |
fb32de45 | 108 | return $expectedResult; |
6a488035 TO |
109 | } |
110 | ||
a828d7b8 | 111 | /* |
50fb255d | 112 | * This example has been generated from the API test suite. |
a828d7b8 CW |
113 | * The test that created it is called "testGetOptionGroup" |
114 | * and can be found at: | |
69d79249 | 115 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/OptionValueTest.php |
6a488035 TO |
116 | * |
117 | * You can see the outcome of the API tests at | |
8390b11b | 118 | * https://test.civicrm.org/job/CiviCRM-Core-Matrix/ |
6a488035 TO |
119 | * |
120 | * To Learn about the API read | |
8390b11b | 121 | * https://docs.civicrm.org/dev/en/latest/api/ |
6a488035 | 122 | * |
8390b11b SL |
123 | * Browse the API on your own site with the API Explorer. It is in the main |
124 | * CiviCRM menu, under: Support > Development > API Explorer. | |
6a488035 TO |
125 | * |
126 | * Read more about testing here | |
8390b11b | 127 | * https://docs.civicrm.org/dev/en/latest/testing/ |
6a488035 TO |
128 | * |
129 | * API Standards documentation: | |
8390b11b | 130 | * https://docs.civicrm.org/dev/en/latest/framework/api-architecture/ |
b259a4ab | 131 | */ |