Merge pull request #2714 from jitendrapurohit/CRMTestFix
[civicrm-core.git] / api / v3 / examples / OptionGroup / Create.php
CommitLineData
6a488035 1<?php
fb32de45 2/**
3 * Test Generated example of using option_group create API
4 * *
6a488035
TO
5 */
6function 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 21try{
22 $result = civicrm_api3('option_group', 'create', $params);
23}
24catch (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 32return $result;
6a488035
TO
33}
34
fb32de45 35/**
6a488035
TO
36 * Function returns array of result expected from previous function
37 */
38function 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',
b259a4ab 53 'api.OptionValue.create' => 727,
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
69d79249 66* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/OptionGroupTest.php
6a488035
TO
67*
68* You can see the outcome of the API tests at
69d79249 69* https://test.civicrm.org/job/CiviCRM-master-git/
6a488035
TO
70*
71* To Learn about the API read
69d79249 72* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
6a488035 73*
69d79249
E
74* Browse the api on your own site with the api explorer
75* http://MYSITE.ORG/path/to/civicrm/api/explorer
6a488035
TO
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
b259a4ab 82*/