CRM-13072 Update examples
[civicrm-core.git] / api / v3 / examples / MembershipTypeCreate.php
CommitLineData
6a488035 1<?php
fb32de45 2/**
3 * Test Generated example of using membership_type create API
4 * *
6a488035
TO
5 */
6function membership_type_create_example(){
53ca8fd7 7$params = array(
6a488035
TO
8 'name' => '40+ Membership',
9 'description' => 'people above 40 are given health instructions',
10 'member_of_contact_id' => 1,
11 'financial_type_id' => 1,
12 'domain_id' => '1',
13 'minimum_fee' => '200',
14 'duration_unit' => 'month',
15 'duration_interval' => '10',
16 'period_type' => 'rolling',
17 'visibility' => 'public',
6a488035
TO
18);
19
fb32de45 20try{
21 $result = civicrm_api3('membership_type', 'create', $params);
22}
23catch (CiviCRM_API3_Exception $e) {
24 // handle error here
25 $errorMessage = $e->getMessage();
26 $errorCode = $e->getErrorCode();
27 $errorData = $e->getExtraParams();
28 return array('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData);
29}
6a488035 30
fb32de45 31return $result;
6a488035
TO
32}
33
fb32de45 34/**
6a488035
TO
35 * Function returns array of result expected from previous function
36 */
37function membership_type_create_expectedresult(){
38
53ca8fd7 39 $expectedResult = array(
6a488035
TO
40 'is_error' => 0,
41 'version' => 3,
42 'count' => 1,
43 'id' => 2,
53ca8fd7 44 'values' => array(
45 '2' => array(
6a488035
TO
46 'id' => '2',
47 'domain_id' => '1',
48 'name' => '40+ Membership',
49 'description' => 'people above 40 are given health instructions',
50 'member_of_contact_id' => '1',
51 'financial_type_id' => '1',
52 'minimum_fee' => '200',
53 'duration_unit' => 'month',
54 'duration_interval' => '10',
55 'period_type' => 'rolling',
56 'fixed_period_start_day' => '',
57 'fixed_period_rollover_day' => '',
58 'relationship_type_id' => '',
59 'relationship_direction' => '',
60 'max_related' => '',
53ca8fd7 61 'visibility' => '1',
6a488035
TO
62 'weight' => '',
63 'receipt_text_signup' => '',
64 'receipt_text_renewal' => '',
65 'auto_renew' => '',
66 'is_active' => '',
53ca8fd7 67 'contribution_type_id' => '1',
6a488035
TO
68 ),
69 ),
70);
71
fb32de45 72 return $expectedResult;
6a488035
TO
73}
74
75
76/*
77* This example has been generated from the API test suite. The test that created it is called
78*
79* testCreate and can be found in
80* http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/MembershipTypeTest.php
81*
82* You can see the outcome of the API tests at
83* http://tests.dev.civicrm.org/trunk/results-api_v3
84*
85* To Learn about the API read
86* http://book.civicrm.org/developer/current/techniques/api/
87*
88* and review the wiki at
89* http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs
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
96*/