Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
50fb255d | 2 | /** |
a828d7b8 | 3 | * Test Generated example demonstrating the Membership.create API. |
50fb255d | 4 | * |
50fb255d | 5 | * @return array |
6 | * API result array | |
7 | */ | |
a828d7b8 | 8 | function membership_create_example() { |
cf8f0fff | 9 | $params = [ |
8390b11b SL |
10 | 'contact_id' => 3, |
11 | 'membership_type_id' => 1, | |
50fb255d | 12 | 'join_date' => '2009-01-21', |
13 | 'start_date' => '2009-01-21', | |
14 | 'end_date' => '2009-12-21', | |
15 | 'source' => 'Payment', | |
16 | 'is_override' => 1, | |
8390b11b | 17 | 'status_id' => 42, |
50fb255d | 18 | 'custom_1' => 'custom string', |
cf8f0fff | 19 | ]; |
6a488035 | 20 | |
50fb255d | 21 | try{ |
a828d7b8 | 22 | $result = civicrm_api3('Membership', 'create', $params); |
50fb255d | 23 | } |
24 | catch (CiviCRM_API3_Exception $e) { | |
25 | // Handle error here. | |
26 | $errorMessage = $e->getMessage(); | |
27 | $errorCode = $e->getErrorCode(); | |
28 | $errorData = $e->getExtraParams(); | |
cf8f0fff | 29 | return [ |
5be22f39 | 30 | 'is_error' => 1, |
31 | 'error_message' => $errorMessage, | |
50fb255d | 32 | 'error_code' => $errorCode, |
33 | 'error_data' => $errorData, | |
cf8f0fff | 34 | ]; |
50fb255d | 35 | } |
36 | ||
37 | return $result; | |
6a488035 TO |
38 | } |
39 | ||
fb32de45 | 40 | /** |
50fb255d | 41 | * Function returns array of result expected from previous function. |
42 | * | |
43 | * @return array | |
44 | * API result array | |
6a488035 | 45 | */ |
a828d7b8 | 46 | function membership_create_expectedresult() { |
6a488035 | 47 | |
cf8f0fff | 48 | $expectedResult = [ |
50fb255d | 49 | 'is_error' => 0, |
50 | 'version' => 3, | |
51 | 'count' => 1, | |
52 | 'id' => 1, | |
cf8f0fff CW |
53 | 'values' => [ |
54 | '1' => [ | |
50fb255d | 55 | 'id' => '1', |
8390b11b SL |
56 | 'contact_id' => '3', |
57 | 'membership_type_id' => '1', | |
50fb255d | 58 | 'join_date' => '20090121000000', |
59 | 'start_date' => '2013-07-29 00:00:00', | |
60 | 'end_date' => '2013-08-04 00:00:00', | |
61 | 'source' => 'Payment', | |
8390b11b | 62 | 'status_id' => '42', |
50fb255d | 63 | 'is_override' => '1', |
8390b11b | 64 | 'status_override_end_date' => '', |
50fb255d | 65 | 'owner_membership_id' => '', |
66 | 'max_related' => '', | |
67 | 'is_test' => 0, | |
68 | 'is_pay_later' => '', | |
69 | 'contribution_recur_id' => '', | |
70 | 'campaign_id' => '', | |
cf8f0fff CW |
71 | ], |
72 | ], | |
73 | ]; | |
6a488035 | 74 | |
fb32de45 | 75 | return $expectedResult; |
6a488035 TO |
76 | } |
77 | ||
a828d7b8 | 78 | /* |
50fb255d | 79 | * This example has been generated from the API test suite. |
a828d7b8 CW |
80 | * The test that created it is called "testUpdateWithCustom" |
81 | * and can be found at: | |
69d79249 | 82 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/MembershipTest.php |
6a488035 TO |
83 | * |
84 | * You can see the outcome of the API tests at | |
8390b11b | 85 | * https://test.civicrm.org/job/CiviCRM-Core-Matrix/ |
6a488035 TO |
86 | * |
87 | * To Learn about the API read | |
8390b11b | 88 | * https://docs.civicrm.org/dev/en/latest/api/ |
6a488035 | 89 | * |
8390b11b SL |
90 | * Browse the API on your own site with the API Explorer. It is in the main |
91 | * CiviCRM menu, under: Support > Development > API Explorer. | |
6a488035 TO |
92 | * |
93 | * Read more about testing here | |
8390b11b | 94 | * https://docs.civicrm.org/dev/en/latest/testing/ |
6a488035 TO |
95 | * |
96 | * API Standards documentation: | |
8390b11b | 97 | * https://docs.civicrm.org/dev/en/latest/framework/api-architecture/ |
b259a4ab | 98 | */ |