3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviUnitTestCase.php';
31 * Class api_v3_MembershipTypeTest
33 class api_v3_MembershipTypeTest
extends CiviUnitTestCase
{
34 protected $_contactID;
35 protected $_contributionTypeID;
36 protected $_apiversion;
37 protected $_entity = 'MembershipType';
39 public function setUp() {
41 $this->useTransaction(TRUE);
42 $this->_apiversion
= 3;
43 $this->_contactID
= $this->organizationCreate(NULL);
46 public function testGetWithoutId() {
48 'name' => '60+ Membership',
49 'description' => 'people above 60 are given health instructions',
50 'financial_type_id' => 1,
51 'minimum_fee' => '200',
52 'duration_unit' => 'month',
53 'duration_interval' => '10',
54 'visibility' => 'public',
57 $membershiptype = $this->callAPISuccess('membership_type', 'get', $params);
58 $this->assertEquals($membershiptype['count'], 0);
61 public function testGet() {
62 $id = $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID
));
67 $membershiptype = $this->callAPIAndDocument('membership_type', 'get', $params, __FUNCTION__
, __FILE__
);
68 $this->assertEquals($membershiptype['values'][$id]['name'], 'General', 'In line ' . __LINE__
. " id is " . $id);
69 $this->assertEquals($membershiptype['values'][$id]['member_of_contact_id'], $this->_contactID
, 'In line ' . __LINE__
);
70 $this->assertEquals($membershiptype['values'][$id]['financial_type_id'], 1, 'In line ' . __LINE__
);
71 $this->assertEquals($membershiptype['values'][$id]['duration_unit'], 'year', 'In line ' . __LINE__
);
72 $this->assertEquals($membershiptype['values'][$id]['duration_interval'], '1', 'In line ' . __LINE__
);
73 $this->assertEquals($membershiptype['values'][$id]['period_type'], 'rolling', 'In line ' . __LINE__
);
74 $this->membershipTypeDelete($params);
77 ///////////////// civicrm_membership_type_create methods
78 public function testCreateWithEmptyParams() {
79 $membershiptype = $this->callAPIFailure('membership_type', 'create', array());
80 $this->assertEquals($membershiptype['error_message'],
81 'Mandatory key(s) missing from params array: domain_id, member_of_contact_id, financial_type_id, duration_unit, duration_interval, name'
85 public function testCreateWithoutMemberOfContactId() {
87 'name' => '60+ Membership',
88 'description' => 'people above 60 are given health instructions',
89 'financial_type_id' => 1,
91 'minimum_fee' => '200',
92 'duration_unit' => 'month',
93 'duration_interval' => '10',
94 'period_type' => 'rolling',
95 'visibility' => 'public',
98 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params,
99 'Mandatory key(s) missing from params array: member_of_contact_id'
103 public function testCreateWithoutContributionTypeId() {
105 'name' => '70+ Membership',
106 'description' => 'people above 70 are given health instructions',
107 'member_of_contact_id' => $this->_contactID
,
109 'minimum_fee' => '200',
110 'duration_unit' => 'month',
111 'duration_interval' => '10',
112 'period_type' => 'rolling',
113 'visibility' => 'public',
115 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
116 $this->assertEquals($membershiptype['error_message'],
117 'Mandatory key(s) missing from params array: financial_type_id'
121 public function testCreateWithoutDurationUnit() {
123 'name' => '80+ Membership',
124 'description' => 'people above 80 are given health instructions',
125 'member_of_contact_id' => $this->_contactID
,
126 'financial_type_id' => 1,
128 'minimum_fee' => '200',
129 'duration_interval' => '10',
130 'visibility' => 'public',
133 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
134 $this->assertEquals($membershiptype['error_message'],
135 'Mandatory key(s) missing from params array: duration_unit'
139 public function testCreateWithoutDurationInterval() {
141 'name' => '70+ Membership',
142 'description' => 'people above 70 are given health instructions',
143 'member_of_contact_id' => $this->_contactID
,
145 'minimum_fee' => '200',
146 'duration_unit' => 'month',
147 'period_type' => 'rolling',
148 'visibility' => 'public',
150 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
151 $this->assertEquals($membershiptype['error_message'],
152 'Mandatory key(s) missing from params array: financial_type_id, duration_interval'
156 public function testCreateWithoutNameandDomainIDandDurationUnit() {
158 'description' => 'people above 50 are given health instructions',
159 'member_of_contact_id' => $this->_contactID
,
160 'financial_type_id' => 1,
161 'minimum_fee' => '200',
162 'duration_interval' => '10',
163 'period_type' => 'rolling',
164 'visibility' => 'public',
167 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
168 $this->assertEquals($membershiptype['error_message'],
169 'Mandatory key(s) missing from params array: domain_id, duration_unit, name'
173 public function testCreateWithoutName() {
175 'description' => 'people above 50 are given health instructions',
176 'member_of_contact_id' => $this->_contactID
,
177 'financial_type_id' => 1,
179 'minimum_fee' => '200',
180 'duration_unit' => 'month',
181 'duration_interval' => '10',
182 'period_type' => 'rolling',
183 'visibility' => 'public',
186 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
187 $this->assertEquals($membershiptype['error_message'], 'Mandatory key(s) missing from params array: name');
190 public function testCreate() {
192 'name' => '40+ Membership',
193 'description' => 'people above 40 are given health instructions',
194 'member_of_contact_id' => $this->_contactID
,
195 'financial_type_id' => 1,
197 'minimum_fee' => '200',
198 'duration_unit' => 'month',
199 'duration_interval' => '10',
200 'period_type' => 'rolling',
201 'visibility' => 'public',
204 $membershiptype = $this->callAPIAndDocument('membership_type', 'create', $params, __FUNCTION__
, __FILE__
);
205 $this->assertNotNull($membershiptype['values']);
206 $this->membershipTypeDelete(array('id' => $membershiptype['id']));
210 public function testUpdateWithEmptyParams() {
212 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
213 $this->assertEquals($membershiptype['error_message'],
214 'Mandatory key(s) missing from params array: domain_id, member_of_contact_id, financial_type_id, duration_unit, duration_interval, name'
218 public function testUpdateWithoutId() {
220 'name' => '60+ Membership',
221 'description' => 'people above 60 are given health instructions',
222 'member_of_contact_id' => $this->_contactID
,
223 'financial_type_id' => 1,
224 'minimum_fee' => '1200',
225 'duration_unit' => 'month',
226 'duration_interval' => '10',
227 'period_type' => 'rolling',
228 'visibility' => 'public',
231 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
232 $this->assertEquals($membershiptype['error_message'], 'Mandatory key(s) missing from params array: domain_id');
235 public function testUpdate() {
236 $id = $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID
, 'financial_type_id' => 2));
237 $newMembOrgParams = array(
238 'organization_name' => 'New membership organisation',
239 'contact_type' => 'Organization',
243 // create a new contact to update this membership type to
244 $newMembOrgID = $this->organizationCreate($newMembOrgParams);
248 'name' => 'Updated General',
249 'member_of_contact_id' => $newMembOrgID,
250 'duration_unit' => 'month',
251 'duration_interval' => '10',
252 'period_type' => 'fixed',
256 $this->callAPISuccess('membership_type', 'update', $params);
258 $this->getAndCheck($params, $id, $this->_entity
);
261 public function testDeleteNotExists() {
263 'id' => 'doesNotExist',
265 $membershiptype = $this->callAPIFailure('membership_type', 'delete', $params,
266 'Error while deleting membership type. id : ' . $params['id']
270 public function testDelete() {
271 $orgID = $this->organizationCreate(NULL);
272 $membershipTypeID = $this->membershipTypeCreate(array('member_of_contact_id' => $orgID));
274 'id' => $membershipTypeID,
277 $result = $this->callAPIAndDocument('membership_type', 'delete', $params, __FUNCTION__
, __FILE__
);