Merge remote-tracking branch 'upstream/4.5' into 4.5-master-2015-02-09-11-44-07
[civicrm-core.git] / api / v3 / examples / MembershipType / Create.php
1 <?php
2 /**
3 * Test Generated example of using membership_type create API.
4 *
5 *
6 * @return array
7 * API result array
8 */
9 function membership_type_create_example() {
10 $params = array(
11 'name' => '40+ Membership',
12 'description' => 'people above 40 are given health instructions',
13 'member_of_contact_id' => 13,
14 'financial_type_id' => 1,
15 'domain_id' => '1',
16 'minimum_fee' => '200',
17 'duration_unit' => 'month',
18 'duration_interval' => '10',
19 'period_type' => 'rolling',
20 'visibility' => 'public',
21 );
22
23 try{
24 $result = civicrm_api3('membership_type', 'create', $params);
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 }
37
38 return $result;
39 }
40
41 /**
42 * Function returns array of result expected from previous function.
43 *
44 * @return array
45 * API result array
46 */
47 function membership_type_create_expectedresult() {
48
49 $expectedResult = array(
50 'is_error' => 0,
51 'version' => 3,
52 'count' => 1,
53 'id' => 2,
54 'values' => array(
55 '2' => array(
56 'id' => '2',
57 'domain_id' => '1',
58 'name' => '40+ Membership',
59 'description' => 'people above 40 are given health instructions',
60 'member_of_contact_id' => '13',
61 'financial_type_id' => '1',
62 'minimum_fee' => '200',
63 'duration_unit' => 'month',
64 'duration_interval' => '10',
65 'period_type' => 'rolling',
66 'fixed_period_start_day' => '',
67 'fixed_period_rollover_day' => '',
68 'relationship_type_id' => '',
69 'relationship_direction' => '',
70 'max_related' => '',
71 'visibility' => 'Public',
72 'weight' => '',
73 'receipt_text_signup' => '',
74 'receipt_text_renewal' => '',
75 'auto_renew' => '',
76 'is_active' => '',
77 'contribution_type_id' => '1',
78 ),
79 ),
80 );
81
82 return $expectedResult;
83 }
84
85 /**
86 * This example has been generated from the API test suite.
87 * The test that created it is called
88 * testCreate
89 * and can be found in
90 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/MembershipTypeTest.php
91 *
92 * You can see the outcome of the API tests at
93 * https://test.civicrm.org/job/CiviCRM-master-git/
94 *
95 * To Learn about the API read
96 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
97 *
98 * Browse the api on your own site with the api explorer
99 * http://MYSITE.ORG/path/to/civicrm/api
100 *
101 * Read more about testing here
102 * http://wiki.civicrm.org/confluence/display/CRM/Testing
103 *
104 * API Standards documentation:
105 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
106 */