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