4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.5 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2014 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
29 require_once 'CiviTest/CiviUnitTestCase.php';
32 * Class api_v3_MembershipTypeTest
34 class api_v3_MembershipTypeTest
extends CiviUnitTestCase
{
35 protected $_contactID;
36 protected $_contributionTypeID;
37 protected $_apiversion;
38 protected $_entity = 'MembershipType';
46 'name' => 'MembershipType Create',
47 'description' => 'Test all Membership Type Create API methods.',
48 'group' => 'CiviCRM API Tests',
54 $this->_apiversion
= 3;
55 $this->_contactID
= $this->organizationCreate(NULL);
59 $tablesToTruncate = array('civicrm_contact');
60 $this->quickCleanup($tablesToTruncate);
63 function testGetWithoutId() {
65 'name' => '60+ Membership',
66 'description' => 'people above 60 are given health instructions',
67 'financial_type_id' => 1,
68 'minimum_fee' => '200',
69 'duration_unit' => 'month',
70 'duration_interval' => '10',
71 'visibility' => 'public',
74 $membershiptype = $this->callAPISuccess('membership_type', 'get', $params);
75 $this->assertEquals($membershiptype['count'], 0);
79 $id = $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID
));
84 $membershiptype = $this->callAPIAndDocument('membership_type', 'get', $params, __FUNCTION__
, __FILE__
);
85 $this->assertEquals($membershiptype['values'][$id]['name'], 'General', 'In line ' . __LINE__
. " id is " . $id);
86 $this->assertEquals($membershiptype['values'][$id]['member_of_contact_id'], $this->_contactID
, 'In line ' . __LINE__
);
87 $this->assertEquals($membershiptype['values'][$id]['financial_type_id'], 1, 'In line ' . __LINE__
);
88 $this->assertEquals($membershiptype['values'][$id]['duration_unit'], 'year', 'In line ' . __LINE__
);
89 $this->assertEquals($membershiptype['values'][$id]['duration_interval'], '1', 'In line ' . __LINE__
);
90 $this->assertEquals($membershiptype['values'][$id]['period_type'], 'rolling', 'In line ' . __LINE__
);
91 $this->membershipTypeDelete($params);
94 ///////////////// civicrm_membership_type_create methods
95 function testCreateWithEmptyParams() {
96 $membershiptype = $this->callAPIFailure('membership_type', 'create', array());
97 $this->assertEquals($membershiptype['error_message'],
98 'Mandatory key(s) missing from params array: domain_id, member_of_contact_id, financial_type_id, duration_unit, duration_interval, name'
102 function testCreateWithoutMemberOfContactId() {
104 'name' => '60+ Membership',
105 'description' => 'people above 60 are given health instructions',
106 'financial_type_id' => 1,
108 'minimum_fee' => '200',
109 'duration_unit' => 'month',
110 'duration_interval' => '10',
111 'period_type' => 'rolling',
112 'visibility' => 'public',
115 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params,
116 'Mandatory key(s) missing from params array: member_of_contact_id'
120 function testCreateWithoutContributionTypeId() {
122 'name' => '70+ Membership',
123 'description' => 'people above 70 are given health instructions',
124 'member_of_contact_id' => $this->_contactID
,
126 'minimum_fee' => '200',
127 'duration_unit' => 'month',
128 'duration_interval' => '10',
129 'period_type' => 'rolling',
130 'visibility' => 'public', );
131 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
132 $this->assertEquals($membershiptype['error_message'],
133 'Mandatory key(s) missing from params array: financial_type_id'
137 function testCreateWithoutDurationUnit() {
139 'name' => '80+ Membership',
140 'description' => 'people above 80 are given health instructions',
141 'member_of_contact_id' => $this->_contactID
,
142 'financial_type_id' => 1,
144 'minimum_fee' => '200',
145 'duration_interval' => '10',
146 'visibility' => 'public', );
148 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
149 $this->assertEquals($membershiptype['error_message'],
150 'Mandatory key(s) missing from params array: duration_unit'
154 function testCreateWithoutDurationInterval() {
156 'name' => '70+ Membership',
157 'description' => 'people above 70 are given health instructions',
158 'member_of_contact_id' => $this->_contactID
,
160 'minimum_fee' => '200',
161 'duration_unit' => 'month',
162 'period_type' => 'rolling',
163 'visibility' => 'public', );
164 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
165 $this->assertEquals($membershiptype['error_message'],
166 'Mandatory key(s) missing from params array: financial_type_id, duration_interval'
170 function testCreateWithoutNameandDomainIDandDurationUnit() {
172 'description' => 'people above 50 are given health instructions',
173 'member_of_contact_id' => $this->_contactID
,
174 'financial_type_id' => 1,
175 'minimum_fee' => '200',
176 'duration_interval' => '10',
177 'period_type' => 'rolling',
178 'visibility' => 'public', );
180 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
181 $this->assertEquals($membershiptype['error_message'],
182 'Mandatory key(s) missing from params array: domain_id, duration_unit, name'
186 function testCreateWithoutName() {
188 'description' => 'people above 50 are given health instructions',
189 'member_of_contact_id' => $this->_contactID
,
190 'financial_type_id' => 1,
192 'minimum_fee' => '200',
193 'duration_unit' => 'month',
194 'duration_interval' => '10',
195 'period_type' => 'rolling',
196 'visibility' => 'public', );
198 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
199 $this->assertEquals($membershiptype['error_message'], 'Mandatory key(s) missing from params array: name');
202 function testCreate() {
204 'name' => '40+ Membership',
205 'description' => 'people above 40 are given health instructions',
206 'member_of_contact_id' => $this->_contactID
,
207 'financial_type_id' => 1,
209 'minimum_fee' => '200',
210 'duration_unit' => 'month',
211 'duration_interval' => '10',
212 'period_type' => 'rolling',
213 'visibility' => 'public',
216 $membershiptype = $this->callAPIAndDocument('membership_type', 'create', $params, __FUNCTION__
, __FILE__
);
217 $this->assertNotNull($membershiptype['values']);
218 $this->membershipTypeDelete(array('id' => $membershiptype['id']));
222 function testUpdateWithEmptyParams() {
224 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
225 $this->assertEquals($membershiptype['error_message'],
226 'Mandatory key(s) missing from params array: domain_id, member_of_contact_id, financial_type_id, duration_unit, duration_interval, name'
230 function testUpdateWithoutId() {
232 'name' => '60+ Membership',
233 'description' => 'people above 60 are given health instructions',
234 'member_of_contact_id' => $this->_contactID
,
235 'financial_type_id' => 1,
236 'minimum_fee' => '1200',
237 'duration_unit' => 'month',
238 'duration_interval' => '10',
239 'period_type' => 'rolling',
240 'visibility' => 'public', );
242 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
243 $this->assertEquals($membershiptype['error_message'], 'Mandatory key(s) missing from params array: domain_id');
246 function testUpdate() {
247 $id = $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID
, 'financial_type_id' => 2));
248 $newMembOrgParams = array(
249 'organization_name' => 'New membership organisation',
250 'contact_type' => 'Organization',
251 'visibility' => 1, );
253 // create a new contact to update this membership type to
254 $newMembOrgID = $this->organizationCreate($newMembOrgParams);
258 'name' => 'Updated General',
259 'member_of_contact_id' => $newMembOrgID,
260 'duration_unit' => 'month',
261 'duration_interval' => '10',
262 'period_type' => 'fixed',
265 $this->callAPISuccess('membership_type', 'update', $params);
267 $this->getAndCheck($params, $id, $this->_entity
);
270 function testDeleteNotExists() {
272 'id' => 'doesNotExist',
274 $membershiptype = $this->callAPIFailure('membership_type', 'delete', $params,
275 'Error while deleting membership type. id : ' . $params['id']
279 function testDelete() {
280 $orgID = $this->organizationCreate(NULL);
281 $membershipTypeID = $this->membershipTypeCreate(array('member_of_contact_id' => $orgID));
283 'id' => $membershipTypeID,
286 $result = $this->callAPIAndDocument('membership_type', 'delete', $params, __FUNCTION__
, __FILE__
);