Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
fb32de45 | 2 | /** |
3 | * Test Generated example of using option_group create API | |
4 | * * | |
6a488035 TO |
5 | */ |
6 | function option_group_create_example(){ | |
53ca8fd7 | 7 | $params = array( |
6a488035 TO |
8 | 'sequential' => 1, |
9 | 'name' => 'civicrm_event.amount.560', | |
10 | 'is_reserved' => 1, | |
11 | 'is_active' => 1, | |
53ca8fd7 | 12 | 'api.OptionValue.create' => array( |
6a488035 TO |
13 | 'label' => 'workshop', |
14 | 'value' => 35, | |
15 | 'is_default' => 1, | |
16 | 'is_active' => 1, | |
17 | 'format.only_id' => 1, | |
18 | ), | |
19 | ); | |
20 | ||
fb32de45 | 21 | try{ |
22 | $result = civicrm_api3('option_group', 'create', $params); | |
23 | } | |
24 | catch (CiviCRM_API3_Exception $e) { | |
25 | // handle error here | |
26 | $errorMessage = $e->getMessage(); | |
27 | $errorCode = $e->getErrorCode(); | |
28 | $errorData = $e->getExtraParams(); | |
29 | return array('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData); | |
30 | } | |
6a488035 | 31 | |
fb32de45 | 32 | return $result; |
6a488035 TO |
33 | } |
34 | ||
fb32de45 | 35 | /** |
6a488035 TO |
36 | * Function returns array of result expected from previous function |
37 | */ | |
38 | function option_group_create_expectedresult(){ | |
39 | ||
53ca8fd7 | 40 | $expectedResult = array( |
6a488035 TO |
41 | 'is_error' => 0, |
42 | 'version' => 3, | |
43 | 'count' => 1, | |
fb32de45 | 44 | 'id' => 86, |
53ca8fd7 | 45 | 'values' => array( |
46 | '0' => array( | |
fb32de45 | 47 | 'id' => '86', |
6a488035 TO |
48 | 'name' => 'civicrm_event.amount.560', |
49 | 'title' => '', | |
50 | 'description' => '', | |
51 | 'is_reserved' => '1', | |
52 | 'is_active' => '1', | |
fb32de45 | 53 | 'api.OptionValue.create' => 722, |
6a488035 TO |
54 | ), |
55 | ), | |
56 | ); | |
57 | ||
fb32de45 | 58 | return $expectedResult; |
6a488035 TO |
59 | } |
60 | ||
61 | ||
62 | /* | |
63 | * This example has been generated from the API test suite. The test that created it is called | |
64 | * | |
65 | * testGetOptionCreateSuccess and can be found in | |
66 | * http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/OptionGroupTest.php | |
67 | * | |
68 | * You can see the outcome of the API tests at | |
69 | * http://tests.dev.civicrm.org/trunk/results-api_v3 | |
70 | * | |
71 | * To Learn about the API read | |
72 | * http://book.civicrm.org/developer/current/techniques/api/ | |
73 | * | |
74 | * and review the wiki at | |
75 | * http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs | |
76 | * | |
77 | * Read more about testing here | |
78 | * http://wiki.civicrm.org/confluence/display/CRM/Testing | |
79 | * | |
80 | * API Standards documentation: | |
81 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards | |
82 | */ |