Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
50fb255d | 2 | /** |
a828d7b8 | 3 | * Test Generated example demonstrating the OptionGroup.create API. |
50fb255d | 4 | * |
50fb255d | 5 | * @return array |
6 | * API result array | |
7 | */ | |
8 | function option_group_create_example() { | |
9 | $params = array( | |
10 | 'sequential' => 1, | |
11 | 'name' => 'civicrm_event.amount.560', | |
12 | 'is_reserved' => 1, | |
13 | 'is_active' => 1, | |
14 | 'api.OptionValue.create' => array( | |
6a488035 TO |
15 | 'label' => 'workshop', |
16 | 'value' => 35, | |
17 | 'is_default' => 1, | |
18 | 'is_active' => 1, | |
19 | 'format.only_id' => 1, | |
20 | ), | |
50fb255d | 21 | ); |
6a488035 | 22 | |
50fb255d | 23 | try{ |
a828d7b8 | 24 | $result = civicrm_api3('OptionGroup', 'create', $params); |
50fb255d | 25 | } |
26 | catch (CiviCRM_API3_Exception $e) { | |
27 | // Handle error here. | |
28 | $errorMessage = $e->getMessage(); | |
29 | $errorCode = $e->getErrorCode(); | |
30 | $errorData = $e->getExtraParams(); | |
31 | return array( | |
32 | 'error' => $errorMessage, | |
33 | 'error_code' => $errorCode, | |
34 | 'error_data' => $errorData, | |
35 | ); | |
36 | } | |
6a488035 | 37 | |
50fb255d | 38 | return $result; |
6a488035 TO |
39 | } |
40 | ||
fb32de45 | 41 | /** |
50fb255d | 42 | * Function returns array of result expected from previous function. |
43 | * | |
44 | * @return array | |
45 | * API result array | |
6a488035 | 46 | */ |
50fb255d | 47 | function option_group_create_expectedresult() { |
6a488035 | 48 | |
53ca8fd7 | 49 | $expectedResult = array( |
50fb255d | 50 | 'is_error' => 0, |
51 | 'version' => 3, | |
52 | 'count' => 1, | |
5c49fee0 | 53 | 'id' => 93, |
50fb255d | 54 | 'values' => array( |
53ca8fd7 | 55 | '0' => array( |
5c49fee0 | 56 | 'id' => '93', |
50fb255d | 57 | 'name' => 'civicrm_event.amount.560', |
58 | 'title' => '', | |
59 | 'description' => '', | |
60 | 'is_reserved' => '1', | |
61 | 'is_active' => '1', | |
62 | 'is_locked' => '', | |
5c49fee0 | 63 | 'api.OptionValue.create' => 784, |
50fb255d | 64 | ), |
6a488035 | 65 | ), |
50fb255d | 66 | ); |
6a488035 | 67 | |
fb32de45 | 68 | return $expectedResult; |
6a488035 TO |
69 | } |
70 | ||
a828d7b8 | 71 | /* |
50fb255d | 72 | * This example has been generated from the API test suite. |
a828d7b8 CW |
73 | * The test that created it is called "testGetOptionCreateSuccess" |
74 | * and can be found at: | |
69d79249 | 75 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/OptionGroupTest.php |
6a488035 TO |
76 | * |
77 | * You can see the outcome of the API tests at | |
69d79249 | 78 | * https://test.civicrm.org/job/CiviCRM-master-git/ |
6a488035 TO |
79 | * |
80 | * To Learn about the API read | |
69d79249 | 81 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API |
6a488035 | 82 | * |
69d79249 | 83 | * Browse the api on your own site with the api explorer |
41d4d31f | 84 | * http://MYSITE.ORG/path/to/civicrm/api |
6a488035 TO |
85 | * |
86 | * Read more about testing here | |
87 | * http://wiki.civicrm.org/confluence/display/CRM/Testing | |
88 | * | |
89 | * API Standards documentation: | |
90 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards | |
b259a4ab | 91 | */ |