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', );
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', );
132 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
133 $this->assertEquals($membershiptype['error_message'],
134 'Mandatory key(s) missing from params array: duration_unit'
138 public function testCreateWithoutDurationInterval() {
140 'name' => '70+ Membership',
141 'description' => 'people above 70 are given health instructions',
142 'member_of_contact_id' => $this->_contactID
,
144 'minimum_fee' => '200',
145 'duration_unit' => 'month',
146 'period_type' => 'rolling',
147 'visibility' => 'public', );
148 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
149 $this->assertEquals($membershiptype['error_message'],
150 'Mandatory key(s) missing from params array: financial_type_id, duration_interval'
154 public function testCreateWithoutNameandDomainIDandDurationUnit() {
156 'description' => 'people above 50 are given health instructions',
157 'member_of_contact_id' => $this->_contactID
,
158 'financial_type_id' => 1,
159 'minimum_fee' => '200',
160 'duration_interval' => '10',
161 'period_type' => 'rolling',
162 'visibility' => 'public', );
164 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
165 $this->assertEquals($membershiptype['error_message'],
166 'Mandatory key(s) missing from params array: domain_id, duration_unit, name'
170 public function testCreateWithoutName() {
172 'description' => 'people above 50 are given health instructions',
173 'member_of_contact_id' => $this->_contactID
,
174 'financial_type_id' => 1,
176 'minimum_fee' => '200',
177 'duration_unit' => 'month',
178 'duration_interval' => '10',
179 'period_type' => 'rolling',
180 'visibility' => 'public', );
182 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
183 $this->assertEquals($membershiptype['error_message'], 'Mandatory key(s) missing from params array: name');
186 public function testCreate() {
188 'name' => '40+ Membership',
189 'description' => 'people above 40 are given health instructions',
190 'member_of_contact_id' => $this->_contactID
,
191 'financial_type_id' => 1,
193 'minimum_fee' => '200',
194 'duration_unit' => 'month',
195 'duration_interval' => '10',
196 'period_type' => 'rolling',
197 'visibility' => 'public',
200 $membershiptype = $this->callAPIAndDocument('membership_type', 'create', $params, __FUNCTION__
, __FILE__
);
201 $this->assertNotNull($membershiptype['values']);
202 $this->membershipTypeDelete(array('id' => $membershiptype['id']));
206 public function testUpdateWithEmptyParams() {
208 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
209 $this->assertEquals($membershiptype['error_message'],
210 'Mandatory key(s) missing from params array: domain_id, member_of_contact_id, financial_type_id, duration_unit, duration_interval, name'
214 public function testUpdateWithoutId() {
216 'name' => '60+ Membership',
217 'description' => 'people above 60 are given health instructions',
218 'member_of_contact_id' => $this->_contactID
,
219 'financial_type_id' => 1,
220 'minimum_fee' => '1200',
221 'duration_unit' => 'month',
222 'duration_interval' => '10',
223 'period_type' => 'rolling',
224 'visibility' => 'public', );
226 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
227 $this->assertEquals($membershiptype['error_message'], 'Mandatory key(s) missing from params array: domain_id');
230 public function testUpdate() {
231 $id = $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID
, 'financial_type_id' => 2));
232 $newMembOrgParams = array(
233 'organization_name' => 'New membership organisation',
234 'contact_type' => 'Organization',
235 'visibility' => 1, );
237 // create a new contact to update this membership type to
238 $newMembOrgID = $this->organizationCreate($newMembOrgParams);
242 'name' => 'Updated General',
243 'member_of_contact_id' => $newMembOrgID,
244 'duration_unit' => 'month',
245 'duration_interval' => '10',
246 'period_type' => 'fixed',
249 $this->callAPISuccess('membership_type', 'update', $params);
251 $this->getAndCheck($params, $id, $this->_entity
);
254 public function testDeleteNotExists() {
256 'id' => 'doesNotExist',
258 $membershiptype = $this->callAPIFailure('membership_type', 'delete', $params,
259 'Error while deleting membership type. id : ' . $params['id']
263 public function testDelete() {
264 $orgID = $this->organizationCreate(NULL);
265 $membershipTypeID = $this->membershipTypeCreate(array('member_of_contact_id' => $orgID));
267 'id' => $membershipTypeID,
270 $result = $this->callAPIAndDocument('membership_type', 'delete', $params, __FUNCTION__
, __FILE__
);