Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
fb32de45 | 2 | /** |
3 | * Test Generated example of using membership get API | |
4 | * Demonstrates use of 'filter' active_only' param * | |
6a488035 TO |
5 | */ |
6 | function membership_get_example(){ | |
53ca8fd7 | 7 | $params = array( |
a73daeff | 8 | 'contact_id' => 18, |
53ca8fd7 | 9 | 'filters' => array( |
6a488035 TO |
10 | 'is_current' => 1, |
11 | ), | |
6a488035 TO |
12 | ); |
13 | ||
fb32de45 | 14 | try{ |
15 | $result = civicrm_api3('membership', 'get', $params); | |
16 | } | |
17 | catch (CiviCRM_API3_Exception $e) { | |
18 | // handle error here | |
19 | $errorMessage = $e->getMessage(); | |
20 | $errorCode = $e->getErrorCode(); | |
21 | $errorData = $e->getExtraParams(); | |
22 | return array('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData); | |
23 | } | |
6a488035 | 24 | |
fb32de45 | 25 | return $result; |
6a488035 TO |
26 | } |
27 | ||
fb32de45 | 28 | /** |
6a488035 TO |
29 | * Function returns array of result expected from previous function |
30 | */ | |
31 | function membership_get_expectedresult(){ | |
32 | ||
53ca8fd7 | 33 | $expectedResult = array( |
6a488035 TO |
34 | 'is_error' => 0, |
35 | 'version' => 3, | |
36 | 'count' => 1, | |
37 | 'id' => 1, | |
53ca8fd7 | 38 | 'values' => array( |
39 | '1' => array( | |
6a488035 | 40 | 'id' => '1', |
a73daeff E |
41 | 'contact_id' => '18', |
42 | 'membership_type_id' => '27', | |
6a488035 | 43 | 'join_date' => '2009-01-21', |
9f1b81e0 | 44 | 'start_date' => '2013-07-29 00:00:00', |
9f1b81e0 | 45 | 'end_date' => '2013-08-04 00:00:00', |
6a488035 | 46 | 'source' => 'Payment', |
a73daeff | 47 | 'status_id' => '21', |
6a488035 TO |
48 | 'is_override' => '1', |
49 | 'is_test' => 0, | |
6a488035 | 50 | 'is_pay_later' => 0, |
6a488035 TO |
51 | 'membership_name' => 'General', |
52 | 'relationship_name' => 'Child of', | |
53 | ), | |
54 | ), | |
55 | ); | |
56 | ||
fb32de45 | 57 | return $expectedResult; |
6a488035 TO |
58 | } |
59 | ||
60 | ||
61 | /* | |
62 | * This example has been generated from the API test suite. The test that created it is called | |
63 | * | |
64 | * testGetOnlyActive and can be found in | |
69d79249 | 65 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/MembershipTest.php |
6a488035 TO |
66 | * |
67 | * You can see the outcome of the API tests at | |
69d79249 | 68 | * https://test.civicrm.org/job/CiviCRM-master-git/ |
6a488035 TO |
69 | * |
70 | * To Learn about the API read | |
69d79249 | 71 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API |
6a488035 | 72 | * |
69d79249 E |
73 | * Browse the api on your own site with the api explorer |
74 | * http://MYSITE.ORG/path/to/civicrm/api/explorer | |
6a488035 TO |
75 | * |
76 | * Read more about testing here | |
77 | * http://wiki.civicrm.org/confluence/display/CRM/Testing | |
78 | * | |
79 | * API Standards documentation: | |
80 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards | |
b259a4ab | 81 | */ |