4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.6 |
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';
40 public function setUp() {
42 $this->useTransaction(TRUE);
43 $this->_apiversion
= 3;
44 $this->_contactID
= $this->organizationCreate(NULL);
47 public function testGetWithoutId() {
49 'name' => '60+ Membership',
50 'description' => 'people above 60 are given health instructions',
51 'financial_type_id' => 1,
52 'minimum_fee' => '200',
53 'duration_unit' => 'month',
54 'duration_interval' => '10',
55 'visibility' => 'public',
58 $membershiptype = $this->callAPISuccess('membership_type', 'get', $params);
59 $this->assertEquals($membershiptype['count'], 0);
62 public function testGet() {
63 $id = $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID
));
68 $membershiptype = $this->callAPIAndDocument('membership_type', 'get', $params, __FUNCTION__
, __FILE__
);
69 $this->assertEquals($membershiptype['values'][$id]['name'], 'General', 'In line ' . __LINE__
. " id is " . $id);
70 $this->assertEquals($membershiptype['values'][$id]['member_of_contact_id'], $this->_contactID
, 'In line ' . __LINE__
);
71 $this->assertEquals($membershiptype['values'][$id]['financial_type_id'], 1, 'In line ' . __LINE__
);
72 $this->assertEquals($membershiptype['values'][$id]['duration_unit'], 'year', 'In line ' . __LINE__
);
73 $this->assertEquals($membershiptype['values'][$id]['duration_interval'], '1', 'In line ' . __LINE__
);
74 $this->assertEquals($membershiptype['values'][$id]['period_type'], 'rolling', 'In line ' . __LINE__
);
75 $this->membershipTypeDelete($params);
78 ///////////////// civicrm_membership_type_create methods
79 public function testCreateWithEmptyParams() {
80 $membershiptype = $this->callAPIFailure('membership_type', 'create', array());
81 $this->assertEquals($membershiptype['error_message'],
82 'Mandatory key(s) missing from params array: domain_id, member_of_contact_id, financial_type_id, duration_unit, duration_interval, name'
86 public function testCreateWithoutMemberOfContactId() {
88 'name' => '60+ Membership',
89 'description' => 'people above 60 are given health instructions',
90 'financial_type_id' => 1,
92 'minimum_fee' => '200',
93 'duration_unit' => 'month',
94 'duration_interval' => '10',
95 'period_type' => 'rolling',
96 'visibility' => 'public',
99 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params,
100 'Mandatory key(s) missing from params array: member_of_contact_id'
104 public function testCreateWithoutContributionTypeId() {
106 'name' => '70+ Membership',
107 'description' => 'people above 70 are given health instructions',
108 'member_of_contact_id' => $this->_contactID
,
110 'minimum_fee' => '200',
111 'duration_unit' => 'month',
112 'duration_interval' => '10',
113 'period_type' => 'rolling',
114 'visibility' => 'public',
116 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
117 $this->assertEquals($membershiptype['error_message'],
118 'Mandatory key(s) missing from params array: financial_type_id'
122 public function testCreateWithoutDurationUnit() {
124 'name' => '80+ Membership',
125 'description' => 'people above 80 are given health instructions',
126 'member_of_contact_id' => $this->_contactID
,
127 'financial_type_id' => 1,
129 'minimum_fee' => '200',
130 'duration_interval' => '10',
131 'visibility' => 'public',
134 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
135 $this->assertEquals($membershiptype['error_message'],
136 'Mandatory key(s) missing from params array: duration_unit'
140 public function testCreateWithoutDurationInterval() {
142 'name' => '70+ Membership',
143 'description' => 'people above 70 are given health instructions',
144 'member_of_contact_id' => $this->_contactID
,
146 'minimum_fee' => '200',
147 'duration_unit' => 'month',
148 'period_type' => 'rolling',
149 'visibility' => 'public',
151 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
152 $this->assertEquals($membershiptype['error_message'],
153 'Mandatory key(s) missing from params array: financial_type_id, duration_interval'
157 public function testCreateWithoutNameandDomainIDandDurationUnit() {
159 'description' => 'people above 50 are given health instructions',
160 'member_of_contact_id' => $this->_contactID
,
161 'financial_type_id' => 1,
162 'minimum_fee' => '200',
163 'duration_interval' => '10',
164 'period_type' => 'rolling',
165 'visibility' => 'public',
168 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
169 $this->assertEquals($membershiptype['error_message'],
170 'Mandatory key(s) missing from params array: domain_id, duration_unit, name'
174 public function testCreateWithoutName() {
176 'description' => 'people above 50 are given health instructions',
177 'member_of_contact_id' => $this->_contactID
,
178 'financial_type_id' => 1,
180 'minimum_fee' => '200',
181 'duration_unit' => 'month',
182 'duration_interval' => '10',
183 'period_type' => 'rolling',
184 'visibility' => 'public',
187 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
188 $this->assertEquals($membershiptype['error_message'], 'Mandatory key(s) missing from params array: name');
191 public function testCreate() {
193 'name' => '40+ Membership',
194 'description' => 'people above 40 are given health instructions',
195 'member_of_contact_id' => $this->_contactID
,
196 'financial_type_id' => 1,
198 'minimum_fee' => '200',
199 'duration_unit' => 'month',
200 'duration_interval' => '10',
201 'period_type' => 'rolling',
202 'visibility' => 'public',
205 $membershiptype = $this->callAPIAndDocument('membership_type', 'create', $params, __FUNCTION__
, __FILE__
);
206 $this->assertNotNull($membershiptype['values']);
207 $this->membershipTypeDelete(array('id' => $membershiptype['id']));
211 public function testUpdateWithEmptyParams() {
213 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
214 $this->assertEquals($membershiptype['error_message'],
215 'Mandatory key(s) missing from params array: domain_id, member_of_contact_id, financial_type_id, duration_unit, duration_interval, name'
219 public function testUpdateWithoutId() {
221 'name' => '60+ Membership',
222 'description' => 'people above 60 are given health instructions',
223 'member_of_contact_id' => $this->_contactID
,
224 'financial_type_id' => 1,
225 'minimum_fee' => '1200',
226 'duration_unit' => 'month',
227 'duration_interval' => '10',
228 'period_type' => 'rolling',
229 'visibility' => 'public',
232 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
233 $this->assertEquals($membershiptype['error_message'], 'Mandatory key(s) missing from params array: domain_id');
236 public function testUpdate() {
237 $id = $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID
, 'financial_type_id' => 2));
238 $newMembOrgParams = array(
239 'organization_name' => 'New membership organisation',
240 'contact_type' => 'Organization',
244 // create a new contact to update this membership type to
245 $newMembOrgID = $this->organizationCreate($newMembOrgParams);
249 'name' => 'Updated General',
250 'member_of_contact_id' => $newMembOrgID,
251 'duration_unit' => 'month',
252 'duration_interval' => '10',
253 'period_type' => 'fixed',
257 $this->callAPISuccess('membership_type', 'update', $params);
259 $this->getAndCheck($params, $id, $this->_entity
);
262 public function testDeleteNotExists() {
264 'id' => 'doesNotExist',
266 $membershiptype = $this->callAPIFailure('membership_type', 'delete', $params,
267 'Error while deleting membership type. id : ' . $params['id']
271 public function testDelete() {
272 $orgID = $this->organizationCreate(NULL);
273 $membershipTypeID = $this->membershipTypeCreate(array('member_of_contact_id' => $orgID));
275 'id' => $membershipTypeID,
278 $result = $this->callAPIAndDocument('membership_type', 'delete', $params, __FUNCTION__
, __FILE__
);