79ebb5a9c29aadafce53a5ed0aed21233ad1bbff
[civicrm-core.git] / api / v3 / examples / Membership / SearchWithCustomData.php
1 <?php
2 /**
3 * Test Generated example demonstrating the Membership.create API.
4 *
5 * @return array
6 * API result array
7 */
8 function membership_create_example() {
9 $params = array(
10 'contact_id' => 94,
11 'membership_type_id' => 57,
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,
17 'status_id' => 35,
18 );
19
20 try{
21 $result = civicrm_api3('Membership', 'create', $params);
22 }
23 catch (CiviCRM_API3_Exception $e) {
24 // Handle error here.
25 $errorMessage = $e->getMessage();
26 $errorCode = $e->getErrorCode();
27 $errorData = $e->getExtraParams();
28 return array(
29 'is_error' => 1,
30 'error_message' => $errorMessage,
31 'error_code' => $errorCode,
32 'error_data' => $errorData,
33 );
34 }
35
36 return $result;
37 }
38
39 /**
40 * Function returns array of result expected from previous function.
41 *
42 * @return array
43 * API result array
44 */
45 function membership_create_expectedresult() {
46
47 $expectedResult = array(
48 'is_error' => 0,
49 'version' => 3,
50 'count' => 1,
51 'id' => 1,
52 'values' => array(
53 '1' => array(
54 'id' => '1',
55 'contact_id' => '94',
56 'membership_type_id' => '57',
57 'join_date' => '20090121000000',
58 'start_date' => '2013-07-29 00:00:00',
59 'end_date' => '2013-08-04 00:00:00',
60 'source' => 'Payment',
61 'status_id' => '35',
62 'is_override' => '1',
63 'owner_membership_id' => '',
64 'max_related' => '',
65 'is_test' => 0,
66 'is_pay_later' => '',
67 'contribution_recur_id' => '',
68 'campaign_id' => '',
69 ),
70 ),
71 );
72
73 return $expectedResult;
74 }
75
76 /*
77 * This example has been generated from the API test suite.
78 * The test that created it is called "testSearchWithCustomDataCRM16036"
79 * and can be found at:
80 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/MembershipTest.php
81 *
82 * You can see the outcome of the API tests at
83 * https://test.civicrm.org/job/CiviCRM-master-git/
84 *
85 * To Learn about the API read
86 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
87 *
88 * Browse the api on your own site with the api explorer
89 * http://MYSITE.ORG/path/to/civicrm/api
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 */