4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.4 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
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';
30 class api_v3_MembershipTypeTest
extends CiviUnitTestCase
{
31 protected $_contactID;
32 protected $_contributionTypeID;
33 protected $_apiversion;
34 protected $_entity = 'MembershipType';
35 public $_eNoticeCompliant = TRUE;
39 'name' => 'MembershipType Create',
40 'description' => 'Test all Membership Type Create API methods.',
41 'group' => 'CiviCRM API Tests',
47 $this->_apiversion
= 3;
48 $this->_contactID
= $this->organizationCreate(NULL);
52 $tablesToTruncate = array('civicrm_contact');
53 $this->quickCleanup($tablesToTruncate);
56 function testGetWithoutId() {
58 'name' => '60+ Membership',
59 'description' => 'people above 60 are given health instructions',
60 'financial_type_id' => 1,
61 'minimum_fee' => '200',
62 'duration_unit' => 'month',
63 'duration_interval' => '10',
64 'visibility' => 'public',
67 $membershiptype = $this->callAPISuccess('membership_type', 'get', $params);
68 $this->assertEquals($membershiptype['count'], 0);
72 $id = $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID
));
77 $membershiptype = $this->callAPIAndDocument('membership_type', 'get', $params, __FUNCTION__
, __FILE__
);
78 $this->assertEquals($membershiptype['values'][$id]['name'], 'General', 'In line ' . __LINE__
. " id is " . $id);
79 $this->assertEquals($membershiptype['values'][$id]['member_of_contact_id'], $this->_contactID
, 'In line ' . __LINE__
);
80 $this->assertEquals($membershiptype['values'][$id]['financial_type_id'], 1, 'In line ' . __LINE__
);
81 $this->assertEquals($membershiptype['values'][$id]['duration_unit'], 'year', 'In line ' . __LINE__
);
82 $this->assertEquals($membershiptype['values'][$id]['duration_interval'], '1', 'In line ' . __LINE__
);
83 $this->assertEquals($membershiptype['values'][$id]['period_type'], 'rolling', 'In line ' . __LINE__
);
84 $this->membershipTypeDelete($params);
87 ///////////////// civicrm_membership_type_create methods
88 function testCreateWithEmptyParams() {
89 $membershiptype = $this->callAPIFailure('membership_type', 'create', array());
90 $this->assertEquals($membershiptype['error_message'],
91 'Mandatory key(s) missing from params array: domain_id, member_of_contact_id, financial_type_id, duration_unit, duration_interval, name'
95 function testCreateWithoutMemberOfContactId() {
97 'name' => '60+ Membership',
98 'description' => 'people above 60 are given health instructions',
99 'financial_type_id' => 1,
101 'minimum_fee' => '200',
102 'duration_unit' => 'month',
103 'duration_interval' => '10',
104 'period_type' => 'rolling',
105 'visibility' => 'public',
108 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params,
109 'Mandatory key(s) missing from params array: member_of_contact_id'
113 function testCreateWithoutContributionTypeId() {
115 'name' => '70+ Membership',
116 'description' => 'people above 70 are given health instructions',
117 'member_of_contact_id' => $this->_contactID
,
119 'minimum_fee' => '200',
120 'duration_unit' => 'month',
121 'duration_interval' => '10',
122 'period_type' => 'rolling',
123 'visibility' => 'public', );
124 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
125 $this->assertEquals($membershiptype['error_message'],
126 'Mandatory key(s) missing from params array: financial_type_id'
130 function testCreateWithoutDurationUnit() {
132 'name' => '80+ Membership',
133 'description' => 'people above 80 are given health instructions',
134 'member_of_contact_id' => $this->_contactID
,
135 'financial_type_id' => 1,
137 'minimum_fee' => '200',
138 'duration_interval' => '10',
139 'visibility' => 'public', );
141 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
142 $this->assertEquals($membershiptype['error_message'],
143 'Mandatory key(s) missing from params array: duration_unit'
147 function testCreateWithoutDurationInterval() {
149 'name' => '70+ Membership',
150 'description' => 'people above 70 are given health instructions',
151 'member_of_contact_id' => $this->_contactID
,
153 'minimum_fee' => '200',
154 'duration_unit' => 'month',
155 'period_type' => 'rolling',
156 'visibility' => 'public', );
157 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
158 $this->assertEquals($membershiptype['error_message'],
159 'Mandatory key(s) missing from params array: financial_type_id, duration_interval'
163 function testCreateWithoutNameandDomainIDandDurationUnit() {
165 'description' => 'people above 50 are given health instructions',
166 'member_of_contact_id' => $this->_contactID
,
167 'financial_type_id' => 1,
168 'minimum_fee' => '200',
169 'duration_interval' => '10',
170 'period_type' => 'rolling',
171 'visibility' => 'public', );
173 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
174 $this->assertEquals($membershiptype['error_message'],
175 'Mandatory key(s) missing from params array: domain_id, duration_unit, name'
179 function testCreateWithoutName() {
181 'description' => 'people above 50 are given health instructions',
182 'member_of_contact_id' => $this->_contactID
,
183 'financial_type_id' => 1,
185 'minimum_fee' => '200',
186 'duration_unit' => 'month',
187 'duration_interval' => '10',
188 'period_type' => 'rolling',
189 'visibility' => 'public', );
191 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
192 $this->assertEquals($membershiptype['error_message'], 'Mandatory key(s) missing from params array: name');
195 function testCreate() {
197 'name' => '40+ Membership',
198 'description' => 'people above 40 are given health instructions',
199 'member_of_contact_id' => $this->_contactID
,
200 'financial_type_id' => 1,
202 'minimum_fee' => '200',
203 'duration_unit' => 'month',
204 'duration_interval' => '10',
205 'period_type' => 'rolling',
206 'visibility' => 'public',
209 $membershiptype = $this->callAPIAndDocument('membership_type', 'create', $params, __FUNCTION__
, __FILE__
);
210 $this->assertNotNull($membershiptype['values']);
211 $this->membershipTypeDelete(array('id' => $membershiptype['id']));
215 function testUpdateWithEmptyParams() {
217 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
218 $this->assertEquals($membershiptype['error_message'],
219 'Mandatory key(s) missing from params array: domain_id, member_of_contact_id, financial_type_id, duration_unit, duration_interval, name'
223 function testUpdateWithoutId() {
225 'name' => '60+ Membership',
226 'description' => 'people above 60 are given health instructions',
227 'member_of_contact_id' => $this->_contactID
,
228 'financial_type_id' => 1,
229 'minimum_fee' => '1200',
230 'duration_unit' => 'month',
231 'duration_interval' => '10',
232 'period_type' => 'rolling',
233 'visibility' => 'public', );
235 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
236 $this->assertEquals($membershiptype['error_message'], 'Mandatory key(s) missing from params array: domain_id');
239 function testUpdate() {
240 $id = $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID
, 'financial_type_id' => 2));
241 $newMembOrgParams = array(
242 'organization_name' => 'New membership organisation',
243 'contact_type' => 'Organization',
244 'visibility' => 1, );
246 // create a new contact to update this membership type to
247 $newMembOrgID = $this->organizationCreate($newMembOrgParams);
251 'name' => 'Updated General',
252 'member_of_contact_id' => $newMembOrgID,
253 'duration_unit' => 'month',
254 'duration_interval' => '10',
255 'period_type' => 'fixed',
258 $this->callAPISuccess('membership_type', 'update', $params);
260 $this->getAndCheck($params, $id, $this->_entity
);
263 function testDeleteNotExists() {
265 'id' => 'doesNotExist',
267 $membershiptype = $this->callAPIFailure('membership_type', 'delete', $params,
268 'Error while deleting membership type. id : ' . $params['id']
272 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__
);