| 1 | <?php |
| 2 | /** |
| 3 | * Test Generated example of using membership_type create API |
| 4 | * * |
| 5 | */ |
| 6 | function membership_type_create_example(){ |
| 7 | $params = array( |
| 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', |
| 18 | ); |
| 19 | |
| 20 | try{ |
| 21 | $result = civicrm_api3('membership_type', '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('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData); |
| 29 | } |
| 30 | |
| 31 | return $result; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Function returns array of result expected from previous function |
| 36 | */ |
| 37 | function membership_type_create_expectedresult(){ |
| 38 | |
| 39 | $expectedResult = array( |
| 40 | 'is_error' => 0, |
| 41 | 'version' => 3, |
| 42 | 'count' => 1, |
| 43 | 'id' => 2, |
| 44 | 'values' => array( |
| 45 | '2' => array( |
| 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' => '', |
| 61 | 'visibility' => '1', |
| 62 | 'weight' => '', |
| 63 | 'receipt_text_signup' => '', |
| 64 | 'receipt_text_renewal' => '', |
| 65 | 'auto_renew' => '', |
| 66 | 'is_active' => '', |
| 67 | 'contribution_type_id' => '1', |
| 68 | ), |
| 69 | ), |
| 70 | ); |
| 71 | |
| 72 | return $expectedResult; |
| 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 | */ |