Merge pull request #5035 from TeNNoX/master
[civicrm-core.git] / api / v3 / examples / MembershipType / Create.php
CommitLineData
6a488035 1<?php
fb32de45 2/**
50fb255d 3 * @file
4 * Test Generated API Example.
5 * See bottom of this file for more detail.
6a488035 6 */
6a488035 7
50fb255d 8/**
9 * Test Generated example of using membership_type create API.
10 *
11 *
12 * @return array
13 * API result array
14 */
15function membership_type_create_example() {
16 $params = array(
17 'name' => '40+ Membership',
18 'description' => 'people above 40 are given health instructions',
19 'member_of_contact_id' => 13,
20 'financial_type_id' => 1,
21 'domain_id' => '1',
22 'minimum_fee' => '200',
23 'duration_unit' => 'month',
24 'duration_interval' => '10',
25 'period_type' => 'rolling',
26 'visibility' => 'public',
27 );
6a488035 28
50fb255d 29 try{
30 $result = civicrm_api3('membership_type', 'create', $params);
31 }
32 catch (CiviCRM_API3_Exception $e) {
33 // Handle error here.
34 $errorMessage = $e->getMessage();
35 $errorCode = $e->getErrorCode();
36 $errorData = $e->getExtraParams();
37 return array(
38 'error' => $errorMessage,
39 'error_code' => $errorCode,
40 'error_data' => $errorData,
41 );
42 }
43
44 return $result;
6a488035
TO
45}
46
fb32de45 47/**
50fb255d 48 * Function returns array of result expected from previous function.
49 *
50 * @return array
51 * API result array
6a488035 52 */
50fb255d 53function membership_type_create_expectedresult() {
6a488035 54
53ca8fd7 55 $expectedResult = array(
50fb255d 56 'is_error' => 0,
57 'version' => 3,
58 'count' => 1,
59 'id' => 2,
60 'values' => array(
53ca8fd7 61 '2' => array(
50fb255d 62 'id' => '2',
63 'domain_id' => '1',
64 'name' => '40+ Membership',
65 'description' => 'people above 40 are given health instructions',
66 'member_of_contact_id' => '13',
67 'financial_type_id' => '1',
68 'minimum_fee' => '200',
69 'duration_unit' => 'month',
70 'duration_interval' => '10',
71 'period_type' => 'rolling',
72 'fixed_period_start_day' => '',
73 'fixed_period_rollover_day' => '',
74 'relationship_type_id' => '',
75 'relationship_direction' => '',
76 'max_related' => '',
77 'visibility' => 'Public',
78 'weight' => '',
79 'receipt_text_signup' => '',
80 'receipt_text_renewal' => '',
81 'auto_renew' => '',
82 'is_active' => '',
83 'contribution_type_id' => '1',
84 ),
6a488035 85 ),
50fb255d 86 );
6a488035 87
fb32de45 88 return $expectedResult;
6a488035
TO
89}
90
50fb255d 91/**
92* This example has been generated from the API test suite.
93* The test that created it is called
94* testCreate
95* and can be found in
69d79249 96* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/MembershipTypeTest.php
6a488035
TO
97*
98* You can see the outcome of the API tests at
69d79249 99* https://test.civicrm.org/job/CiviCRM-master-git/
6a488035
TO
100*
101* To Learn about the API read
69d79249 102* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
6a488035 103*
69d79249
E
104* Browse the api on your own site with the api explorer
105* http://MYSITE.ORG/path/to/civicrm/api/explorer
6a488035
TO
106*
107* Read more about testing here
108* http://wiki.civicrm.org/confluence/display/CRM/Testing
109*
110* API Standards documentation:
111* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
b259a4ab 112*/