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);
78 * Civicrm_membership_type_create methods.
80 public function testCreateWithEmptyParams() {
81 $membershiptype = $this->callAPIFailure('membership_type', 'create', array());
82 $this->assertEquals($membershiptype['error_message'],
83 'Mandatory key(s) missing from params array: domain_id, member_of_contact_id, financial_type_id, duration_unit, duration_interval, name'
87 public function testCreateWithoutMemberOfContactId() {
89 'name' => '60+ Membership',
90 'description' => 'people above 60 are given health instructions',
91 'financial_type_id' => 1,
93 'minimum_fee' => '200',
94 'duration_unit' => 'month',
95 'duration_interval' => '10',
96 'period_type' => 'rolling',
97 'visibility' => 'public',
100 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params,
101 'Mandatory key(s) missing from params array: member_of_contact_id'
105 public function testCreateWithoutContributionTypeId() {
107 'name' => '70+ Membership',
108 'description' => 'people above 70 are given health instructions',
109 'member_of_contact_id' => $this->_contactID
,
111 'minimum_fee' => '200',
112 'duration_unit' => 'month',
113 'duration_interval' => '10',
114 'period_type' => 'rolling',
115 'visibility' => 'public',
117 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
118 $this->assertEquals($membershiptype['error_message'],
119 'Mandatory key(s) missing from params array: financial_type_id'
123 public function testCreateWithoutDurationUnit() {
125 'name' => '80+ Membership',
126 'description' => 'people above 80 are given health instructions',
127 'member_of_contact_id' => $this->_contactID
,
128 'financial_type_id' => 1,
130 'minimum_fee' => '200',
131 'duration_interval' => '10',
132 'visibility' => 'public',
135 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
136 $this->assertEquals($membershiptype['error_message'],
137 'Mandatory key(s) missing from params array: duration_unit'
141 public function testCreateWithoutDurationInterval() {
143 'name' => '70+ Membership',
144 'description' => 'people above 70 are given health instructions',
145 'member_of_contact_id' => $this->_contactID
,
147 'minimum_fee' => '200',
148 'duration_unit' => 'month',
149 'period_type' => 'rolling',
150 'visibility' => 'public',
152 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
153 $this->assertEquals($membershiptype['error_message'],
154 'Mandatory key(s) missing from params array: financial_type_id, duration_interval'
158 public function testCreateWithoutNameandDomainIDandDurationUnit() {
160 'description' => 'people above 50 are given health instructions',
161 'member_of_contact_id' => $this->_contactID
,
162 'financial_type_id' => 1,
163 'minimum_fee' => '200',
164 'duration_interval' => '10',
165 'period_type' => 'rolling',
166 'visibility' => 'public',
169 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
170 $this->assertEquals($membershiptype['error_message'],
171 'Mandatory key(s) missing from params array: domain_id, duration_unit, name'
175 public function testCreateWithoutName() {
177 'description' => 'people above 50 are given health instructions',
178 'member_of_contact_id' => $this->_contactID
,
179 'financial_type_id' => 1,
181 'minimum_fee' => '200',
182 'duration_unit' => 'month',
183 'duration_interval' => '10',
184 'period_type' => 'rolling',
185 'visibility' => 'public',
188 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
189 $this->assertEquals($membershiptype['error_message'], 'Mandatory key(s) missing from params array: name');
192 public function testCreate() {
194 'name' => '40+ Membership',
195 'description' => 'people above 40 are given health instructions',
196 'member_of_contact_id' => $this->_contactID
,
197 'financial_type_id' => 1,
199 'minimum_fee' => '200',
200 'duration_unit' => 'month',
201 'duration_interval' => '10',
202 'period_type' => 'rolling',
203 'visibility' => 'public',
206 $membershiptype = $this->callAPIAndDocument('membership_type', 'create', $params, __FUNCTION__
, __FILE__
);
207 $this->assertNotNull($membershiptype['values']);
208 $this->membershipTypeDelete(array('id' => $membershiptype['id']));
212 public function testUpdateWithEmptyParams() {
214 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
215 $this->assertEquals($membershiptype['error_message'],
216 'Mandatory key(s) missing from params array: domain_id, member_of_contact_id, financial_type_id, duration_unit, duration_interval, name'
220 public function testUpdateWithoutId() {
222 'name' => '60+ Membership',
223 'description' => 'people above 60 are given health instructions',
224 'member_of_contact_id' => $this->_contactID
,
225 'financial_type_id' => 1,
226 'minimum_fee' => '1200',
227 'duration_unit' => 'month',
228 'duration_interval' => '10',
229 'period_type' => 'rolling',
230 'visibility' => 'public',
233 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
234 $this->assertEquals($membershiptype['error_message'], 'Mandatory key(s) missing from params array: domain_id');
237 public function testUpdate() {
238 $id = $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID
, 'financial_type_id' => 2));
239 $newMembOrgParams = array(
240 'organization_name' => 'New membership organisation',
241 'contact_type' => 'Organization',
245 // create a new contact to update this membership type to
246 $newMembOrgID = $this->organizationCreate($newMembOrgParams);
250 'name' => 'Updated General',
251 'member_of_contact_id' => $newMembOrgID,
252 'duration_unit' => 'month',
253 'duration_interval' => '10',
254 'period_type' => 'fixed',
258 $this->callAPISuccess('membership_type', 'update', $params);
260 $this->getAndCheck($params, $id, $this->_entity
);
263 public function testDeleteNotExists() {
265 'id' => 'doesNotExist',
267 $membershiptype = $this->callAPIFailure('membership_type', 'delete', $params,
268 'Error while deleting membership type. id : ' . $params['id']
272 public function testDelete() {
273 $orgID = $this->organizationCreate(NULL);
274 $membershipTypeID = $this->membershipTypeCreate(array('member_of_contact_id' => $orgID));
276 'id' => $membershipTypeID,
279 $result = $this->callAPIAndDocument('membership_type', 'delete', $params, __FUNCTION__
, __FILE__
);